From 0e803c23cba5e55e3d1ef3ba184d1e50eb6116ad Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sat, 6 May 2017 23:27:54 +0200 Subject: [PATCH] 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 - -