From de7e0fc9c4c1b0f66f120abe6acb60cddd171563 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 13 Nov 2015 15:13:44 +0100 Subject: [PATCH] Updated Accommodation testing plugin. --- accommodation/accommodation.cpp | 10 +++++++ accommodation/accommodation.h | 4 +++ accommodation/accommodation.json | 8 ++++++ accommodation/accommodation.pro | 13 ++++++--- accommodation/accommodationform.cpp | 25 +++++++++++++++++ accommodation/accommodationform.h | 2 ++ accommodation/accommodationform.ui | 12 +++++++- accommodation/accommodationservice.cpp | 13 ++++++++- accommodation/accommodationservice.h | 5 ++-- accommodation/acform.cpp | 17 +++++++++++ accommodation/acform.h | 25 +++++++++++++++++ accommodation/acform.ui | 39 ++++++++++++++++++++++++++ accommodation/data/person.h | 3 ++ accommodation/dialog.cpp | 13 ++++++++- accommodation/dialog.h | 6 ++++ accommodation/dialog.ui | 15 ++++++++-- accommodation/tablemodel.cpp | 8 ++++++ accommodation/tablemodel.h | 18 ++++++++++++ 18 files changed, 225 insertions(+), 11 deletions(-) create mode 100644 accommodation/acform.cpp create mode 100644 accommodation/acform.h create mode 100644 accommodation/acform.ui create mode 100644 accommodation/tablemodel.cpp create mode 100644 accommodation/tablemodel.h diff --git a/accommodation/accommodation.cpp b/accommodation/accommodation.cpp index 1a24ac4..faf2b91 100644 --- a/accommodation/accommodation.cpp +++ b/accommodation/accommodation.cpp @@ -18,6 +18,16 @@ void Accommodation::initServiceUi() m_service = service; } +QWidget *Accommodation::ui() +{ + QWidget *ui = IPlugin::ui(); + AccommodationForm *form = qobject_cast(ui); + + form->fillGrid(); + + return ui; +} + /* QString Accommodation::pluginName() { diff --git a/accommodation/accommodation.h b/accommodation/accommodation.h index 8d55730..9dbf7ff 100644 --- a/accommodation/accommodation.h +++ b/accommodation/accommodation.h @@ -23,6 +23,10 @@ public: protected: void initServiceUi() Q_DECL_OVERRIDE; + + // IPlugin interface +public: + QWidget *ui(); }; #endif // ACCOMMODATION_H diff --git a/accommodation/accommodation.json b/accommodation/accommodation.json index c889e70..dbe0e59 100644 --- a/accommodation/accommodation.json +++ b/accommodation/accommodation.json @@ -8,5 +8,13 @@ "default" : "", "CZ" : "" }, + "schemaVersion" : 1, + "sql" : [ + "CREATE TABLE \"Person\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"firstName\" TEXT NULL, + \"lastName\" TEXT NULL);" + + ], "dependencies" : [] } diff --git a/accommodation/accommodation.pro b/accommodation/accommodation.pro index 27c0f12..3c9fee7 100644 --- a/accommodation/accommodation.pro +++ b/accommodation/accommodation.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += widgets +QT += widgets sql TARGET = accommodation TEMPLATE = lib @@ -15,14 +15,18 @@ SOURCES += accommodation.cpp \ accommodationform.cpp \ data/person.cpp \ dialog.cpp \ - accommodationservice.cpp + accommodationservice.cpp \ + tablemodel.cpp \ + acform.cpp HEADERS += accommodation.h\ accommodation_global.h \ accommodationform.h \ data/person.h \ dialog.h \ - accommodationservice.h + accommodationservice.h \ + tablemodel.h \ + acform.h unix { target.path = /usr/lib @@ -43,7 +47,8 @@ OTHER_FILES += \ FORMS += \ accommodationform.ui \ - dialog.ui + dialog.ui \ + acform.ui ODB_FILES = accommodation/data/person.h H_DIR = $$PWD/data/*.h diff --git a/accommodation/accommodationform.cpp b/accommodation/accommodationform.cpp index 8df9782..ffe052f 100644 --- a/accommodation/accommodationform.cpp +++ b/accommodation/accommodationform.cpp @@ -1,7 +1,15 @@ #include "accommodationform.h" #include "ui_accommodationform.h" +#include +#include + #include "dialog.h" +#include "data/person.h" + +#include "tablemodel.h" + +#include "accommodation-odb.hxx" AccommodationForm::AccommodationForm(QWidget *parent) : QWidget(parent), @@ -15,8 +23,25 @@ AccommodationForm::~AccommodationForm() delete ui; } +void AccommodationForm::fillGrid() +{ + Service service; + TableModel *model = qobject_cast(ui->tableView->model()); + + if (model == NULL) { + model = new TableModel(); + } + + model->setData(service.all()); + ui->tableView->setModel(model); +} + void AccommodationForm::on_pushButton_clicked() { Dialog *d = new Dialog(); + if (ui->tableView->model()->rowCount() > 0) + { + d->setData(((TableModel*)ui->tableView->model())->itemFromIndex(ui->tableView->currentIndex())); + } d->open(); } diff --git a/accommodation/accommodationform.h b/accommodation/accommodationform.h index 0fcdcd9..ad5c602 100644 --- a/accommodation/accommodationform.h +++ b/accommodation/accommodationform.h @@ -15,6 +15,8 @@ public: explicit AccommodationForm(QWidget *parent = 0); ~AccommodationForm(); + void fillGrid(); + private slots: void on_pushButton_clicked(); diff --git a/accommodation/accommodationform.ui b/accommodation/accommodationform.ui index 68a7aa7..820a5df 100644 --- a/accommodation/accommodationform.ui +++ b/accommodation/accommodationform.ui @@ -22,7 +22,17 @@ - + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + diff --git a/accommodation/accommodationservice.cpp b/accommodation/accommodationservice.cpp index e0a7038..7051c5b 100644 --- a/accommodation/accommodationservice.cpp +++ b/accommodation/accommodationservice.cpp @@ -1,5 +1,10 @@ #include "accommodationservice.h" +#include +#include + +#include "accommodation-odb.hxx" + AccommodationService::AccommodationService() { @@ -10,8 +15,14 @@ AccommodationService::~AccommodationService() } -void AccommodationService::pokus() +void AccommodationService::pokus(QSharedPointer entity) { + odb::database *db = Context::instance().db(); + //odb::transaction tr(db->begin()); + Transaction tr; + this->all(); + db->persist(entity); + tr.commit(); } diff --git a/accommodation/accommodationservice.h b/accommodation/accommodationservice.h index df75c2b..db333fb 100644 --- a/accommodation/accommodationservice.h +++ b/accommodation/accommodationservice.h @@ -5,14 +5,15 @@ #include #include "accommodation_global.h" +#include "accommodation-odb.hxx" -class AccommodationService : public Service +class ACCOMMODATIONSHARED_EXPORT AccommodationService : public Service { public: AccommodationService(); ~AccommodationService(); - void pokus(); + void pokus(QSharedPointer entity); }; #endif // ACCOMMODATIONSERVICE_H diff --git a/accommodation/acform.cpp b/accommodation/acform.cpp new file mode 100644 index 0000000..e412f6c --- /dev/null +++ b/accommodation/acform.cpp @@ -0,0 +1,17 @@ +#include "acform.h" +#include "ui_acform.h" + +AcForm::AcForm(QWidget *parent) : + AutoForm(parent), + ui(new Ui::AcForm) +{ + ui->setupUi(this); + + registerBinding(ui->firstName); + registerBinding(ui->lastName); +} + +AcForm::~AcForm() +{ + delete ui; +} diff --git a/accommodation/acform.h b/accommodation/acform.h new file mode 100644 index 0000000..441c767 --- /dev/null +++ b/accommodation/acform.h @@ -0,0 +1,25 @@ +#ifndef ACFORM_H +#define ACFORM_H + +#include +#include + +#include "data/person.h" + +namespace Ui { +class AcForm; +} + +class AcForm : public AutoForm +{ + Q_OBJECT + +public: + explicit AcForm(QWidget *parent = 0); + ~AcForm(); + +private: + Ui::AcForm *ui; +}; + +#endif // ACFORM_H diff --git a/accommodation/acform.ui b/accommodation/acform.ui new file mode 100644 index 0000000..cff0c6f --- /dev/null +++ b/accommodation/acform.ui @@ -0,0 +1,39 @@ + + + AcForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 90 + 60 + 191 + 20 + + + + + + + 90 + 110 + 191 + 20 + + + + + + + diff --git a/accommodation/data/person.h b/accommodation/data/person.h index 3c1e828..015b2f7 100644 --- a/accommodation/data/person.h +++ b/accommodation/data/person.h @@ -10,6 +10,9 @@ class Person : public QObject { Q_OBJECT + + Q_PROPERTY(QString firstName READ getFirstName WRITE setFirstName) + Q_PROPERTY(QString lastName READ getLastName WRITE setLastName) public: Person(); diff --git a/accommodation/dialog.cpp b/accommodation/dialog.cpp index 3860037..54071ba 100644 --- a/accommodation/dialog.cpp +++ b/accommodation/dialog.cpp @@ -6,6 +6,8 @@ #include "data/person.h" #include "accommodationservice.h" +#include "acform.h" + #include "accommodation-odb.hxx" Dialog::Dialog(QWidget *parent) : @@ -20,6 +22,15 @@ Dialog::~Dialog() delete ui; } +void Dialog::setData(QSharedPointer data) +{ + m_data = data; + + AcForm *form = new AcForm(this); + form->setEntity(data); + ui->verticalLayout->addWidget(form); +} + void Dialog::on_buttonBox_accepted() { IPlugin *plugin = Context::instance().plugins().at(0); @@ -29,5 +40,5 @@ void Dialog::on_buttonBox_accepted() p->setLastName(ui->lineEdit_2->text()); AccommodationService *service = (AccommodationService*)plugin->service(); - service->save(p); + service->pokus(p); } diff --git a/accommodation/dialog.h b/accommodation/dialog.h index 5e8c556..fdcee67 100644 --- a/accommodation/dialog.h +++ b/accommodation/dialog.h @@ -2,6 +2,9 @@ #define DIALOG_H #include +#include + +#include "data/person.h" namespace Ui { class Dialog; @@ -15,11 +18,14 @@ public: explicit Dialog(QWidget *parent = 0); ~Dialog(); + void setData(QSharedPointer data); + private slots: void on_buttonBox_accepted(); private: Ui::Dialog *ui; + QSharedPointer m_data; }; #endif // DIALOG_H diff --git a/accommodation/dialog.ui b/accommodation/dialog.ui index 5ef4676..ad30caa 100644 --- a/accommodation/dialog.ui +++ b/accommodation/dialog.ui @@ -7,7 +7,7 @@ 0 0 544 - 355 + 444 @@ -17,7 +17,7 @@ 30 - 240 + 340 341 32 @@ -49,6 +49,17 @@ + + + + 60 + 130 + 421 + 191 + + + + diff --git a/accommodation/tablemodel.cpp b/accommodation/tablemodel.cpp new file mode 100644 index 0000000..531eeab --- /dev/null +++ b/accommodation/tablemodel.cpp @@ -0,0 +1,8 @@ +#include "tablemodel.h" + +TableModel::TableModel(QObject *parent) + :AutoTableModel(parent) +{ + +} + diff --git a/accommodation/tablemodel.h b/accommodation/tablemodel.h new file mode 100644 index 0000000..bfde631 --- /dev/null +++ b/accommodation/tablemodel.h @@ -0,0 +1,18 @@ +#ifndef TABLEMODEL_H +#define TABLEMODEL_H + +#include +#include + +#include "data/person.h" + +class TableModel : public AutoTableModel +{ + Q_OBJECT + +public: + explicit TableModel(QObject *parent = NULL); + +}; + +#endif // TABLEMODEL_H