diff --git a/application/mainwindow.cpp b/application/mainwindow.cpp index 989eb1d..daff678 100644 --- a/application/mainwindow.cpp +++ b/application/mainwindow.cpp @@ -42,7 +42,7 @@ MainWindow::MainWindow(QWidget *parent) : int i = 0; foreach (IPlugin *plugin, Context::instance().plugins()) { - if (plugin->pluginId() != "CORE") + if (plugin->pluginId() != "CORE" && plugin->showIcon()) { QToolButton *plugButton = new QToolButton(this); plugButton->setText(plugin->pluginName()); @@ -81,26 +81,16 @@ void MainWindow::openPlugin() QVariant var = QObject::sender()->property(PLUGIN_INDEX); IPlugin *plugin = Context::instance().plugins().at(var.toInt()); - for (int i = 0; i < ui->tabWidget->count(); i++) { - if (ui->tabWidget->widget(i)->objectName() == plugin->pluginId()) { - ui->tabWidget->setCurrentIndex(i); - return; - } - } - - if (plugin->ui() != NULL) - { - ui->tabWidget->addTab(plugin->ui(), plugin->pluginIcon(), plugin->pluginName()); - ui->tabWidget->widget(ui->tabWidget->count() - 1)->setObjectName(plugin->pluginId()); - ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); - } + openPlugin(plugin); } void MainWindow::on_actionOpen_database_triggered() { - /*QFileDialog dialog(this); - dialog.setNameFilter(tr("Database Files (*.db)")); - dialog.setWindowTitle(tr("Open Database"));*/ + int tabCount = ui->tabWidget->count(); + for (int i = 0; i < tabCount; i++) + { + ui->tabWidget->removeTab(0); + } QString dbFile = QFileDialog::getOpenFileName(this, "Open Database", "", "Database Files (*.db)"); if (!dbFile.isEmpty()) @@ -118,6 +108,12 @@ void MainWindow::on_tabWidget_tabCloseRequested(int index) void MainWindow::on_actionLogin_triggered() { + int tabCount = ui->tabWidget->count(); + for (int i = 0; i < tabCount; i++) + { + ui->tabWidget->removeTab(0); + } + QSharedPointer u; Context::instance().setCurrentUser(u); m_lblUser->setText(""); @@ -144,3 +140,30 @@ void MainWindow::on_actionSettings_triggered() SettingsForm *settings = new SettingsForm(this); settings->show(); } + +void MainWindow::on_actionPost_register_triggered() +{ + IPlugin *plugZipCodes = Context::instance().plugin("POSTREGISTER"); + + if (plugZipCodes != NULL) + { + openPlugin(plugZipCodes); + } +} + +void MainWindow::openPlugin(IPlugin *plugin) +{ + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->widget(i)->objectName() == plugin->pluginId()) { + ui->tabWidget->setCurrentIndex(i); + return; + } + } + + if (plugin->ui() != NULL) + { + ui->tabWidget->addTab(plugin->ui(), plugin->pluginIcon(), plugin->pluginName()); + ui->tabWidget->widget(ui->tabWidget->count() - 1)->setObjectName(plugin->pluginId()); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + } +} diff --git a/application/mainwindow.h b/application/mainwindow.h index 305ab1b..1f61002 100644 --- a/application/mainwindow.h +++ b/application/mainwindow.h @@ -9,6 +9,8 @@ #define PLUGIN_INDEX "plug_index" +class IPlugin; + namespace Ui { class MainWindow; } @@ -33,10 +35,13 @@ private slots: void on_actionSettings_triggered(); + void on_actionPost_register_triggered(); + private: Ui::MainWindow *ui; LoginDialog *m_loginDialog; QLabel *m_lblUser; + void openPlugin(IPlugin *plugin); // QWidget interface protected: diff --git a/application/mainwindow.ui b/application/mainwindow.ui index e97c89e..7b912f7 100644 --- a/application/mainwindow.ui +++ b/application/mainwindow.ui @@ -60,7 +60,7 @@ 0 0 1000 - 19 + 20 @@ -72,7 +72,14 @@ + + + &Registers + + + + @@ -116,6 +123,11 @@ Settings + + + Post register + + diff --git a/camp/camp.pro b/camp/camp.pro index 37e7891..1ef3cb9 100644 --- a/camp/camp.pro +++ b/camp/camp.pro @@ -45,11 +45,6 @@ H_DIR = $$PWD/data/*.h ODB_OTHER_INCLUDES = -I $$PWD/../shop -I $$PWD/../addressbook/data -I $$PWD/../services/data include(../odb.pri) -unix { - target.path = /usr/lib - INSTALLS += target -} - win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lshop diff --git a/postregister/data/postdata.cpp b/postregister/data/postdata.cpp new file mode 100644 index 0000000..5ed831c --- /dev/null +++ b/postregister/data/postdata.cpp @@ -0,0 +1,76 @@ +#include "postdata.h" + +PostData::PostData(QObject *parent) + :QObject(parent) +{ +} + +QString PostData::townPart() const +{ + return m_townPart; +} + +void PostData::setTownPart(const QString &townPart) +{ + m_townPart = townPart; +} + +int PostData::id() const +{ + return m_id; +} + +void PostData::setId(int id) +{ + m_id = id; +} + +QString PostData::zipCode() const +{ + return m_zipCode; +} + +void PostData::setZipCode(const QString &zipCode) +{ + m_zipCode = zipCode; +} + +QString PostData::postName() const +{ + return m_postName; +} + +void PostData::setPostName(const QString &postName) +{ + m_postName = postName; +} + +QString PostData::code() const +{ + return m_code; +} + +void PostData::setCode(const QString &code) +{ + m_code = code; +} + +QString PostData::township() const +{ + return m_township; +} + +void PostData::setTownship(const QString &township) +{ + m_township = township; +} + +QString PostData::town() const +{ + return m_town; +} + +void PostData::setTown(const QString &town) +{ + m_town = town; +} diff --git a/postregister/data/postdata.h b/postregister/data/postdata.h new file mode 100644 index 0000000..c7cd2b7 --- /dev/null +++ b/postregister/data/postdata.h @@ -0,0 +1,55 @@ +#ifndef POSTDATA_H +#define POSTDATA_H + +#include +#include +#include + +#pragma db object +class PostData : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString townPart READ townPart WRITE setTownPart) + Q_PROPERTY(QString zipCode READ zipCode WRITE setZipCode) + Q_PROPERTY(QString postName READ postName WRITE setPostName) + Q_PROPERTY(QString code READ code WRITE setCode) + Q_PROPERTY(QString township READ township WRITE setTownship) + Q_PROPERTY(QString town READ town WRITE setTown) + +public: + Q_INVOKABLE explicit PostData(QObject *parent = NULL); + + QString townPart() const; + void setTownPart(const QString &townPart); + + int id() const; + void setId(int id); + + QString zipCode() const; + void setZipCode(const QString &zipCode); + + QString postName() const; + void setPostName(const QString &postName); + + QString code() const; + void setCode(const QString &code); + + QString township() const; + void setTownship(const QString &township); + + QString town() const; + void setTown(const QString &town); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_townPart; + QString m_zipCode; + QString m_postName; + QString m_code; + QString m_township; + QString m_town; +}; + +#endif // POSTDATA_H diff --git a/postregister/icons/import.svg b/postregister/icons/import.svg new file mode 100644 index 0000000..60c43bb --- /dev/null +++ b/postregister/icons/import.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/postregister/importdialog.cpp b/postregister/importdialog.cpp new file mode 100644 index 0000000..a54c212 --- /dev/null +++ b/postregister/importdialog.cpp @@ -0,0 +1,46 @@ +#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/importdialog.h b/postregister/importdialog.h new file mode 100644 index 0000000..833f0bd --- /dev/null +++ b/postregister/importdialog.h @@ -0,0 +1,27 @@ +#ifndef IMPORTDIALOG_H +#define IMPORTDIALOG_H + +#include + +namespace Ui { +class ImportDialog; +} + +class ImportDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ImportDialog(QWidget *parent = 0); + ~ImportDialog(); + +private slots: + void on_buttonBox_accepted(); + + void on_btnFile_clicked(); + +private: + Ui::ImportDialog *ui; +}; + +#endif // IMPORTDIALOG_H diff --git a/postregister/importdialog.ui b/postregister/importdialog.ui new file mode 100644 index 0000000..48410fd --- /dev/null +++ b/postregister/importdialog.ui @@ -0,0 +1,122 @@ + + + ImportDialog + + + + 0 + 0 + 518 + 152 + + + + Dialog + + + + 10 + + + 10 + + + + + CSV file + + + + + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + ... + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Field separator + + + + + + + ; + + + + + + + + + buttonBox + accepted() + ImportDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ImportDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/postregister/importprogressform.cpp b/postregister/importprogressform.cpp new file mode 100644 index 0000000..67480bd --- /dev/null +++ b/postregister/importprogressform.cpp @@ -0,0 +1,34 @@ +#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 new file mode 100644 index 0000000..27811bf --- /dev/null +++ b/postregister/importprogressform.h @@ -0,0 +1,32 @@ +#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/importprogressform.ui b/postregister/importprogressform.ui new file mode 100644 index 0000000..af184bc --- /dev/null +++ b/postregister/importprogressform.ui @@ -0,0 +1,35 @@ + + + ImportProgressForm + + + + 0 + 0 + 369 + 134 + + + + Form + + + + + + 24 + + + + + + + Cancel + + + + + + + + diff --git a/postregister/postregister.cpp b/postregister/postregister.cpp new file mode 100644 index 0000000..7824837 --- /dev/null +++ b/postregister/postregister.cpp @@ -0,0 +1,18 @@ +#include "postregister.h" + +#include "postregistergrid.h" + +PostRegister::PostRegister() +{ +} + +void PostRegister::initServiceUi() +{ + m_service = new Service(); + m_ui = new PostRegisterGrid(); +} + +bool PostRegister::showIcon() +{ + return false; +} diff --git a/postregister/postregister.h b/postregister/postregister.h new file mode 100644 index 0000000..8f39bd9 --- /dev/null +++ b/postregister/postregister.h @@ -0,0 +1,26 @@ +#ifndef POSTREGISTER_H +#define POSTREGISTER_H + +#include "postregister_global.h" +#include +#include + +class POSTREGISTERSHARED_EXPORT PostRegister : public QObject, IMetaDataPlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID PluginInterface_iid FILE "postregister.json") + Q_INTERFACES(IPlugin) +public: + PostRegister(); + + // IMetaDataPlugin interface +protected: + void initServiceUi(); + + // IPlugin interface +public: + bool showIcon(); +}; + +#endif // POSTREGISTER_H diff --git a/postregister/postregister.json b/postregister/postregister.json new file mode 100644 index 0000000..b96a491 --- /dev/null +++ b/postregister/postregister.json @@ -0,0 +1,34 @@ +{ + "id" : "POSTREGISTER", + "name" : { + "default" : "Post register", + "CZ" : "Číselník PSČ" + }, + "descriptoin" : { + "default" : "", + "CZ" : "" + }, + "schemaVersion" : 1, + "sql" : [ +"CREATE TABLE \"PostData\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"townPart\" TEXT NULL, + \"zipCode\" TEXT NULL, + \"postName\" TEXT NULL, + \"code\" TEXT NULL, + \"township\" TEXT NULL, + \"town\" TEXT NULL); +" + ], + "dependencies" : [ ], + "translations" : { + "CZ" : { + "townPart" : "Část obce", + "zipCode" : "PSČ", + "postName" : "Pošta", + "code" : "Kód", + "township" : "Okres", + "town" : "Obec" + } + } +} diff --git a/postregister/postregister.pro b/postregister/postregister.pro new file mode 100644 index 0000000..f99124e --- /dev/null +++ b/postregister/postregister.pro @@ -0,0 +1,52 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-04-21T08:14:36 +# +#------------------------------------------------- + +QT += widgets sql + +TARGET = postregister +TEMPLATE = lib + +DEFINES += POSTREGISTER_LIBRARY + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += postregister.cpp \ + data/postdata.cpp \ + postregistergrid.cpp \ + importdialog.cpp \ + importprogressform.cpp + +HEADERS += postregister.h\ + postregister_global.h \ + data/postdata.h \ + postregistergrid.h \ + importdialog.h \ + importprogressform.h + +include(../config_plugin.pri) + +ODB_FILES = postregister/data/postdata.h +H_DIR = $$PWD/data/*.h +include(../odb.pri) + +DISTFILES += \ + postregister.json + +FORMS += \ + importdialog.ui \ + importprogressform.ui + +RESOURCES += \ + postregisterrc.qrc diff --git a/postregister/postregister_global.h b/postregister/postregister_global.h new file mode 100644 index 0000000..99d2cc7 --- /dev/null +++ b/postregister/postregister_global.h @@ -0,0 +1,12 @@ +#ifndef POSTREGISTER_GLOBAL_H +#define POSTREGISTER_GLOBAL_H + +#include + +#if defined(POSTREGISTER_LIBRARY) +# define POSTREGISTERSHARED_EXPORT Q_DECL_EXPORT +#else +# define POSTREGISTERSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // POSTREGISTER_GLOBAL_H diff --git a/postregister/postregistergrid.cpp b/postregister/postregistergrid.cpp new file mode 100644 index 0000000..77af64f --- /dev/null +++ b/postregister/postregistergrid.cpp @@ -0,0 +1,45 @@ +#include "postregistergrid.h" +#include +#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(); + }); + } +} + +bool PostRegisterGrid::canAddRecord() +{ + return false; +} + +bool PostRegisterGrid::canEditRecord() +{ + return false; +} + +bool PostRegisterGrid::canDeleteRecord() +{ + return false; +} diff --git a/postregister/postregistergrid.h b/postregister/postregistergrid.h new file mode 100644 index 0000000..226de16 --- /dev/null +++ b/postregister/postregistergrid.h @@ -0,0 +1,19 @@ +#ifndef POSTREGISTERGRID_H +#define POSTREGISTERGRID_H + +#include +#include "data/postdata.h" + +class PostRegisterGrid : public GridForm +{ +public: + PostRegisterGrid(QWidget *parent = NULL); + + // IGridForm interface +protected: + bool canAddRecord(); + bool canEditRecord(); + bool canDeleteRecord(); +}; + +#endif // POSTREGISTERGRID_H diff --git a/postregister/postregisterrc.qrc b/postregister/postregisterrc.qrc new file mode 100644 index 0000000..3bd9e96 --- /dev/null +++ b/postregister/postregisterrc.qrc @@ -0,0 +1,5 @@ + + + icons/import.svg + + diff --git a/prodejna.pro b/prodejna.pro index 95848ec..5134588 100644 --- a/prodejna.pro +++ b/prodejna.pro @@ -9,5 +9,6 @@ SUBDIRS += \ addressbook \ shop \ commodity \ - camp + camp \ + postregister