Updated Accommodation testing plugin.

print
Josef Rokos 9 years ago
parent 7c90c66468
commit de7e0fc9c4

@ -18,6 +18,16 @@ void Accommodation::initServiceUi()
m_service = service;
}
QWidget *Accommodation::ui()
{
QWidget *ui = IPlugin::ui();
AccommodationForm *form = qobject_cast<AccommodationForm*>(ui);
form->fillGrid();
return ui;
}
/*
QString Accommodation::pluginName()
{

@ -23,6 +23,10 @@ public:
protected:
void initServiceUi() Q_DECL_OVERRIDE;
// IPlugin interface
public:
QWidget *ui();
};
#endif // ACCOMMODATION_H

@ -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" : []
}

@ -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

@ -1,7 +1,15 @@
#include "accommodationform.h"
#include "ui_accommodationform.h"
#include <core.h>
#include <autotablemodel.h>
#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<Person> service;
TableModel *model = qobject_cast<TableModel*>(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();
}

@ -15,6 +15,8 @@ public:
explicit AccommodationForm(QWidget *parent = 0);
~AccommodationForm();
void fillGrid();
private slots:
void on_pushButton_clicked();

@ -22,7 +22,17 @@
</widget>
</item>
<item>
<widget class="QTableView" name="tableView"/>
<widget class="QTableView" name="tableView">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>

@ -1,5 +1,10 @@
#include "accommodationservice.h"
#include <odb/database.hxx>
#include <odb/transaction.hxx>
#include "accommodation-odb.hxx"
AccommodationService::AccommodationService()
{
@ -10,8 +15,14 @@ AccommodationService::~AccommodationService()
}
void AccommodationService::pokus()
void AccommodationService::pokus(QSharedPointer<Person> entity)
{
odb::database *db = Context::instance().db();
//odb::transaction tr(db->begin());
Transaction tr;
this->all();
db->persist(entity);
tr.commit();
}

@ -5,14 +5,15 @@
#include <core.h>
#include "accommodation_global.h"
#include "accommodation-odb.hxx"
class AccommodationService : public Service<Person>
class ACCOMMODATIONSHARED_EXPORT AccommodationService : public Service<Person>
{
public:
AccommodationService();
~AccommodationService();
void pokus();
void pokus(QSharedPointer<Person> entity);
};
#endif // ACCOMMODATIONSERVICE_H

@ -0,0 +1,17 @@
#include "acform.h"
#include "ui_acform.h"
AcForm::AcForm(QWidget *parent) :
AutoForm<Person>(parent),
ui(new Ui::AcForm)
{
ui->setupUi(this);
registerBinding(ui->firstName);
registerBinding(ui->lastName);
}
AcForm::~AcForm()
{
delete ui;
}

@ -0,0 +1,25 @@
#ifndef ACFORM_H
#define ACFORM_H
#include <QWidget>
#include <autoform.h>
#include "data/person.h"
namespace Ui {
class AcForm;
}
class AcForm : public AutoForm<Person>
{
Q_OBJECT
public:
explicit AcForm(QWidget *parent = 0);
~AcForm();
private:
Ui::AcForm *ui;
};
#endif // ACFORM_H

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AcForm</class>
<widget class="QWidget" name="AcForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLineEdit" name="firstName">
<property name="geometry">
<rect>
<x>90</x>
<y>60</y>
<width>191</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lastName">
<property name="geometry">
<rect>
<x>90</x>
<y>110</y>
<width>191</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

@ -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();

@ -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<Person> 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<Person>();
service->save(p);
service->pokus(p);
}

@ -2,6 +2,9 @@
#define DIALOG_H
#include <QDialog>
#include <QSharedPointer>
#include "data/person.h"
namespace Ui {
class Dialog;
@ -15,11 +18,14 @@ public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
void setData(QSharedPointer<Person> data);
private slots:
void on_buttonBox_accepted();
private:
Ui::Dialog *ui;
QSharedPointer<Person> m_data;
};
#endif // DIALOG_H

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>544</width>
<height>355</height>
<height>444</height>
</rect>
</property>
<property name="windowTitle">
@ -17,7 +17,7 @@
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<y>340</y>
<width>341</width>
<height>32</height>
</rect>
@ -49,6 +49,17 @@
</rect>
</property>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>60</x>
<y>130</y>
<width>421</width>
<height>191</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
</widget>
<resources/>
<connections>

@ -0,0 +1,8 @@
#include "tablemodel.h"
TableModel::TableModel(QObject *parent)
:AutoTableModel<Person>(parent)
{
}

@ -0,0 +1,18 @@
#ifndef TABLEMODEL_H
#define TABLEMODEL_H
#include <core.h>
#include <autotablemodel.h>
#include "data/person.h"
class TableModel : public AutoTableModel<Person>
{
Q_OBJECT
public:
explicit TableModel(QObject *parent = NULL);
};
#endif // TABLEMODEL_H
Loading…
Cancel
Save