From 0e803c23cba5e55e3d1ef3ba184d1e50eb6116ad Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sat, 6 May 2017 23:27:54 +0200 Subject: [PATCH 1/8] Import dialog and import progress moved to core library. --- core/core.pro | 12 +++- core/gridform.h | 43 +++++++++++++ {postregister => core}/icons/import.svg | 0 core/importdialog.cpp | 36 +++++++++++ {postregister => core}/importdialog.h | 7 ++- {postregister => core}/importdialog.ui | 63 ++++++++----------- core/importprogress.cpp | 34 ++++++++++ core/importprogress.h | 32 ++++++++++ .../importprogress.ui | 12 ++-- core/rc.qrc | 1 + countryregister/countryregistergrid.cpp | 1 + postregister/importdialog.cpp | 46 -------------- postregister/importprogressform.cpp | 34 ---------- postregister/importprogressform.h | 32 ---------- postregister/postregister.pro | 15 ++--- postregister/postregistergrid.cpp | 20 +----- postregister/postregisterrc.qrc | 5 -- 17 files changed, 197 insertions(+), 196 deletions(-) rename {postregister => core}/icons/import.svg (100%) create mode 100644 core/importdialog.cpp rename {postregister => core}/importdialog.h (78%) rename {postregister => core}/importdialog.ui (79%) create mode 100644 core/importprogress.cpp create mode 100644 core/importprogress.h rename postregister/importprogressform.ui => core/importprogress.ui (75%) delete mode 100644 postregister/importdialog.cpp delete mode 100644 postregister/importprogressform.cpp delete mode 100644 postregister/importprogressform.h delete mode 100644 postregister/postregisterrc.qrc diff --git a/core/core.pro b/core/core.pro index 5e996c1..ee89f4a 100644 --- a/core/core.pro +++ b/core/core.pro @@ -63,7 +63,9 @@ SOURCES += \ reporting/report.cpp \ reporting/reportviewer.cpp \ reporting/reportdialog.cpp \ - csvimporter.cpp + csvimporter.cpp \ + importdialog.cpp \ + importprogress.cpp HEADERS += core.h\ core_global.h \ @@ -126,7 +128,9 @@ HEADERS += core.h\ reporting/reportdialog.h \ iimporter.h \ csvimporter.h \ - iimportprogress.h + iimportprogress.h \ + importdialog.h \ + importprogress.h unix { target.path = /usr/lib @@ -161,7 +165,9 @@ FORMS += \ settings/globalsettingsform.ui \ settings/seasonnamedialog.ui \ reporting/reportviewer.ui \ - reporting/reportdialog.ui + reporting/reportdialog.ui \ + importdialog.ui \ + importprogress.ui OTHER_FILES += \ users/metaData.json \ diff --git a/core/gridform.h b/core/gridform.h index 5164d87..1823f25 100644 --- a/core/gridform.h +++ b/core/gridform.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "autoform.h" #include "autotablemodel.h" @@ -12,6 +14,9 @@ #include "iplugin.h" #include "igridform.h" #include "iservice.h" +#include "importdialog.h" +#include "csvimporter.h" +#include "importprogress.h" template class GridForm : public IGridForm @@ -164,6 +169,8 @@ private: bool m_serviceConnected; bool m_permissionDenied; +private slots: + // IGridForm interface protected: void handleNewRecord() override @@ -216,6 +223,42 @@ protected: } } } + + void showImportButton() + { + QHBoxLayout *tbLayout = qobject_cast(this->toolbar()->layout()); + + if (tbLayout != NULL) + { + QToolButton *btnImport = new QToolButton(this->toolbar()); + btnImport->setIcon(QIcon(":/icons/import.svg")); + btnImport->setAutoRaise(true); + btnImport->setIconSize(QSize(24, 24)); + btnImport->setToolTip(tr("Import")); + tbLayout->insertWidget(tbLayout->count() - 1, btnImport); + + connect(btnImport, &QToolButton::clicked, [this](){ + ImportDialog *dlg = new ImportDialog(this); + dlg->setAttribute(Qt::WA_DeleteOnClose); + dlg->show(); + + connect(dlg, &QDialog::accepted, [this, dlg](){ + T dataObj; + CsvImporter importer(dataObj.metaObject()); + + importer.setImportFile(dlg->fileName()); + importer.setSeparator(dlg->separator()); + + ImportProgress *progress = new ImportProgress(); + progress->move(QApplication::desktop()->screen()->rect().center() - progress->rect().center()); + progress->setWindowModality(Qt::ApplicationModal); + progress->show(); + + service()->importData(&importer, progress); + }); + }); + } + } }; #endif // GRIDFORM_H diff --git a/postregister/icons/import.svg b/core/icons/import.svg similarity index 100% rename from postregister/icons/import.svg rename to core/icons/import.svg diff --git a/core/importdialog.cpp b/core/importdialog.cpp new file mode 100644 index 0000000..17c1a9d --- /dev/null +++ b/core/importdialog.cpp @@ -0,0 +1,36 @@ +#include "importdialog.h" +#include "ui_importdialog.h" +#include "importprogress.h" +#include "csvimporter.h" + +#include +#include +#include + +ImportDialog::ImportDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ImportDialog) +{ + ui->setupUi(this); +} + +ImportDialog::~ImportDialog() +{ + delete ui; +} + +QString ImportDialog::fileName() +{ + return ui->editFile->text(); +} + +QString ImportDialog::separator() +{ + return ui->editSeparator->text(); +} + +void ImportDialog::on_btnFile_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, tr("Import file"), "", tr("All Files (*.*)")); + ui->editFile->setText(file); +} diff --git a/postregister/importdialog.h b/core/importdialog.h similarity index 78% rename from postregister/importdialog.h rename to core/importdialog.h index 833f0bd..8fe18a1 100644 --- a/postregister/importdialog.h +++ b/core/importdialog.h @@ -2,6 +2,8 @@ #define IMPORTDIALOG_H #include +#include +#include "iservice.h" namespace Ui { class ImportDialog; @@ -15,9 +17,10 @@ public: explicit ImportDialog(QWidget *parent = 0); ~ImportDialog(); -private slots: - void on_buttonBox_accepted(); + QString fileName(); + QString separator(); +private slots: void on_btnFile_clicked(); private: diff --git a/postregister/importdialog.ui b/core/importdialog.ui similarity index 79% rename from postregister/importdialog.ui rename to core/importdialog.ui index 48410fd..92c1be7 100644 --- a/postregister/importdialog.ui +++ b/core/importdialog.ui @@ -6,33 +6,44 @@ 0 0 - 518 - 152 + 454 + 115 - Dialog + Import data - - 10 - - - 10 - - + - CSV file + File + + + + + + + Separator + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + - - 3 - 0 @@ -58,30 +69,6 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - Field separator - - - - - - - ; - - - diff --git a/core/importprogress.cpp b/core/importprogress.cpp new file mode 100644 index 0000000..6434aef --- /dev/null +++ b/core/importprogress.cpp @@ -0,0 +1,34 @@ +#include "importprogress.h" +#include "ui_importprogress.h" + +ImportProgress::ImportProgress(QWidget *parent) : + QWidget(parent), + ui(new Ui::ImportProgress) +{ + ui->setupUi(this); + ui->progressBar->setRange(0, 100); + ui->progressBar->setValue(0); + + m_terminate = false; +} + +ImportProgress::~ImportProgress() +{ + delete ui; +} + +void ImportProgress::on_btnCancel_clicked() +{ + m_terminate = true; + this->close(); +} + +void ImportProgress::updateProgress(int currentPos) +{ + ui->progressBar->setValue(currentPos); +} + +bool ImportProgress::terminate() +{ + return m_terminate; +} diff --git a/core/importprogress.h b/core/importprogress.h new file mode 100644 index 0000000..81fd1bd --- /dev/null +++ b/core/importprogress.h @@ -0,0 +1,32 @@ +#ifndef IMPORTPROGRESS_H +#define IMPORTPROGRESS_H + +#include +#include "iimportprogress.h" + +namespace Ui { +class ImportProgress; +} + +class ImportProgress : public QWidget, public IImportProgress +{ + Q_OBJECT + +public: + explicit ImportProgress(QWidget *parent = 0); + ~ImportProgress(); + +private slots: + void on_btnCancel_clicked(); + +private: + Ui::ImportProgress *ui; + bool m_terminate; + + // IImportProgress interface +public: + void updateProgress(int currentPos); + bool terminate(); +}; + +#endif // IMPORTPROGRESS_H diff --git a/postregister/importprogressform.ui b/core/importprogress.ui similarity index 75% rename from postregister/importprogressform.ui rename to core/importprogress.ui index af184bc..6af7af7 100644 --- a/postregister/importprogressform.ui +++ b/core/importprogress.ui @@ -1,17 +1,17 @@ - ImportProgressForm - + ImportProgress + 0 0 - 369 - 134 + 400 + 165 - Form + Import progress @@ -24,7 +24,7 @@ - Cancel + Cenacel diff --git a/core/rc.qrc b/core/rc.qrc index 952aa60..9c37bcd 100644 --- a/core/rc.qrc +++ b/core/rc.qrc @@ -24,5 +24,6 @@ icons/zoomIn.svg icons/zoomOut.svg icons/report.svg + icons/import.svg diff --git a/countryregister/countryregistergrid.cpp b/countryregister/countryregistergrid.cpp index 4c74a80..1ce8902 100644 --- a/countryregister/countryregistergrid.cpp +++ b/countryregister/countryregistergrid.cpp @@ -4,6 +4,7 @@ CountryRegisterGrid::CountryRegisterGrid(QWidget *parent) : GridForm(parent) { setTableModel(new AutoTableModel()); + showImportButton(); } bool CountryRegisterGrid::canAddRecord() diff --git a/postregister/importdialog.cpp b/postregister/importdialog.cpp deleted file mode 100644 index a54c212..0000000 --- a/postregister/importdialog.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "importdialog.h" -#include "ui_importdialog.h" - -#include -#include -#include -#include - -#include "data/postdata.h" -#include "postregister-odb.hxx" -#include "importprogressform.h" - -ImportDialog::ImportDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::ImportDialog) -{ - ui->setupUi(this); -} - -ImportDialog::~ImportDialog() -{ - delete ui; -} - -void ImportDialog::on_buttonBox_accepted() -{ - QString fileName = ui->editFile->text(); - Service service; - PostData pd; - CsvImporter importer(pd.metaObject()); - - importer.setImportFile(fileName); - importer.setSeparator(ui->editSparator->text()); - - ImportProgressForm *progress = new ImportProgressForm(); - progress->move(QApplication::desktop()->screen()->rect().center() - progress->rect().center()); - progress->setWindowModality(Qt::ApplicationModal); - progress->show(); - service.importData(&importer, progress); -} - -void ImportDialog::on_btnFile_clicked() -{ - QString file = QFileDialog::getOpenFileName(this, tr("Import file"), "", tr("All Files (*.*)")); - ui->editFile->setText(file); -} diff --git a/postregister/importprogressform.cpp b/postregister/importprogressform.cpp deleted file mode 100644 index 67480bd..0000000 --- a/postregister/importprogressform.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "importprogressform.h" -#include "ui_importprogressform.h" - -ImportProgressForm::ImportProgressForm(QWidget *parent) : - QWidget(parent), - ui(new Ui::ImportProgressForm) -{ - ui->setupUi(this); - ui->progressBar->setRange(0, 100); - ui->progressBar->setValue(0); - - m_terminate = false; -} - -ImportProgressForm::~ImportProgressForm() -{ - delete ui; -} - -void ImportProgressForm::on_btnCancel_clicked() -{ - m_terminate = true; - this->close(); -} - -void ImportProgressForm::updateProgress(int currentPos) -{ - ui->progressBar->setValue(currentPos); -} - -bool ImportProgressForm::terminate() -{ - return m_terminate; -} diff --git a/postregister/importprogressform.h b/postregister/importprogressform.h deleted file mode 100644 index 27811bf..0000000 --- a/postregister/importprogressform.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef IMPORTPROGRESSFORM_H -#define IMPORTPROGRESSFORM_H - -#include -#include - -namespace Ui { -class ImportProgressForm; -} - -class ImportProgressForm : public QWidget, public IImportProgress -{ - Q_OBJECT - -public: - explicit ImportProgressForm(QWidget *parent = 0); - ~ImportProgressForm(); - -private slots: - void on_btnCancel_clicked(); - -private: - Ui::ImportProgressForm *ui; - bool m_terminate; - - // IImportProgress interface -public: - void updateProgress(int currentPos); - bool terminate(); -}; - -#endif // IMPORTPROGRESSFORM_H diff --git a/postregister/postregister.pro b/postregister/postregister.pro index f99124e..264a39a 100644 --- a/postregister/postregister.pro +++ b/postregister/postregister.pro @@ -24,16 +24,12 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += postregister.cpp \ data/postdata.cpp \ - postregistergrid.cpp \ - importdialog.cpp \ - importprogressform.cpp + postregistergrid.cpp HEADERS += postregister.h\ postregister_global.h \ data/postdata.h \ - postregistergrid.h \ - importdialog.h \ - importprogressform.h + postregistergrid.h include(../config_plugin.pri) @@ -44,9 +40,6 @@ include(../odb.pri) DISTFILES += \ postregister.json -FORMS += \ - importdialog.ui \ - importprogressform.ui +FORMS += -RESOURCES += \ - postregisterrc.qrc +RESOURCES += diff --git a/postregister/postregistergrid.cpp b/postregister/postregistergrid.cpp index 77af64f..4a0c1fd 100644 --- a/postregister/postregistergrid.cpp +++ b/postregister/postregistergrid.cpp @@ -3,30 +3,12 @@ #include #include "postregister-odb.hxx" -#include "importdialog.h" PostRegisterGrid::PostRegisterGrid(QWidget *parent) :GridForm(parent) { setTableModel(new AutoTableModel()); - QHBoxLayout *tbLayout = qobject_cast(this->toolbar()->layout()); - - if (tbLayout != NULL) - { - QToolButton *btnImport = new QToolButton(this->toolbar()); - btnImport->setIcon(QIcon(":/icons/import.svg")); - btnImport->setAutoRaise(true); - btnImport->setIconSize(QSize(24, 24)); - btnImport->setToolTip(tr("Import")); - tbLayout->insertWidget(tbLayout->count() - 1, btnImport); - - connect(btnImport, &QToolButton::clicked, [this](){ - ImportDialog *dlg = new ImportDialog(this); - dlg->setAttribute(Qt::WA_DeleteOnClose); - - dlg->show(); - }); - } + showImportButton(); } bool PostRegisterGrid::canAddRecord() diff --git a/postregister/postregisterrc.qrc b/postregister/postregisterrc.qrc deleted file mode 100644 index 3bd9e96..0000000 --- a/postregister/postregisterrc.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - icons/import.svg - - From 50ecd60c9a3317c92e24b27e37aab83e6716db13 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 7 May 2017 23:37:30 +0200 Subject: [PATCH 2/8] Inline editing of QDecDouble in AutoTableModel now possible. --- core/autotablemodel.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/autotablemodel.h b/core/autotablemodel.h index f7ee949..1fd9aed 100644 --- a/core/autotablemodel.h +++ b/core/autotablemodel.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "../qdecimal/src/QDecDouble.hh" @@ -264,7 +265,14 @@ public: QSharedPointer entity = m_list.at(index.row()); QObject *rawEntity = (QObject*)entity.data(); - rawEntity->setProperty(rawEntity->metaObject()->property(index.column() + 1).name(), value); + QVariant val = value; + if (rawEntity->property(rawEntity->metaObject()->property(index.column() + 1).name()).canConvert()) + { + QDecDouble dec(val.toDouble()); + val = QVariant::fromValue(dec); + } + + rawEntity->setProperty(rawEntity->metaObject()->property(index.column() + 1).name(), val); } if (role == Qt::CheckStateRole) From 78c80199b2884e2911788594ca1485680052a94b Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 7 May 2017 23:38:46 +0200 Subject: [PATCH 3/8] Fixed decimal point issue in QDecDouble constructor from double. --- qdecimal/src/QDecDouble.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qdecimal/src/QDecDouble.cc b/qdecimal/src/QDecDouble.cc index 793d576..7685c88 100644 --- a/qdecimal/src/QDecDouble.cc +++ b/qdecimal/src/QDecDouble.cc @@ -28,7 +28,10 @@ QDecDouble& QDecDouble::fromDouble(double d) #if defined(_MSC_VER) _snprintf(str, MaxStrSize, "%.*g", QDecNumDigits, d); #else + char *curLoc = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); snprintf(str, MaxStrSize, "%.*g", QDecNumDigits, d); + setlocale(LC_NUMERIC, curLoc); #endif return fromString(str); From 87ec7098ffcdbec50af68c2bd7ae756b78d609dd Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 7 May 2017 23:40:17 +0200 Subject: [PATCH 4/8] Fixed saving of enums to json settings. Added global enum for rounding. --- core/enums.h | 9 +++++++++ core/settingsservice.h | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/enums.h b/core/enums.h index 65adf26..14dec69 100644 --- a/core/enums.h +++ b/core/enums.h @@ -9,6 +9,7 @@ class CORESHARED_EXPORT Enums : public QObject Q_OBJECT Q_ENUMS(VatType) + Q_ENUMS(Rounding) public: enum VatType @@ -19,6 +20,14 @@ public: SECOND_LOWER }; + enum Rounding + { + R_NONE, + R_UP, + R_DOWN, + R_MATH + }; + Enums() { } diff --git a/core/settingsservice.h b/core/settingsservice.h index 15aa258..45dcb4b 100644 --- a/core/settingsservice.h +++ b/core/settingsservice.h @@ -8,6 +8,7 @@ #include #include +#include #include "data/system.h" #include "service.h" @@ -50,8 +51,19 @@ public: { QDecDouble dec(TO_DEC(varVal.toInt())); varVal = QVariant::fromValue(dec); + objSettings->setProperty(propName, varVal); + continue; + } + + // all other numbers are int + if (varVal.toInt() > 0) + { + objSettings->setProperty(propName, varVal.toInt()); + } + else + { + objSettings->setProperty(propName, varVal); } - objSettings->setProperty(propName, varVal); } return settingsObj; From 4c00364698118ba815473ca30f7adfc44759e0be Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 7 May 2017 23:41:36 +0200 Subject: [PATCH 5/8] Added settings for Camp module. Changed Camp data model. --- addressbook/data/addressbookdata.cpp | 1 + addressbook/data/addressbookdata.h | 3 + camp/camp.cpp | 3 + camp/camp.json | 32 ++- camp/camp.pro | 16 +- camp/data/addressitem.cpp | 23 ++- camp/data/addressitem.h | 10 + camp/data/camp-data.h | 6 + camp/data/campdata.cpp | 35 +++- camp/data/campdata.h | 15 ++ camp/data/personprice.cpp | 71 +++++++ camp/data/personprice.h | 50 +++++ camp/data/sale.cpp | 49 +++++ camp/data/sale.h | 40 ++++ camp/data/serviceitem.cpp | 5 +- camp/settings/campsettings.cpp | 40 ++++ camp/settings/campsettings.h | 36 ++++ camp/settings/campsettingsform.cpp | 137 +++++++++++++ camp/settings/campsettingsform.h | 51 +++++ camp/settings/campsettingsform.ui | 282 +++++++++++++++++++++++++++ 20 files changed, 898 insertions(+), 7 deletions(-) create mode 100644 camp/data/personprice.cpp create mode 100644 camp/data/personprice.h create mode 100644 camp/data/sale.cpp create mode 100644 camp/data/sale.h create mode 100644 camp/settings/campsettings.cpp create mode 100644 camp/settings/campsettings.h create mode 100644 camp/settings/campsettingsform.cpp create mode 100644 camp/settings/campsettingsform.h create mode 100644 camp/settings/campsettingsform.ui diff --git a/addressbook/data/addressbookdata.cpp b/addressbook/data/addressbookdata.cpp index 0b002d0..899b7b5 100644 --- a/addressbook/data/addressbookdata.cpp +++ b/addressbook/data/addressbookdata.cpp @@ -3,6 +3,7 @@ AddressbookData::AddressbookData(QObject * parent) :ComboItem(parent) { + m_ztp = false; } QString AddressbookData::title() const diff --git a/addressbook/data/addressbookdata.h b/addressbook/data/addressbookdata.h index 114d4dc..ab21936 100644 --- a/addressbook/data/addressbookdata.h +++ b/addressbook/data/addressbookdata.h @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -86,4 +87,6 @@ public: virtual QString toString(); }; +typedef QSharedPointer AddressbookDataPtr; + #endif // ADDRESSBOOKDATA_H diff --git a/camp/camp.cpp b/camp/camp.cpp index 1937270..351d31e 100644 --- a/camp/camp.cpp +++ b/camp/camp.cpp @@ -2,6 +2,7 @@ #include "campgrid.h" #include "campform.h" +#include "settings/campsettingsform.h" Camp::Camp() { @@ -9,8 +10,10 @@ Camp::Camp() void Camp::initServiceUi() { + m_service = new Service(); m_ui = new CampGrid(); ((CampGrid*)m_ui)->setForm(new CampForm()); + m_settingsUi = new CampSettingsForm(); } QIcon Camp::pluginIcon() diff --git a/camp/camp.json b/camp/camp.json index cd72275..4dae0af 100644 --- a/camp/camp.json +++ b/camp/camp.json @@ -8,16 +8,19 @@ "default" : "", "CZ" : "" }, - "schemaVersion" : 1, + "schemaVersion" : 2, "sql" : [ "CREATE TABLE \"CampData\" ( \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"numSer\" TEXT NULL, \"start\" TEXT NULL, \"end\" TEXT NULL, \"ownerFirstame\" TEXT NULL, \"ownerLastname\" TEXT NULL, \"ownerAddress\" TEXT NULL, \"totalPrice\" INTEGER NOT NULL, + \"sale\" INTEGER NOT NULL, + \"fixedSale\" INTEGER NOT NULL, \"season\" INTEGER NULL, CONSTRAINT \"season_fk\" FOREIGN KEY (\"season\") @@ -29,11 +32,21 @@ CREATE TABLE \"AddressItem\" ( \"firstName\" TEXT NULL, \"lastName\" TEXT NULL, \"address\" TEXT NULL, + \"adbItem\" INTEGER NULL, \"price\" INTEGER NOT NULL, \"campData\" INTEGER NOT NULL, + \"personPrice\" INTEGER NULL, + CONSTRAINT \"adbItem_fk\" + FOREIGN KEY (\"adbItem\") + REFERENCES \"AddressbookData\" (\"id\") + DEFERRABLE INITIALLY DEFERRED, CONSTRAINT \"campData_fk\" FOREIGN KEY (\"campData\") REFERENCES \"CampData\" (\"id\") + DEFERRABLE INITIALLY DEFERRED, + CONSTRAINT \"personPrice_fk\" + FOREIGN KEY (\"personPrice\") + REFERENCES \"PersonPrice\" (\"id\") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE \"ServiceItem\" ( @@ -48,7 +61,24 @@ CREATE TABLE \"ServiceItem\" ( FOREIGN KEY (\"campData\") REFERENCES \"CampData\" (\"id\") DEFERRABLE INITIALLY DEFERRED); + +CREATE TABLE \"Sale\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"sale\" INTEGER NOT NULL, + \"fixed\" INTEGER NOT NULL); + +CREATE TABLE \"PersonPrice\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"description\" TEXT NULL, + \"fromAge\" INTEGER NOT NULL, + \"toAge\" INTEGER NOT NULL, + \"price\" INTEGER NOT NULL, + \"active\" INTEGER NOT NULL); +", + +"ALTER TABLE Sale ADD \"description\" TEXT NULL; " + ], "dependencies" : [ "ADDRESSBOOK", "SHOP", "SERVICES" ], "translations" : { diff --git a/camp/camp.pro b/camp/camp.pro index 1ef3cb9..08cfebd 100644 --- a/camp/camp.pro +++ b/camp/camp.pro @@ -27,7 +27,11 @@ SOURCES += camp.cpp \ data/addressitem.cpp \ data/serviceitem.cpp \ campgrid.cpp \ - campform.cpp + campform.cpp \ + data/sale.cpp \ + settings/campsettingsform.cpp \ + data/personprice.cpp \ + settings/campsettings.cpp HEADERS += camp.h\ camp_global.h \ @@ -36,7 +40,11 @@ HEADERS += camp.h\ data/serviceitem.h \ data/camp-data.h \ campgrid.h \ - campform.h + campform.h \ + data/sale.h \ + settings/campsettingsform.h \ + data/personprice.h \ + settings/campsettings.h include(../config_plugin.pri) @@ -57,6 +65,7 @@ else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddre else:unix: LIBS += -L$$OUT_PWD/../plugins/ -laddressbook INCLUDEPATH += $$PWD/../addressbook +INCLUDEPATH += $$PWD/../addressbook/data DEPENDPATH += $$PWD/../addressbook win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lservices @@ -74,4 +83,5 @@ RESOURCES += \ camprc.qrc FORMS += \ - campform.ui + campform.ui \ + settings/campsettingsform.ui diff --git a/camp/data/addressitem.cpp b/camp/data/addressitem.cpp index afc1dd2..7886784 100644 --- a/camp/data/addressitem.cpp +++ b/camp/data/addressitem.cpp @@ -3,7 +3,8 @@ AddressItem::AddressItem(QObject *parent) : QObject(parent) { - + m_id = 0; + m_price = 0; } int AddressItem::id() const @@ -65,3 +66,23 @@ void AddressItem::setCampData(const QWeakPointer &campData) { m_campData = campData; } + +PersonPricePtr AddressItem::personPrice() const +{ + return m_personPrice; +} + +void AddressItem::setPersonPrice(const PersonPricePtr &personPrice) +{ + m_personPrice = personPrice; +} + +AddressbookDataPtr AddressItem::adbItem() const +{ + return m_adbItem; +} + +void AddressItem::setAdbItem(const AddressbookDataPtr &adbItem) +{ + m_adbItem = adbItem; +} diff --git a/camp/data/addressitem.h b/camp/data/addressitem.h index ad64bf8..296b6c1 100644 --- a/camp/data/addressitem.h +++ b/camp/data/addressitem.h @@ -8,6 +8,8 @@ #include #include +#include + class CampData; #pragma db object @@ -40,6 +42,12 @@ public: QWeakPointer campData() const; void setCampData(const QWeakPointer &campData); + PersonPricePtr personPrice() const; + void setPersonPrice(const PersonPricePtr &personPrice); + + AddressbookDataPtr adbItem() const; + void setAdbItem(const AddressbookDataPtr &adbItem); + private: friend class odb::access; #pragma db id auto @@ -47,9 +55,11 @@ private: QString m_firstName; QString m_lastName; QString m_address; + AddressbookDataPtr m_adbItem; int m_price; #pragma db not_null QWeakPointer m_campData; + PersonPricePtr m_personPrice; }; #endif // ADDRESSITEM_H diff --git a/camp/data/camp-data.h b/camp/data/camp-data.h index ea8dc1a..43ce501 100644 --- a/camp/data/camp-data.h +++ b/camp/data/camp-data.h @@ -6,13 +6,19 @@ class CampData; class AddressItem; class ServiceItem; +class Sale; +class PersonPrice; typedef QSharedPointer CampDataPtr; typedef QSharedPointer ServiceItemPtr; typedef QSharedPointer AddressItemPtr; +typedef QSharedPointer SalePtr; +typedef QSharedPointer PersonPricePtr; #include "campdata.h" #include "addressitem.h" #include "serviceitem.h" +#include "sale.h" +#include "personprice.h" #endif // CAMP_DATA_H diff --git a/camp/data/campdata.cpp b/camp/data/campdata.cpp index 1954e13..8f5de66 100644 --- a/camp/data/campdata.cpp +++ b/camp/data/campdata.cpp @@ -3,7 +3,10 @@ CampData::CampData(QObject *parent) : QObject(parent) { - + m_id = 0; + m_totalPrice = 0; + m_sale = 0; + m_ownerFirstame = false; } int CampData::id() const @@ -115,3 +118,33 @@ void CampData::setSeason(const SeasonPtr &season) { m_season = season; } + +QDecDouble CampData::sale() const +{ + return TO_DEC(m_sale); +} + +void CampData::setSale(QDecDouble sale) +{ + m_sale = FROM_DEC(sale); +} + +bool CampData::fixedSale() const +{ + return m_fixedSale; +} + +void CampData::setFixedSale(bool fixedSale) +{ + m_fixedSale = fixedSale; +} + +QString CampData::numSer() const +{ + return m_numSer; +} + +void CampData::setNumSer(const QString &numSer) +{ + m_numSer = numSer; +} diff --git a/camp/data/campdata.h b/camp/data/campdata.h index 1467864..018424b 100644 --- a/camp/data/campdata.h +++ b/camp/data/campdata.h @@ -14,12 +14,15 @@ class CampData : public QObject { Q_OBJECT + Q_PROPERTY(QString numSer READ numSer WRITE setNumSer) Q_PROPERTY(QDate start READ start WRITE setStart) Q_PROPERTY(QDate end READ end WRITE setEnd) Q_PROPERTY(QString ownerFirstame READ ownerFirstame WRITE setOwnerFirstame) Q_PROPERTY(QString ownerLastname READ ownerLastname WRITE setOwnerLastname) Q_PROPERTY(QString ownerAddress READ ownerAddress WRITE setOwnerAddress) Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice) + Q_PROPERTY(QDecDouble sale READ sale WRITE setSale) + Q_PROPERTY(bool fixedSale READ fixedSale WRITE setFixedSale) public: explicit CampData(QObject *parent = 0); @@ -56,10 +59,20 @@ public: SeasonPtr season() const; void setSeason(const SeasonPtr &season); + QDecDouble sale() const; + void setSale(QDecDouble sale); + + bool fixedSale() const; + void setFixedSale(bool fixedSale); + + QString numSer() const; + void setNumSer(const QString &numSer); + private: friend class odb::access; #pragma db id auto int m_id; + QString m_numSer; QDate m_start; QDate m_end; QString m_ownerFirstame; @@ -70,6 +83,8 @@ private: #pragma db value_not_null inverse(m_campData) QOdbList m_people; int m_totalPrice; + int m_sale; + bool m_fixedSale; SeasonPtr m_season; }; diff --git a/camp/data/personprice.cpp b/camp/data/personprice.cpp new file mode 100644 index 0000000..16bd3ae --- /dev/null +++ b/camp/data/personprice.cpp @@ -0,0 +1,71 @@ +#include "personprice.h" +#include + +PersonPrice::PersonPrice(QObject *parent) : QObject(parent) +{ + m_id = 0; + m_fromAge = 0; + m_toAge = 0; + m_price = 0; + m_active = true; +} + +int PersonPrice::id() const +{ + return m_id; +} + +void PersonPrice::setId(int id) +{ + m_id = id; +} + +QString PersonPrice::description() const +{ + return m_description; +} + +void PersonPrice::setDescription(const QString &description) +{ + m_description = description; +} + +int PersonPrice::fromAge() const +{ + return m_fromAge; +} + +void PersonPrice::setFromAge(int fromAge) +{ + m_fromAge = fromAge; +} + +int PersonPrice::toAge() const +{ + return m_toAge; +} + +void PersonPrice::setToAge(int toAge) +{ + m_toAge = toAge; +} + +QDecDouble PersonPrice::price() const +{ + return TO_DEC(m_price); +} + +void PersonPrice::setPrice(QDecDouble price) +{ + m_price = FROM_DEC(price); +} + +bool PersonPrice::active() const +{ + return m_active; +} + +void PersonPrice::setActive(bool active) +{ + m_active = active; +} diff --git a/camp/data/personprice.h b/camp/data/personprice.h new file mode 100644 index 0000000..72711c5 --- /dev/null +++ b/camp/data/personprice.h @@ -0,0 +1,50 @@ +#ifndef PERSONPRICE_H +#define PERSONPRICE_H + +#include +#include +#include + +#pragma db object +class PersonPrice : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString description READ description WRITE setDescription) + Q_PROPERTY(int fromAge READ fromAge WRITE setFromAge) + Q_PROPERTY(int toAge READ toAge WRITE setToAge) + Q_PROPERTY(QDecDouble price READ price WRITE setPrice) + Q_PROPERTY(bool active READ active WRITE setActive) + +public: + explicit PersonPrice(QObject *parent = 0); + + int id() const; + void setId(int id); + + QString description() const; + void setDescription(const QString &description); + + int fromAge() const; + void setFromAge(int fromAge); + + int toAge() const; + void setToAge(int toAge); + + QDecDouble price() const; + void setPrice(QDecDouble price); + + bool active() const; + void setActive(bool active); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_description; + int m_fromAge; + int m_toAge; + int m_price; + bool m_active; +}; + +#endif // PERSONPRICE_H diff --git a/camp/data/sale.cpp b/camp/data/sale.cpp new file mode 100644 index 0000000..22dc0c9 --- /dev/null +++ b/camp/data/sale.cpp @@ -0,0 +1,49 @@ +#include "sale.h" +#include + +Sale::Sale(QObject *parent) : QObject(parent) +{ + m_id = 0; + m_sale = 0; + m_fixed = false; +} + +int Sale::id() const +{ + return m_id; +} + +void Sale::setId(int id) +{ + m_id = id; +} + +QDecDouble Sale::sale() const +{ + return TO_DEC(m_sale); +} + +void Sale::setSale(QDecDouble sale) +{ + m_sale = FROM_DEC(sale); +} + +bool Sale::fixed() const +{ + return m_fixed; +} + +void Sale::setFixed(bool fixed) +{ + m_fixed = fixed; +} + +QString Sale::description() const +{ + return m_description; +} + +void Sale::setDescription(const QString &description) +{ + m_description = description; +} diff --git a/camp/data/sale.h b/camp/data/sale.h new file mode 100644 index 0000000..2047f1a --- /dev/null +++ b/camp/data/sale.h @@ -0,0 +1,40 @@ +#ifndef SALE_H +#define SALE_H + +#include +#include +#include + +#pragma db object +class Sale : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString description READ description WRITE setDescription) + Q_PROPERTY(QDecDouble sale READ sale WRITE setSale) + Q_PROPERTY(bool fixed READ fixed WRITE setFixed) + +public: + explicit Sale(QObject *parent = 0); + + int id() const; + void setId(int id); + + QDecDouble sale() const; + void setSale(QDecDouble sale); + + bool fixed() const; + void setFixed(bool fixed); + + QString description() const; + void setDescription(const QString &description); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_description; + int m_sale; + bool m_fixed; +}; + +#endif // SALE_H diff --git a/camp/data/serviceitem.cpp b/camp/data/serviceitem.cpp index d721283..34b1286 100644 --- a/camp/data/serviceitem.cpp +++ b/camp/data/serviceitem.cpp @@ -3,7 +3,10 @@ ServiceItem::ServiceItem(QObject *parent) : QObject(parent) { - + m_id = 0; + m_salePossible = false; + m_price = 0; + m_type = AccService::OTHER; } int ServiceItem::id() const diff --git a/camp/settings/campsettings.cpp b/camp/settings/campsettings.cpp new file mode 100644 index 0000000..322c7ff --- /dev/null +++ b/camp/settings/campsettings.cpp @@ -0,0 +1,40 @@ +#include "campsettings.h" +#include +#include + +CampSettings::CampSettings(QObject *parent) : QObject(parent) +{ + m_accFee = 0; + m_rounding = Enums::R_MATH; + m_decimalPlaces = 0; +} + +QDecDouble CampSettings::accFee() const +{ + return TO_DEC(m_accFee); +} + +void CampSettings::setAccFee(QDecDouble accFee) +{ + m_accFee = FROM_DEC(accFee); +} + +Enums::Rounding CampSettings::rounding() const +{ + return m_rounding; +} + +void CampSettings::setRounding(const Enums::Rounding &rounding) +{ + m_rounding = rounding; +} + +int CampSettings::decimalPlaces() const +{ + return m_decimalPlaces; +} + +void CampSettings::setDecimalPlaces(int decimalPlaces) +{ + m_decimalPlaces = decimalPlaces; +} diff --git a/camp/settings/campsettings.h b/camp/settings/campsettings.h new file mode 100644 index 0000000..57a64a2 --- /dev/null +++ b/camp/settings/campsettings.h @@ -0,0 +1,36 @@ +#ifndef CAMPSETTINGS_H +#define CAMPSETTINGS_H + +#include +#include +#include +#include + +class CampSettings : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDecDouble accFee READ accFee WRITE setAccFee) + Q_PROPERTY(Enums::Rounding rounding READ rounding WRITE setRounding) + Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces) + +public: + explicit CampSettings(QObject *parent = 0); + + QDecDouble accFee() const; + void setAccFee(QDecDouble accFee); + + Enums::Rounding rounding() const; + void setRounding(const Enums::Rounding &rounding); + + int decimalPlaces() const; + void setDecimalPlaces(int decimalPlaces); + +private: + int m_accFee; + Enums::Rounding m_rounding; + int m_decimalPlaces; +}; + +typedef QSharedPointer CampSettingsPtr; + +#endif // CAMPSETTINGS_H diff --git a/camp/settings/campsettingsform.cpp b/camp/settings/campsettingsform.cpp new file mode 100644 index 0000000..c4e43af --- /dev/null +++ b/camp/settings/campsettingsform.cpp @@ -0,0 +1,137 @@ +#include "camp-odb.hxx" +#include "campsettingsform.h" +#include "ui_campsettingsform.h" + +#include +#include + +CampSettingsForm::CampSettingsForm(QWidget *parent) : + FormBinder(parent), + ui(new Ui::CampSettingsForm) +{ + ui->setupUi(this); + + m_personPriceModel = new AutoTableModel(); + m_personPriceModel->setEditableCols(QList() << 0 << 1 << 2 << 3); + m_saleModel = new AutoTableModel(); + m_saleModel->setEditableCols(QList() << 0 << 1 << 2); + + ui->tablePersonPrices->setModel(m_personPriceModel); + ui->tableSales->setModel(m_saleModel); + + ui->tablePersonPrices->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + ui->tableSales->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + + QScroller::grabGesture(ui->tablePersonPrices, QScroller::LeftMouseButtonGesture); + QScroller::grabGesture(ui->tableSales, QScroller::LeftMouseButtonGesture); + + connect(ui->tablePersonPrices->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](){ + ui->btnPriceDisable->setEnabled(ui->tablePersonPrices->currentIndex().isValid()); + ui->btnPriceRemove->setEnabled(ui->tablePersonPrices->currentIndex().isValid()); + ui->btnPriceDisable->setChecked(m_personPriceModel->itemFromIndex(ui->tablePersonPrices->currentIndex())->active()); + }); + + connect(ui->tableSales->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](){ + ui->btnSaleRemove->setEnabled(ui->tableSales->currentIndex().isValid()); + }); + + registerBinding(ui->accFee); + registerBinding(ui->decimalPlaces); + QList roundings ; + roundings << ComboData(Enums::R_NONE, tr("None")) + << ComboData(Enums::R_UP, tr("Up")) + << ComboData(Enums::R_DOWN, tr("Down")) + << ComboData(Enums::R_MATH, tr("Mathematic")); + registerBinding(ui->rounding, roundings); +} + +CampSettingsForm::~CampSettingsForm() +{ + delete ui; +} + +bool CampSettingsForm::saveRecord() +{ + bindToData(); + SettingsService srv("CAMP"); + srv.saveSettings(entity()); + + Service personSrv; + Service saleSrv; + + foreach (PersonPricePtr p, personSrv.all()) { + personSrv.erase(p); + } + + foreach (PersonPricePtr p, m_personPriceModel->list()) { + personSrv.save(p); + } + + foreach (SalePtr s, saleSrv.all()) { + saleSrv.erase(s); + } + + foreach (SalePtr s, m_saleModel->list()) { + saleSrv.save(s); + } + + return true; +} + +void CampSettingsForm::loadEntity() +{ + SettingsService srv("CAMP"); + CampSettingsPtr settings = srv.loadSettings(); + setEntity(settings); + + Service personSrv; + Service saleSrv; + + m_personPriceModel->setData(personSrv.all()); + m_saleModel->setData(saleSrv.all()); + + ui->btnPriceDisable->setEnabled(false); + ui->btnPriceRemove->setEnabled(false); + ui->btnSaleRemove->setEnabled(false); +} + +void CampSettingsForm::on_btnPriceAdd_clicked() +{ + PersonPricePtr price(new PersonPrice()); + m_personPriceModel->addRow(price); +} + +void CampSettingsForm::on_btnSaleAdd_clicked() +{ + SalePtr sale(new Sale()); + m_saleModel->addRow(sale); +} + +void CampSettingsForm::on_btnPriceRemove_clicked() +{ + m_personPriceModel->removeRowAt(ui->tablePersonPrices->currentIndex()); +} + +void CampSettingsForm::on_btnPriceDisable_clicked() +{ + PersonPricePtr price = m_personPriceModel->itemFromIndex(ui->tablePersonPrices->currentIndex()); + price->setActive(!price->active()); +} + +void CampSettingsForm::on_btnPriceFilter_clicked() +{ + Service srv; + if (ui->btnPriceFilter->isChecked()) + { + m_personPriceModel->setData(srv.all("active = 1")); + } + else + { + m_personPriceModel->setData(srv.all()); + } +} + +void CampSettingsForm::on_btnSaleRemove_clicked() +{ + m_saleModel->removeRowAt(ui->tableSales->currentIndex()); +} diff --git a/camp/settings/campsettingsform.h b/camp/settings/campsettingsform.h new file mode 100644 index 0000000..cca493e --- /dev/null +++ b/camp/settings/campsettingsform.h @@ -0,0 +1,51 @@ +#ifndef CAMPSETTINGSFORM_H +#define CAMPSETTINGSFORM_H + +#include +#include + +#include "campsettings.h" +#include "data/camp-data.h" +#include +#include + +namespace Ui { +class CampSettingsForm; +} + +class CampSettingsForm : public FormBinder +{ + Q_OBJECT + +public: + explicit CampSettingsForm(QWidget *parent = 0); + ~CampSettingsForm(); + + // IForm interface +public slots: + bool saveRecord(); + + // IForm interface +public: + void loadEntity(); + +private slots: + void on_btnPriceAdd_clicked(); + + void on_btnSaleAdd_clicked(); + + void on_btnPriceRemove_clicked(); + + void on_btnPriceDisable_clicked(); + + void on_btnPriceFilter_clicked(); + + void on_btnSaleRemove_clicked(); + +private: + Ui::CampSettingsForm *ui; + AutoTableModel *m_personPriceModel; + AutoTableModel *m_saleModel; +}; + +#endif // CAMPSETTINGSFORM_H diff --git a/camp/settings/campsettingsform.ui b/camp/settings/campsettingsform.ui new file mode 100644 index 0000000..c2c558a --- /dev/null +++ b/camp/settings/campsettingsform.ui @@ -0,0 +1,282 @@ + + + CampSettingsForm + + + + 0 + 0 + 696 + 489 + + + + Form + + + + + + Person prices + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Add + + + ... + + + + :/icons/new.svg:/icons/new.svg + + + true + + + + + + + false + + + Remove + + + ... + + + + :/icons/remove.svg:/icons/remove.svg + + + true + + + + + + + false + + + Deactivate + + + ... + + + + :/icons/ok.svg:/icons/ok.svg + + + true + + + true + + + + + + + Filter active + + + ... + + + + :/icons/filter.svg:/icons/filter.svg + + + true + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + Sales + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Add + + + ... + + + + :/icons/new.svg:/icons/new.svg + + + true + + + + + + + false + + + Remove + + + ... + + + + :/icons/remove.svg:/icons/remove.svg + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + Other settings + + + + + + Accommodation fee + + + + + + + Rounding + + + + + + + + + + Decimal places + + + + + + + QAbstractSpinBox::NoButtons + + + 0 + + + 100000.000000000000000 + + + + + + + QAbstractSpinBox::NoButtons + + + 99999.990000000005239 + + + + + + + + + + + + + From d5ead1b187a2564feb7c944481e2cc77fa42025f Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Mon, 8 May 2017 14:03:51 +0200 Subject: [PATCH 6/8] Added country combo to addressbook. Addressbook plugin depends on Countryregister which must be loaded first. --- addressbook/addressbook.json | 10 ++++++--- addressbook/addressbook.pro | 9 ++++++++ addressbook/addressbookform.cpp | 7 +++++++ addressbook/addressbookform.h | 4 ++++ addressbook/addressbookform.ui | 31 ++++++++++++++++++++++++++-- addressbook/data/addressbookdata.cpp | 13 ++++++++++++ addressbook/data/addressbookdata.h | 6 ++++++ camp/camp.pro | 5 ++++- countryregister/data/countrydata.cpp | 19 ++++++++++++++++- countryregister/data/countrydata.h | 11 +++++++++- shop/shop.pro | 7 +++++-- 11 files changed, 112 insertions(+), 10 deletions(-) diff --git a/addressbook/addressbook.json b/addressbook/addressbook.json index ce7ac2f..5a41280 100644 --- a/addressbook/addressbook.json +++ b/addressbook/addressbook.json @@ -8,7 +8,7 @@ "default" : "", "CZ" : "" }, - "schemaVersion" : 1, + "schemaVersion" : 2, "sql" : [ "CREATE TABLE \"AddressbookData\" ( \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -21,10 +21,14 @@ \"addressCity\" TEXT NULL, \"addressStreet\" TEXT NULL, \"addressHouseNumber\" TEXT NULL, - \"addressZipCode\" TEXT NULL);" + \"addressZipCode\" TEXT NULL); +", + +"ALTER TABLE AddressbookData ADD \"country\" INTEGER NULL; +" ], - "dependencies" : [], + "dependencies" : [ "COUNTRYREGISTER" ], "translations" : { "CZ" : { "title" : "Titul", diff --git a/addressbook/addressbook.pro b/addressbook/addressbook.pro index 91a39b1..f88dd05 100644 --- a/addressbook/addressbook.pro +++ b/addressbook/addressbook.pro @@ -32,6 +32,7 @@ include(../config_plugin.pri) ODB_FILES = addressbook/data/addressbookdata.h H_DIR = $$PWD/data/*.h +ODB_OTHER_INCLUDES = -I $$PWD/../countryregister/data include(../odb.pri) OTHER_FILES += \ @@ -43,3 +44,11 @@ FORMS += \ RESOURCES += \ addressbookrc.qrc TRANSLATIONS = translations/addressbook_cs_CZ.ts + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lcountryregister +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lcountryregister +else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lcountryregister + +INCLUDEPATH += $$PWD/../countryregister/data +INCLUDEPATH += $$PWD/../countryregister + diff --git a/addressbook/addressbookform.cpp b/addressbook/addressbookform.cpp index 0ea80db..e6d30f9 100644 --- a/addressbook/addressbookform.cpp +++ b/addressbook/addressbookform.cpp @@ -1,5 +1,6 @@ #include "addressbookform.h" #include "ui_addressbookform.h" +#include AddressbookForm::AddressbookForm(QWidget *parent) : AutoForm(parent), @@ -22,3 +23,9 @@ AddressbookForm::~AddressbookForm() { delete ui; } + +void AddressbookForm::registerCombos() +{ + Service srv; + registerBinding(ui->country, ComboData::createComboData(srv.all())); +} diff --git a/addressbook/addressbookform.h b/addressbook/addressbookform.h index 7888b7d..85eb79c 100644 --- a/addressbook/addressbookform.h +++ b/addressbook/addressbookform.h @@ -20,6 +20,10 @@ public: private: Ui::AddressbookForm *ui; + + // FormBinder interface +protected: + void registerCombos(); }; diff --git a/addressbook/addressbookform.ui b/addressbook/addressbookform.ui index 8500b86..853d121 100644 --- a/addressbook/addressbookform.ui +++ b/addressbook/addressbookform.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 610 + 407 @@ -115,8 +115,35 @@ + + + + Country + + + + + + + true + + + + + title + firstName + lastName + birthDate + idCardNumber + ztp + addressCity + addressStreet + addressHouseNumber + addressZipCode + country + diff --git a/addressbook/data/addressbookdata.cpp b/addressbook/data/addressbookdata.cpp index 899b7b5..bee6c41 100644 --- a/addressbook/data/addressbookdata.cpp +++ b/addressbook/data/addressbookdata.cpp @@ -106,6 +106,19 @@ void AddressbookData::setId(int id) m_id = id; } +QSharedPointer AddressbookData::country() const +{ + return m_country; +} + +void AddressbookData::setCountry(const QSharedPointer &country) +{ + if (qobject_cast(country.data()) != NULL) + { + m_country = qSharedPointerDynamicCast(country); + } +} + bool AddressbookData::eq(ComboItem *other) { AddressbookData *adb = qobject_cast(other); diff --git a/addressbook/data/addressbookdata.h b/addressbook/data/addressbookdata.h index ab21936..4a250aa 100644 --- a/addressbook/data/addressbookdata.h +++ b/addressbook/data/addressbookdata.h @@ -9,6 +9,7 @@ #include #include +#include #if defined(ADDRESSBOOK_LIBRARY) # define ADDRESSBOOKSHARED_EXPORT Q_DECL_EXPORT @@ -30,6 +31,7 @@ class ADDRESSBOOKSHARED_EXPORT AddressbookData : public ComboItem Q_PROPERTY(QString addressStreet READ addressStreet WRITE setAddressStreet) Q_PROPERTY(QString addressHouseNumber READ addressHouseNumber WRITE setAddressHouseNumber) Q_PROPERTY(QString addressZipCode READ addressZipCode WRITE setAddressZipCode) + Q_PROPERTY(QSharedPointer country READ country WRITE setCountry) public: AddressbookData(QObject *parent = 0); @@ -66,6 +68,9 @@ public: int id() const; void setId(int id); + QSharedPointer country() const; + void setCountry(const QSharedPointer &country); + private: friend class odb::access; #pragma db id auto @@ -80,6 +85,7 @@ private: QString m_addressStreet; QString m_addressHouseNumber; QString m_addressZipCode; + CountryDataPtr m_country; // ComboItem interface public: diff --git a/camp/camp.pro b/camp/camp.pro index 08cfebd..8436342 100644 --- a/camp/camp.pro +++ b/camp/camp.pro @@ -50,7 +50,7 @@ include(../config_plugin.pri) ODB_FILES = camp/data/camp-data.h H_DIR = $$PWD/data/*.h -ODB_OTHER_INCLUDES = -I $$PWD/../shop -I $$PWD/../addressbook/data -I $$PWD/../services/data +ODB_OTHER_INCLUDES = -I $$PWD/../shop -I $$PWD/../addressbook/data -I $$PWD/../countryregister/data -I $$PWD/../services/data include(../odb.pri) win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop @@ -68,6 +68,9 @@ INCLUDEPATH += $$PWD/../addressbook INCLUDEPATH += $$PWD/../addressbook/data DEPENDPATH += $$PWD/../addressbook +INCLUDEPATH += $$PWD/../countryregister/data +INCLUDEPATH += $$PWD/../countryregister + win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lservices else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lservices else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lservices diff --git a/countryregister/data/countrydata.cpp b/countryregister/data/countrydata.cpp index 3d37d13..b47cd92 100644 --- a/countryregister/data/countrydata.cpp +++ b/countryregister/data/countrydata.cpp @@ -1,6 +1,6 @@ #include "countrydata.h" -CountryData::CountryData(QObject *parent) : QObject(parent) +CountryData::CountryData(QObject *parent) : ComboItem(parent) { } @@ -74,3 +74,20 @@ void CountryData::setEnglishName(const QString &englishName) { m_englishName = englishName; } + +bool CountryData::eq(ComboItem *other) +{ + CountryData *obj = qobject_cast(other); + + if (obj == NULL) + { + return false; + } + + return this == obj || (m_id == obj->m_id && m_code2 == obj->m_code2 && m_code3 == obj->m_code3); +} + +QString CountryData::toString() +{ + return m_code3 + " - " + m_czechFullName; +} diff --git a/countryregister/data/countrydata.h b/countryregister/data/countrydata.h index 8b3e66d..4caffb2 100644 --- a/countryregister/data/countrydata.h +++ b/countryregister/data/countrydata.h @@ -4,9 +4,11 @@ #include #include #include +#include +#include #pragma db object -class CountryData : public QObject +class CountryData : public ComboItem { Q_OBJECT Q_PROPERTY(QString code2 READ code2 WRITE setCode2) @@ -50,6 +52,13 @@ private: QString m_englishFullName; QString m_englishName; + + // ComboItem interface +public: + bool eq(ComboItem *other); + QString toString(); }; +typedef QSharedPointer CountryDataPtr; + #endif // COUNTRYDATA_H diff --git a/shop/shop.pro b/shop/shop.pro index 3a4210f..84869c4 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -9,7 +9,7 @@ QT += widgets sql TARGET = shop TEMPLATE = lib -#CONFIG += eet +CONFIG += eet DEFINES += SHOP_LIBRARY @@ -63,7 +63,7 @@ OTHER_FILES += shop.json ODB_FILES = shop/data/shop-data.h H_DIR = $$PWD/data/*.h -ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data -I $$PWD/ +ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data -I $$PWD/../countryregister/data -I $$PWD/ include(../odb.pri) RESOURCES += \ @@ -89,6 +89,9 @@ INCLUDEPATH += $$PWD/../addressbook INCLUDEPATH += $$PWD/ DEPENDPATH += $$PWD/../addressbook +INCLUDEPATH += $$PWD/../countryregister/data +INCLUDEPATH += $$PWD/../countryregister + TRANSLATIONS = translations/shop_cs_CZ.ts win32 { From cd4d58749ae9ba3242b3975745a4364858d7b42c Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 12 May 2017 14:33:14 +0200 Subject: [PATCH 7/8] Fixed camp settings saving. Added about messagebox. Methods IGridForm::handleNewRecord and IGridForm::handleEditRecord are virtual now. --- application/mainwindow.cpp | 10 ++++++++ application/mainwindow.h | 4 +++ application/mainwindow.ui | 24 ++++++++++++++--- camp/campform.ui | 10 +++----- camp/settings/campsettingsform.cpp | 41 +++++++++++++++++++++++++++--- core/gridform.h | 4 +-- 6 files changed, 79 insertions(+), 14 deletions(-) diff --git a/application/mainwindow.cpp b/application/mainwindow.cpp index fdd86ba..e7327da 100644 --- a/application/mainwindow.cpp +++ b/application/mainwindow.cpp @@ -178,3 +178,13 @@ void MainWindow::on_actionCountry_register_triggered() } } + +void MainWindow::on_actionAbout_Qt_triggered() +{ + QMessageBox::aboutQt(this); +} + +void MainWindow::on_actionAbout_triggered() +{ + QMessageBox::about(this, tr("About prodejna"), tr("Modular cash register software under GPL license.\n(C) 2015 - 2017 Josef Rokos, Zdenek Jonák")); +} diff --git a/application/mainwindow.h b/application/mainwindow.h index 543e84d..717f073 100644 --- a/application/mainwindow.h +++ b/application/mainwindow.h @@ -39,6 +39,10 @@ private slots: void on_actionCountry_register_triggered(); + void on_actionAbout_Qt_triggered(); + + void on_actionAbout_triggered(); + private: Ui::MainWindow *ui; LoginDialog *m_loginDialog; diff --git a/application/mainwindow.ui b/application/mainwindow.ui index ce35d2f..886c2be 100644 --- a/application/mainwindow.ui +++ b/application/mainwindow.ui @@ -60,7 +60,7 @@ 0 0 1000 - 20 + 25 @@ -79,8 +79,16 @@ + + + Help + + + + + @@ -126,12 +134,22 @@ - Post register + &Post register - Country register + &Country register + + + + + About + + + + + About Qt diff --git a/camp/campform.ui b/camp/campform.ui index 359af06..6a03d53 100644 --- a/camp/campform.ui +++ b/camp/campform.ui @@ -1,21 +1,19 @@ + - - - CampForm 0 0 - 400 - 300 + 462 + 403 Form - + diff --git a/camp/settings/campsettingsform.cpp b/camp/settings/campsettingsform.cpp index c4e43af..7cdd305 100644 --- a/camp/settings/campsettingsform.cpp +++ b/camp/settings/campsettingsform.cpp @@ -4,6 +4,7 @@ #include #include +#include CampSettingsForm::CampSettingsForm(QWidget *parent) : FormBinder(parent), @@ -58,13 +59,47 @@ bool CampSettingsForm::saveRecord() Service personSrv; Service saleSrv; + bool ret = true; + + connect(&personSrv, &IService::dbErrorDelete, [&ret, this](QString){ + QMessageBox::critical(this, tr("Cannot delete"), tr("Price already used")); + ret = false; + }); foreach (PersonPricePtr p, personSrv.all()) { - personSrv.erase(p); + bool found = false; + foreach (PersonPricePtr price, m_personPriceModel->list()) { + if (price->id() == p->id()) + { + found = true; + break; + } + } + + if (!found) + { + personSrv.erase(p); + } } foreach (PersonPricePtr p, m_personPriceModel->list()) { - personSrv.save(p); + bool found = false; + foreach (PersonPricePtr price, personSrv.all()) { + if (price->id() == p->id()) + { + found = true; + break; + } + } + + if (!found) + { + personSrv.save(p); + } + else + { + personSrv.update(p); + } } foreach (SalePtr s, saleSrv.all()) { @@ -75,7 +110,7 @@ bool CampSettingsForm::saveRecord() saleSrv.save(s); } - return true; + return ret; } void CampSettingsForm::loadEntity() diff --git a/core/gridform.h b/core/gridform.h index 1823f25..2f833d4 100644 --- a/core/gridform.h +++ b/core/gridform.h @@ -173,7 +173,7 @@ private slots: // IGridForm interface protected: - void handleNewRecord() override + virtual void handleNewRecord() override { if (m_form == NULL) { @@ -186,7 +186,7 @@ protected: m_formHandler->showForm(m_form); } - void handleEditRecord() override + virtual void handleEditRecord() override { if (m_form == NULL || m_tableModel == NULL || tableView()->currentIndex().row() < 0) { From 123aefdab57c2bca9cf081865cf64151d9574213 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sat, 13 May 2017 21:57:11 +0200 Subject: [PATCH 8/8] Added wizard for camp records. --- camp/camp.pro | 9 +- camp/campgrid.cpp | 14 + camp/campgrid.h | 5 + camp/campwizard.cpp | 30 ++ camp/campwizard.h | 31 ++ camp/campwizard.ui | 721 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 807 insertions(+), 3 deletions(-) create mode 100644 camp/campwizard.cpp create mode 100644 camp/campwizard.h create mode 100644 camp/campwizard.ui diff --git a/camp/camp.pro b/camp/camp.pro index 8436342..4a09b07 100644 --- a/camp/camp.pro +++ b/camp/camp.pro @@ -31,7 +31,8 @@ SOURCES += camp.cpp \ data/sale.cpp \ settings/campsettingsform.cpp \ data/personprice.cpp \ - settings/campsettings.cpp + settings/campsettings.cpp \ + campwizard.cpp HEADERS += camp.h\ camp_global.h \ @@ -44,7 +45,8 @@ HEADERS += camp.h\ data/sale.h \ settings/campsettingsform.h \ data/personprice.h \ - settings/campsettings.h + settings/campsettings.h \ + campwizard.h include(../config_plugin.pri) @@ -87,4 +89,5 @@ RESOURCES += \ FORMS += \ campform.ui \ - settings/campsettingsform.ui + settings/campsettingsform.ui \ + campwizard.ui diff --git a/camp/campgrid.cpp b/camp/campgrid.cpp index 4c0c007..8560401 100644 --- a/camp/campgrid.cpp +++ b/camp/campgrid.cpp @@ -1,6 +1,20 @@ #include "campgrid.h" +#include "campwizard.h" CampGrid::CampGrid(QWidget *parent) : GridForm(parent) { setTableModel(new AutoTableModel); } + +void CampGrid::handleNewRecord() +{ + CampWizard *wizard = new CampWizard(); + wizard->setAttribute(Qt::WA_DeleteOnClose); + + wizard->show(); +} + +void CampGrid::handleEditRecord() +{ + +} diff --git a/camp/campgrid.h b/camp/campgrid.h index 409b2e5..ff36e96 100644 --- a/camp/campgrid.h +++ b/camp/campgrid.h @@ -9,6 +9,11 @@ class CampGrid : public GridForm { public: CampGrid(QWidget *parent = NULL); + + // IGridForm interface +protected: + void handleNewRecord(); + void handleEditRecord(); }; #endif // CAMPGRID_H diff --git a/camp/campwizard.cpp b/camp/campwizard.cpp new file mode 100644 index 0000000..f2cb170 --- /dev/null +++ b/camp/campwizard.cpp @@ -0,0 +1,30 @@ +#include "campwizard.h" +#include "ui_campwizard.h" + +CampWizard::CampWizard(QWidget *parent) : + QWizard(parent), + ui(new Ui::CampWizard) +{ + ui->setupUi(this); + + m_dataBinder = new ObjectBinder(this); + m_dataBinder->registerBinding(ui->start); + m_dataBinder->registerBinding(ui->end); +} + +CampWizard::~CampWizard() +{ + delete ui; +} + +void CampWizard::setData(const CampDataPtr &data) +{ + m_data = data; + + m_dataBinder->setData(data.data()); +} + +void CampWizard::on_btnAdd_clicked() +{ + +} diff --git a/camp/campwizard.h b/camp/campwizard.h new file mode 100644 index 0000000..bd0583d --- /dev/null +++ b/camp/campwizard.h @@ -0,0 +1,31 @@ +#ifndef CAMPWIZARD_H +#define CAMPWIZARD_H + +#include +#include "data/camp-data.h" +#include + +namespace Ui { +class CampWizard; +} + +class CampWizard : public QWizard +{ + Q_OBJECT + +public: + explicit CampWizard(QWidget *parent = 0); + ~CampWizard(); + + void setData(const CampDataPtr &data); + +private slots: + void on_btnAdd_clicked(); + +private: + Ui::CampWizard *ui; + CampDataPtr m_data; + ObjectBinder *m_dataBinder; +}; + +#endif // CAMPWIZARD_H diff --git a/camp/campwizard.ui b/camp/campwizard.ui new file mode 100644 index 0000000..901aded --- /dev/null +++ b/camp/campwizard.ui @@ -0,0 +1,721 @@ + + + CampWizard + + + Qt::ApplicationModal + + + + 0 + 0 + 948 + 684 + + + + Camp record + + + + :/icons/campPlugin.svg:/icons/campPlugin.svg + + + QWizard::ClassicStyle + + + + + + + + 0 + + + + + From + + + + + + + d. M. yyyy + + + true + + + + + + + To + + + + + + + d. M. yyyy + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + People + + + + + + + + + Existing address + + + + + + + Add + + + + :/icons/new.svg:/icons/new.svg + + + + + + + + 0 + 0 + + + + + 450 + 0 + + + + New address + + + true + + + false + + + + + + Title + + + + + + + + + + First name + + + + + + + + + + Last name + + + + + + + + + + Date of birth + + + + + + + d. MM. yyyy + + + true + + + + + + + ID card + + + + + + + + + + ZTP + + + + + + + Street + + + + + + + + + + House number + + + + + + + + + + ZIP code + + + + + + + + + + City + + + + + + + + + + Country + + + + + + + true + + + + + + + + + + + 0 + 0 + + + + true + + + + + + + + + + + 150 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Remove + + + ... + + + + :/icons/remove.svg:/icons/remove.svg + + + + 24 + 24 + + + + true + + + + + + + false + + + Owner + + + ... + + + + :/icons/ok.svg:/icons/ok.svg + + + + 24 + 24 + + + + true + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + widget_9 + tableView + tablePeople + + + + + + + + + + + + + Services + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + ... + + + + + + + ... + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + Sale + + + + + + Apply sale + + + + + + + + + + + + + + + + + Summary + + + + + + + 0 + + + 0 + + + 0 + + + + + From: + + + + + + + TextLabel + + + + + + + To: + + + + + + + TextLabel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + + + Days: + + + + + + + TextLabel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + People: + + + + + + + + + + Services: + + + + + + + + + + + + + Sale: + + + + + + + TextLabel + + + + + + + + 75 + true + + + + Total: + + + + + + + + 75 + true + + + + TextLabel + + + + + + + + + + + + + Print + + + + :/icons/print.svg:/icons/print.svg + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + start + end + address + groupNew + title + firstName + lastName + birthDate + idCardNumber + ztp + addressStreet + addressHouseNumber + addressZipCode + addressCity + country + btnAdd + btnRemove + btnOwner + tablePeople + toolButton + toolButton_2 + tableView_3 + tableView_4 + tableView_5 + pushButton_2 + checkBox_2 + sale + tableView_2 + + + + + + +