diff --git a/Store/Store/CMakeLists.txt b/Store/Store/CMakeLists.txt new file mode 100644 index 0000000..62b5d0f --- /dev/null +++ b/Store/Store/CMakeLists.txt @@ -0,0 +1,75 @@ +cmake_minimum_required(VERSION 3.5) + +project(COS3711 VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) + +set(PROJECT_SOURCES + main.cpp + mainwindow.cpp + mainwindow.h +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(COS3711 + MANUAL_FINALIZATION + ${PROJECT_SOURCES} + customer.h customer.cpp + item.h item.cpp + transaction.h transaction.cpp + mymodel.h mymodel.cpp + addcustomerdialog.h addcustomerdialog.cpp + additemdialog.h additemdialog.cpp + ) +# Define target properties for Android with Qt 6 as: +# set_property(TARGET COS3711 APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/android) +# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation +else() + if(ANDROID) + add_library(COS3711 SHARED + ${PROJECT_SOURCES} + ) +# Define properties for Android with Qt 5 after find_package() calls as: +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") + else() + add_executable(COS3711 + ${PROJECT_SOURCES} + ) + endif() +endif() + +target_link_libraries(COS3711 PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) + +# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. +# If you are developing for iOS or macOS you should consider setting an +# explicit, fixed bundle identifier manually though. +if(${QT_VERSION} VERSION_LESS 6.1.0) + set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.COS3711) +endif() +set_target_properties(COS3711 PROPERTIES + ${BUNDLE_ID_OPTION} + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE +) + +include(GNUInstallDirs) +install(TARGETS COS3711 + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(COS3711) +endif() diff --git a/Store/Store/CMakeLists.txt.user b/Store/Store/CMakeLists.txt.user new file mode 100644 index 0000000..cd4b710 --- /dev/null +++ b/Store/Store/CMakeLists.txt.user @@ -0,0 +1,420 @@ + + + + + + EnvironmentId + {6fa689f0-d307-453e-aa89-3b1bf25a9d4e} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + + true + true + Builtin.DefaultTidyAndClazy + 4 + true + + + + true + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.5.2 MinGW 64-bit + Desktop Qt 6.5.2 MinGW 64-bit + qt.qt6.652.win64_mingw_kit + 0 + 0 + 0 + + Debug + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + 0 + C:\Users\DELL\Desktop\MXAT\build-COS3711-Desktop_Qt_6_5_2_MinGW_64_bit-Debug + + + + + all + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + Release + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + C:\Users\DELL\Desktop\MXAT\build-COS3711-Desktop_Qt_6_5_2_MinGW_64_bit-Release + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + C:\Users\DELL\Desktop\MXAT\build-COS3711-Desktop_Qt_6_5_2_MinGW_64_bit-RelWithDebInfo + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + 0 + C:\Users\DELL\Desktop\MXAT\build-COS3711-Desktop_Qt_6_5_2_MinGW_64_bit-Profile + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=MinSizeRel +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + C:\Users\DELL\Desktop\MXAT\build-COS3711-Desktop_Qt_6_5_2_MinGW_64_bit-MinSizeRel + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 5 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + false + COS3711 + CMakeProjectManager.CMakeRunConfiguration.COS3711 + COS3711 + true + true + true + C:/Users/DELL/Desktop/MXAT/build-COS3711-Desktop_Qt_6_5_2_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Store/Store/Images/Open_document.png b/Store/Store/Images/Open_document.png new file mode 100644 index 0000000..1d4f488 Binary files /dev/null and b/Store/Store/Images/Open_document.png differ diff --git a/Store/Store/Images/Open_file.png b/Store/Store/Images/Open_file.png new file mode 100644 index 0000000..6e6180a Binary files /dev/null and b/Store/Store/Images/Open_file.png differ diff --git a/Store/Store/Images/add.png b/Store/Store/Images/add.png new file mode 100644 index 0000000..070e4aa Binary files /dev/null and b/Store/Store/Images/add.png differ diff --git a/Store/Store/Images/customers.ico b/Store/Store/Images/customers.ico new file mode 100644 index 0000000..5bac777 Binary files /dev/null and b/Store/Store/Images/customers.ico differ diff --git a/Store/Store/Images/delete.png b/Store/Store/Images/delete.png new file mode 100644 index 0000000..ce4eb18 Binary files /dev/null and b/Store/Store/Images/delete.png differ diff --git a/Store/Store/Images/exit.png b/Store/Store/Images/exit.png new file mode 100644 index 0000000..45d845a Binary files /dev/null and b/Store/Store/Images/exit.png differ diff --git a/Store/Store/Images/help.png b/Store/Store/Images/help.png new file mode 100644 index 0000000..382c111 Binary files /dev/null and b/Store/Store/Images/help.png differ diff --git a/Store/Store/Images/info.png b/Store/Store/Images/info.png new file mode 100644 index 0000000..73b49b0 Binary files /dev/null and b/Store/Store/Images/info.png differ diff --git a/Store/Store/Images/new.png b/Store/Store/Images/new.png new file mode 100644 index 0000000..12131b0 Binary files /dev/null and b/Store/Store/Images/new.png differ diff --git a/Store/Store/Images/open.png b/Store/Store/Images/open.png new file mode 100644 index 0000000..45fa288 Binary files /dev/null and b/Store/Store/Images/open.png differ diff --git a/Store/Store/Images/save.png b/Store/Store/Images/save.png new file mode 100644 index 0000000..daba865 Binary files /dev/null and b/Store/Store/Images/save.png differ diff --git a/Store/Store/Images/saveas.png b/Store/Store/Images/saveas.png new file mode 100644 index 0000000..0a213db Binary files /dev/null and b/Store/Store/Images/saveas.png differ diff --git a/Store/Store/Images/undo.png b/Store/Store/Images/undo.png new file mode 100644 index 0000000..4c4c734 Binary files /dev/null and b/Store/Store/Images/undo.png differ diff --git a/Store/Store/Images/xml.png b/Store/Store/Images/xml.png new file mode 100644 index 0000000..8f5607e Binary files /dev/null and b/Store/Store/Images/xml.png differ diff --git a/Store/Store/UDP/UDPListen.pro b/Store/Store/UDP/UDPListen.pro new file mode 100644 index 0000000..8b62f78 --- /dev/null +++ b/Store/Store/UDP/UDPListen.pro @@ -0,0 +1,19 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-07-24T10:26:36 +# +#------------------------------------------------- + +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = UDPListen +TEMPLATE = app + + +SOURCES += main.cpp \ + udplisten.cpp + +HEADERS += \ + udplisten.h diff --git a/Store/Store/UDP/UDPListen.pro.user b/Store/Store/UDP/UDPListen.pro.user new file mode 100644 index 0000000..92367b5 --- /dev/null +++ b/Store/Store/UDP/UDPListen.pro.user @@ -0,0 +1,269 @@ + + + + + + EnvironmentId + {6fa689f0-d307-453e-aa89-3b1bf25a9d4e} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + + true + true + Builtin.DefaultTidyAndClazy + 4 + true + + + + true + + + true + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.5.2 MinGW 64-bit + Desktop Qt 6.5.2 MinGW 64-bit + qt.qt6.652.win64_mingw_kit + 0 + 0 + 0 + + 0 + C:\Users\DELL\Desktop\Cos3711\2018\S2\SolutionsToAssignment2\SolutionsToAssignment2\Question8\build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Debug + C:/Users/DELL/Desktop/Cos3711/2018/S2/SolutionsToAssignment2/SolutionsToAssignment2/Question8/build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + C:\Users\DELL\Desktop\Cos3711\2018\S2\SolutionsToAssignment2\SolutionsToAssignment2\Question8\build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Release + C:/Users/DELL/Desktop/Cos3711/2018/S2/SolutionsToAssignment2/SolutionsToAssignment2/Question8/build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + C:\Users\DELL\Desktop\Cos3711\2018\S2\SolutionsToAssignment2\SolutionsToAssignment2\Question8\build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Profile + C:/Users/DELL/Desktop/Cos3711/2018/S2/SolutionsToAssignment2/SolutionsToAssignment2/Question8/build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + false + UDPListen2 + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/DELL/Desktop/ASSG3/UDP/UDPListen.pro + C:/Users/DELL/Desktop/ASSG3/UDP/UDPListen.pro + true + true + true + C:/Users/DELL/Desktop/Cos3711/2018/S2/SolutionsToAssignment2/SolutionsToAssignment2/Question8/build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Store/Store/UDP/main.cpp b/Store/Store/UDP/main.cpp new file mode 100644 index 0000000..f69ede7 --- /dev/null +++ b/Store/Store/UDP/main.cpp @@ -0,0 +1,11 @@ +#include +#include "udplisten.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + UDPListen chat; + chat.setWindowTitle("UDP Listen"); + chat.show(); + return app.exec(); +} diff --git a/Store/Store/UDP/udplisten.cpp b/Store/Store/UDP/udplisten.cpp new file mode 100644 index 0000000..b264c70 --- /dev/null +++ b/Store/Store/UDP/udplisten.cpp @@ -0,0 +1,41 @@ +#include "udplisten.h" +#include +#include +#include +#include + +UDPListen::UDPListen(QWidget *parent) : QWidget(parent) +{ + socket = 0; + + QVBoxLayout* layout = new QVBoxLayout(this); + QPushButton* listen = new QPushButton("&Listen"); + display = new QTextEdit(); + display->setReadOnly(true); + layout->addWidget(listen); + layout->addWidget(display); + resize(300, 500); + + connect(listen, SIGNAL(clicked()), this, SLOT(startListening())); +} + +void UDPListen::startListening() +{ + display->setText("Started listening..."); + socket = new QUdpSocket(this); + socket->bind(34567); + connect(socket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); +} + +void UDPListen::processPendingDatagrams() +{ + QByteArray buffer; + buffer.resize(socket->pendingDatagramSize()); + socket->readDatagram(buffer.data(), buffer.size()); + + QDataStream stream(buffer); + stream.setVersion(QDataStream::Qt_4_0); + stream >> line; + display->append(""); + display->append(line); +} diff --git a/Store/Store/UDP/udplisten.h b/Store/Store/UDP/udplisten.h new file mode 100644 index 0000000..23e4ab7 --- /dev/null +++ b/Store/Store/UDP/udplisten.h @@ -0,0 +1,26 @@ +#ifndef UDP_H +#define UDP_H + +#include + +class QLineEdit; +class QTextEdit; +class QUdpSocket; + +class UDPListen : public QWidget +{ + Q_OBJECT +public: + explicit UDPListen(QWidget *parent = 0); +signals: + +public slots: + void startListening(); + void processPendingDatagrams(); +private: + QTextEdit* display; + QUdpSocket *socket; + QString line; +}; + +#endif // UDP_H diff --git a/Store/Store/addcustomerdialog.cpp b/Store/Store/addcustomerdialog.cpp new file mode 100644 index 0000000..1e34142 --- /dev/null +++ b/Store/Store/addcustomerdialog.cpp @@ -0,0 +1,87 @@ +#include "addcustomerdialog.h" +#include +#include +#include +#include +#include +#include +#include + +AddCustomerDialog::AddCustomerDialog(QWidget *parent):QDialog(parent) + ,edtCust(new QComboBox), + edtItem(new QComboBox),edtQuantity(new QSpinBox), + edtAddItem(new QPushButton("Add Item")) + ,txtEdt(new QTextEdit),edtDone(new QPushButton("Done")) +{ + setWindowTitle("Add Customer"); + + setupGUI(); + connect(edtAddItem, &QPushButton::clicked, this, &AddCustomerDialog::accept); + connect(edtAddItem, &QPushButton::clicked, this, &AddCustomerDialog::addCustomer); + + connect(edtDone, &QPushButton::clicked, this, &AddCustomerDialog::reject); +} +Customer AddCustomerDialog::getCustomer() const +{ + return Customer(edtAddItem->text()); +} + +void AddCustomerDialog::addCustomer() +{ + txtEdt->show(); + +} + +void AddCustomerDialog::setupGUI(){ + + // Declare widgets + QGridLayout *layout(new QGridLayout(this)); + + QLabel*lblTop{new QLabel("Complete the required data")}; + QLabel *lblCustomer(new QLabel("Select the Customer")); + QLabel *lblItem(new QLabel("Select the item")); + QLabel *lblType(new QLabel("Item Type")); + QLabel *lblQuantity(new QLabel("item quantity")); + + + + + // Setup layout + layout->addWidget(lblTop); + layout->addWidget(lblCustomer,1,0); + layout->addWidget(edtCust,1,1); + + layout->addWidget(lblItem,2,0); + layout->addWidget(edtItem,2,1); + + layout->addWidget(lblType,3,0); + + + layout->addWidget(lblQuantity,4,0); + layout->addWidget(edtQuantity,4,1); + layout->addWidget(edtAddItem,4,2); + + layout->addWidget(txtEdt,5,0,2,4); + layout->addWidget(edtDone,7,1,2,1); + + + + // Initialize widgets + QStringList listOne = QStringList() <<" " <<"Customer1" << "Customer2" << "Customer3" << "Customer4" ; + edtCust->addItems(listOne); + + QStringList listTwo = QStringList() <<" " << "Book1" << "Book2"<<"Book3"<< "Magazine1" << "Magazine2"<<"Magazine3" ; + edtItem->addItems(listTwo); + + + edtQuantity->setMaximum(9999); + edtQuantity->setMinimum(0); + + edtQuantity->setAlignment(Qt::AlignRight); + + + +} + + + diff --git a/Store/Store/addcustomerdialog.h b/Store/Store/addcustomerdialog.h new file mode 100644 index 0000000..bda8772 --- /dev/null +++ b/Store/Store/addcustomerdialog.h @@ -0,0 +1,45 @@ +#ifndef ADDCUSTOMERDIALOG_H +#define ADDCUSTOMERDIALOG_H +#include +#include +#include +#include +#include "Customer.h" +//#include"customerlist.h" +class QPushButton; +class QLineEdit; +class QTextEdit; +class QComboBox; +class QDoubleSpinBox; +class QSpinBox; +class CustomerList; + +class Customer; +class AddCustomerDialog : public QDialog +{ + Q_OBJECT +public: + AddCustomerDialog(QWidget *parent = nullptr); + + Customer getCustomer() const; + +private slots: + + void addCustomer(); +private: + + void setupGUI(); + + QComboBox *edtCust; + QComboBox *edtItem; + QSpinBox*edtQuantity; + + QPushButton*edtAddItem; + QTextEdit*txtEdt; + QPushButton*edtDone; + + // CustomerList list; + Customer*customer; + +}; +#endif // ADDCUSTOMERDIALOG_H diff --git a/Store/Store/additemdialog.cpp b/Store/Store/additemdialog.cpp new file mode 100644 index 0000000..e396fa0 --- /dev/null +++ b/Store/Store/additemdialog.cpp @@ -0,0 +1,79 @@ +#include "additemdialog.h" +#include"item.h" +#include +#include +#include +#include +#include +#include +#include + +AddItemDialog::AddItemDialog(QWidget *parent) + : QDialog(parent),edtType{new QComboBox},edtItemName{new QLineEdit} + ,edtAddItem{new QPushButton("Add item")} +{ + setWindowTitle("Add Item"); + setupGUI(); + connect(edtAddItem, &QPushButton::clicked, this, &AddItemDialog::accept); + // connect(edtDone, &QPushButton::clicked, this, &AddItemDialog::reject); + +} + +Item AddItemDialog::getItem() const +{ + return Item(edtItemName->text()); +} + +void AddItemDialog::addCustomer() +{ + + +} + +void AddItemDialog::readList() +{ + +} + +void AddItemDialog::writeList() +{ + +} + +void AddItemDialog::setupGUI() +{ + // Setup layout + + QGridLayout*layout(new QGridLayout(this)); + + QLabel*lblTop{new QLabel("Complete the required data")}; + + lblTop->setAlignment(Qt::AlignCenter); + QLabel*lblType{new QLabel("Item Type")}; + QLabel*lblItem{new QLabel("Name of Item")}; + + + + + layout->addWidget(lblTop); + + + layout->addWidget(lblType,1,0); + layout->addWidget(edtType,1,1); + + layout->addWidget(lblItem,2,0); + layout->addWidget(edtItemName,2,1); + + layout->addWidget(edtAddItem,3,1); + + this->setLayout(layout); + + // initialize widgets + + QStringList type =QStringList()<<" "<<"B"<<"M"; + edtType->addItems(type); + +} + + + diff --git a/Store/Store/additemdialog.h b/Store/Store/additemdialog.h new file mode 100644 index 0000000..ee5e148 --- /dev/null +++ b/Store/Store/additemdialog.h @@ -0,0 +1,38 @@ +#ifndef ADDITEMDIALOG_H +#define ADDITEMDIALOG_H +#include +#include +#include +#include +class Item; +class QPushButton; +class QLineEdit; +class QComboBox; +class shopInput; + +class AddItemDialog : public QDialog +{ + Q_OBJECT +public: + AddItemDialog(QWidget *parent = nullptr); + Item getItem() const; + +private slots: + void addCustomer(); + void readList(); + void writeList(); + +private: + + void setupGUI(); + //QLineEdit *m_nameLineEdit; + + QComboBox*edtType; + QLineEdit*edtItemName; + QPushButton*edtAddItem; + + +}; + + +#endif // ADDITEMDIALOG_H diff --git a/Store/Store/customer.cpp b/Store/Store/customer.cpp new file mode 100644 index 0000000..1fb8603 --- /dev/null +++ b/Store/Store/customer.cpp @@ -0,0 +1,10 @@ +#include "customer.h" + +Customer::Customer(const QString &name) + : m_name(name) +{ +} +QString Customer::getName() const +{ + return m_name; +} diff --git a/Store/Store/customer.h b/Store/Store/customer.h new file mode 100644 index 0000000..17026e0 --- /dev/null +++ b/Store/Store/customer.h @@ -0,0 +1,14 @@ +#ifndef CUSTOMER_H +#define CUSTOMER_H + +#include +class Customer +{ +public: + Customer(const QString &name); + QString getName() const; +private: + QString m_name; +}; + +#endif // CUSTOMER_H diff --git a/Store/Store/item.cpp b/Store/Store/item.cpp new file mode 100644 index 0000000..bb9dc76 --- /dev/null +++ b/Store/Store/item.cpp @@ -0,0 +1,10 @@ +#include "item.h" + +Item::Item(const QString &name) + : m_name(name) +{ +} +QString Item::getName() const +{ + return m_name; +} diff --git a/Store/Store/item.h b/Store/Store/item.h new file mode 100644 index 0000000..3dd3183 --- /dev/null +++ b/Store/Store/item.h @@ -0,0 +1,15 @@ +#ifndef ITEM_H +#define ITEM_H +#include + +class Item +{ +public: + Item(const QString &name); + QString getName() const; +private: + QString m_name; +}; + + +#endif // ITEM_H diff --git a/Store/Store/main.cpp b/Store/Store/main.cpp new file mode 100644 index 0000000..aff48df --- /dev/null +++ b/Store/Store/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/Store/Store/mainwindow.cpp b/Store/Store/mainwindow.cpp new file mode 100644 index 0000000..7fb1029 --- /dev/null +++ b/Store/Store/mainwindow.cpp @@ -0,0 +1,253 @@ +#include "mainwindow.h" +#include +#include"customer.h" +#include "item.h" +#include "addcustomerdialog.h" +#include "additemdialog.h" +#include +#include +#include +#include +#include +#include +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent),m_transactionsTreeView{new QTreeView} +{ + setWindowTitle("Store Application"); + resize(800,600); + + + QMenu *fileMenu = menuBar()->addMenu(tr("&File")); + QMenu *editMenu = menuBar()->addMenu(tr("&Add")); + QMenu *restoreMenu=menuBar()->addMenu("&Restore"); + QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); + // Create actions for the menus + QAction *newAction = new QAction(tr("&Add"), this); + QAction *openAction = new QAction(tr("&Open"), this); + QAction *saveAction = new QAction(tr("&Save"), this); + QAction *exitAction = new QAction(tr("&Exit"), this); + QAction *helpAction =new QAction(tr("Help"),this); + + // fileMenu->addAction(newAction); + + fileMenu->addAction(openAction); + fileMenu->addAction(saveAction); + fileMenu->addSeparator(); + fileMenu->addAction(exitAction); + helpMenu->addAction(helpAction); + + editMenu->addAction(newAction); + // Create toolbar + QToolBar *toolbar = addToolBar(tr("Main Toolbar")); + toolbar->addAction(newAction); + toolbar->addAction(openAction); + toolbar->addAction(saveAction); + // Create status bar + QStatusBar *statusBar = this->statusBar(); + statusBar->showMessage(tr("Ready")); + + + m_transactionsModel = new QStandardItemModel(this); + m_transactionsModel->setHorizontalHeaderLabels(QStringList() << tr("Transaction ") << tr("Type") << tr("Quality")); + m_transactionsTreeView->setModel(m_transactionsModel); + + setCentralWidget(m_transactionsTreeView); + + connect(newAction, &QAction::triggered, this, &MainWindow::addItem); + connect(helpAction, &QAction::triggered, this, &MainWindow::showAbout); + connect(newAction, &QAction::triggered, this, &MainWindow::recordTransaction); + connect(newAction, &QAction::triggered, this, &MainWindow::populateTransaction); + + + +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::recordTransaction() +{ + // Create a dialog to record a transaction + QDialog dialog(this); + dialog.setWindowTitle(tr("Shop")); + // Create input fields and buttons in the dialog + // QLabel *customerLabel = new QLabel(tr("Customer:")); + QLabel*lblTop{new QLabel(" \t \t \t Complete the required data")}; + + + + QLabel*custLable=new QLabel("Select the customer"); + custNameBox=new QComboBox; + + QLabel*selectItem=new QLabel("Select the Item"); + selectItemComboBox = new QComboBox; + + + QLabel *itemLabel = new QLabel(tr("Item Type")); + itemComboBox = new QComboBox; + + + QLabel *quantityLabel = new QLabel(tr("Quantity:")); + QSpinBox *quantitySpinBox = new QSpinBox; + + ItemAdd=new QPushButton("AddItem"); + txtEdit=new QPlainTextEdit; + + QPushButton *recordButton = new QPushButton(tr("Done")); + + + + QStringList cName=QStringList()<<" "<<"Customer1"<<"Customer2"<<"Customer3"<<"Customer 4"; + custNameBox->addItems(cName); + + + QStringList type=QStringList()<<" "<<"B"<<"M"; + itemComboBox->addItems(type); + + + QStringList cust=QStringList()<<" "<<"Book1"<<"Book2"<<"Book3"<<"Book4"<<"Magazine1"<<"Magazine2"<<"Magazine 3"; + selectItemComboBox->addItems(cust); + // edtCust->addItems(cust); + + for (const Customer *customer : m_customers) { + selectItemComboBox->addItem(customer->getName()); + // edtCust->addItem(customer->getName()); + } + + for (const Item *item : m_items) { + itemComboBox->addItem(item->getName()); + } + + QGridLayout *layout = new QGridLayout; + + layout->addWidget(lblTop); + + + layout->addWidget(custLable,1,0); + layout->addWidget(custNameBox,1,1); + + layout->addWidget(selectItem,2,0); + layout->addWidget(selectItemComboBox,2,1); + + + layout->addWidget(itemLabel,3,0); + layout->addWidget(itemComboBox,3,1); + + + layout->addWidget(quantityLabel,4,0); + layout->addWidget(quantitySpinBox,4,1); + layout->addWidget(ItemAdd,4,2); + layout->addWidget(txtEdit,5,0,2,4); + + + layout->addWidget(recordButton,7,1,2,1); + dialog.setLayout(layout); + + + + + + connect(recordButton, &QPushButton::clicked, [&]() { + QString custName=custNameBox->currentText(); + QString customerName = selectItemComboBox->currentText(); + QString itemType = itemComboBox->currentText(); + int quantity = quantitySpinBox->value(); + Transaction *transaction = new Transaction(custName,QDateTime::currentDateTime(), customerName, itemType, quantity); + m_transactions.append(transaction); + dialog.accept(); + }); + + dialog.exec(); + +} + +void MainWindow::populateTransaction() +{ + + m_transactionsModel->setHorizontalHeaderLabels(QStringList() << tr("Transaction ") << tr("Type") << tr("Quality")); + m_transactionsModel->clear(); + for (const Transaction *transaction : m_transactions) { + + QListcustomer; + customer.append(new QStandardItem(transaction->getCustomer())); + m_transactionsModel->appendRow(customer); + + QList items; + items.append(new QStandardItem(transaction->getDateTime().toString())); + customer.first()->appendRow(items); + m_transactionsModel->appendRow(customer); + + QListterms; + terms.append(new QStandardItem(transaction->getCustomerName())); + terms.append(new QStandardItem(transaction->getItemType())); + terms.append(new QStandardItem(QString::number(transaction->getQuantity()))); + + items.first()->appendRow(terms); + m_transactionsModel->appendRow(terms); + + + + +} + + +} +QListMainWindow::prepareRow(const QString &first,const QString &second + ,const QString &third ){ + +QListrowItems; +rowItems< +#include +#include +#include +#include +#include"transaction.h" + +class Customer; +class Item; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + + void recordTransaction(); + void populateTransaction(); + void addItem(); + void addCustomer(); + + void newFile(); + void open(); + void about(); + + void showHelp(); + void showAbout(); + +private: + QTreeView *m_transactionsTreeView; + + QListprepareRow(const QString &first,const QString&second,const QString&third); + QStandardItemModel *m_transactionsModel; + QList m_transactions; + QList m_customers; + QList m_items; + + QComboBox *custNameBox; + QComboBox *selectItemComboBox; + QLabel *itemLabel; + QComboBox *itemComboBox; + QSpinBox *quantitySpinBox; + + QPushButton*ItemAdd; + QPlainTextEdit*txtEdit; + + +}; +#endif // MAINWINDOW_H diff --git a/Store/Store/mymodel.cpp b/Store/Store/mymodel.cpp new file mode 100644 index 0000000..a3957f6 --- /dev/null +++ b/Store/Store/mymodel.cpp @@ -0,0 +1,50 @@ +#include "mymodel.h" + +MyModel::MyModel(QObject *parent) + : QAbstractItemModel{parent} +{ + +} +bool MyModel::setData(const QModelIndex & index, const QVariant & value, int role) +{ + if (role == Qt::EditRole) + { + //save value from editor to member m_gridData + m_gridData[index.row()][index.column()] = value.toString(); //for presentation purposes only: build and emit a joined string + QString result; + for(int row= 0; row < ROWS; row++) + { + for(int col= 0; col < COLS; col++) + + { + result += m_gridData[row][col] + " "; + } + } + //emit editCompleted( result ); + } + return true; +} + + +int MyModel::rowCount(const QModelIndex & /*parent*/) const +{ + return 2; +} + +Qt::ItemFlags MyModel::flags(const QModelIndex & /*index*/) const +{ + return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ; +} + + +QVariant MyModel::data(const QModelIndex &index, int role) const +{ + if (role == Qt::DisplayRole) + { + return QString("Row%1, Column%2") + .arg(index.row() + 1) + .arg(index.column() +1); + } + return QVariant(); +} + diff --git a/Store/Store/mymodel.h b/Store/Store/mymodel.h new file mode 100644 index 0000000..55a4c7e --- /dev/null +++ b/Store/Store/mymodel.h @@ -0,0 +1,24 @@ +#ifndef MYMODEL_H +#define MYMODEL_H + +#include +#include + +const int COLS=3; +const int ROWS=2; + +class MyModel : public QAbstractItemModel +{ +public: + explicit MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex&parent=QModelIndex())const; + int columnCount(const QModelIndex&parent, int role=Qt::DisplayRole)const; + + QVariant data(const QModelIndex &iindex, int role=Qt::DisplayRole)const; + bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); Qt::ItemFlags flags(const QModelIndex & index) const ; private: + QString m_gridData[ROWS][COLS]; //holds text entered into QTableView signals: + void editCompleted(const QString &); + +}; + +#endif // MYMODEL_H diff --git a/Store/Store/transaction.cpp b/Store/Store/transaction.cpp new file mode 100644 index 0000000..b0d8d6c --- /dev/null +++ b/Store/Store/transaction.cpp @@ -0,0 +1,33 @@ +#include "transaction.h" + +Transaction::Transaction( QString cust,const QDateTime &dateTime, const QString &customerName, const QString &itemType, int quantity) + : customer(cust),m_dateTime(dateTime), m_customerName(customerName), m_itemType(itemType), m_quantity(quantity) +{ +} +QDateTime Transaction::getDateTime() const +{ + return m_dateTime; +} +QString Transaction::getCustomerName() const +{ + return m_customerName; +} +QString Transaction::getItemType() const +{ + return m_itemType; +} + +int Transaction::getQuantity() const +{ + return m_quantity; +} + +QString Transaction::getCustomer() const +{ + return customer; +} + +void Transaction::setCustomer(const QString &newCustomer) +{ + customer = newCustomer; +} diff --git a/Store/Store/transaction.h b/Store/Store/transaction.h new file mode 100644 index 0000000..313e7a0 --- /dev/null +++ b/Store/Store/transaction.h @@ -0,0 +1,32 @@ +#ifndef TRANSACTION_H +#define TRANSACTION_H +#include +#include +#include "customer.h" +#include "item.h" + + +class Transaction +{ +public: + Transaction(QString cust,const QDateTime &dateTime, const QString &customerName, const QString &itemType, int quantity); + QDateTime getDateTime() const; + QString getCustomerName() const; + QString getItemType() const; + int getQuantity() const; + QString getCustomer() const; + + void setCustomer(const QString &newCustomer); + +private: + QDateTime m_dateTime; + QString m_customerName; + QString m_itemType; + int m_quantity; + QString customer; +}; + + + + +#endif // TRANSACTION_H diff --git a/Store/UDP/UDPListen.pro b/Store/UDP/UDPListen.pro new file mode 100644 index 0000000..8b62f78 --- /dev/null +++ b/Store/UDP/UDPListen.pro @@ -0,0 +1,19 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-07-24T10:26:36 +# +#------------------------------------------------- + +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = UDPListen +TEMPLATE = app + + +SOURCES += main.cpp \ + udplisten.cpp + +HEADERS += \ + udplisten.h diff --git a/Store/UDP/UDPListen.pro.user b/Store/UDP/UDPListen.pro.user new file mode 100644 index 0000000..92367b5 --- /dev/null +++ b/Store/UDP/UDPListen.pro.user @@ -0,0 +1,269 @@ + + + + + + EnvironmentId + {6fa689f0-d307-453e-aa89-3b1bf25a9d4e} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + + true + true + Builtin.DefaultTidyAndClazy + 4 + true + + + + true + + + true + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.5.2 MinGW 64-bit + Desktop Qt 6.5.2 MinGW 64-bit + qt.qt6.652.win64_mingw_kit + 0 + 0 + 0 + + 0 + C:\Users\DELL\Desktop\Cos3711\2018\S2\SolutionsToAssignment2\SolutionsToAssignment2\Question8\build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Debug + C:/Users/DELL/Desktop/Cos3711/2018/S2/SolutionsToAssignment2/SolutionsToAssignment2/Question8/build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + C:\Users\DELL\Desktop\Cos3711\2018\S2\SolutionsToAssignment2\SolutionsToAssignment2\Question8\build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Release + C:/Users/DELL/Desktop/Cos3711/2018/S2/SolutionsToAssignment2/SolutionsToAssignment2/Question8/build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + C:\Users\DELL\Desktop\Cos3711\2018\S2\SolutionsToAssignment2\SolutionsToAssignment2\Question8\build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Profile + C:/Users/DELL/Desktop/Cos3711/2018/S2/SolutionsToAssignment2/SolutionsToAssignment2/Question8/build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + false + UDPListen2 + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/DELL/Desktop/ASSG3/UDP/UDPListen.pro + C:/Users/DELL/Desktop/ASSG3/UDP/UDPListen.pro + true + true + true + C:/Users/DELL/Desktop/Cos3711/2018/S2/SolutionsToAssignment2/SolutionsToAssignment2/Question8/build-UDPListen-Desktop_Qt_6_5_2_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Store/UDP/main.cpp b/Store/UDP/main.cpp new file mode 100644 index 0000000..f69ede7 --- /dev/null +++ b/Store/UDP/main.cpp @@ -0,0 +1,11 @@ +#include +#include "udplisten.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + UDPListen chat; + chat.setWindowTitle("UDP Listen"); + chat.show(); + return app.exec(); +} diff --git a/Store/UDP/udplisten.cpp b/Store/UDP/udplisten.cpp new file mode 100644 index 0000000..b264c70 --- /dev/null +++ b/Store/UDP/udplisten.cpp @@ -0,0 +1,41 @@ +#include "udplisten.h" +#include +#include +#include +#include + +UDPListen::UDPListen(QWidget *parent) : QWidget(parent) +{ + socket = 0; + + QVBoxLayout* layout = new QVBoxLayout(this); + QPushButton* listen = new QPushButton("&Listen"); + display = new QTextEdit(); + display->setReadOnly(true); + layout->addWidget(listen); + layout->addWidget(display); + resize(300, 500); + + connect(listen, SIGNAL(clicked()), this, SLOT(startListening())); +} + +void UDPListen::startListening() +{ + display->setText("Started listening..."); + socket = new QUdpSocket(this); + socket->bind(34567); + connect(socket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); +} + +void UDPListen::processPendingDatagrams() +{ + QByteArray buffer; + buffer.resize(socket->pendingDatagramSize()); + socket->readDatagram(buffer.data(), buffer.size()); + + QDataStream stream(buffer); + stream.setVersion(QDataStream::Qt_4_0); + stream >> line; + display->append(""); + display->append(line); +} diff --git a/Store/UDP/udplisten.h b/Store/UDP/udplisten.h new file mode 100644 index 0000000..23e4ab7 --- /dev/null +++ b/Store/UDP/udplisten.h @@ -0,0 +1,26 @@ +#ifndef UDP_H +#define UDP_H + +#include + +class QLineEdit; +class QTextEdit; +class QUdpSocket; + +class UDPListen : public QWidget +{ + Q_OBJECT +public: + explicit UDPListen(QWidget *parent = 0); +signals: + +public slots: + void startListening(); + void processPendingDatagrams(); +private: + QTextEdit* display; + QUdpSocket *socket; + QString line; +}; + +#endif // UDP_H