Addressbook plugin implementation

print
Zdenek Jonak 9 years ago
parent 2bb07716b9
commit f184ac92d9

@ -0,0 +1,31 @@
#include "addressbook.h"
#include "data/addressbookdata.h"
#include "addressbookform.h"
#include "addressbookgrid.h"
Addressbook::Addressbook()
{
}
void Addressbook::initServiceUi()
{
AddressbookGrid *grid = new AddressbookGrid();
AddressbookForm *form = new AddressbookForm();
m_service = new Service<AddressbookData>;
m_ui = grid;
((AddressbookGrid *) m_ui)->setForm(form);
}

@ -0,0 +1,28 @@
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include "addressbook_global.h"
#include <core.h>
#include <QObject>
#include <QtPlugin>
class ADDRESSBOOKSHARED_EXPORT Addressbook : public QObject, IMetaDataPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID PluginInterface_iid FILE "addressbook.json")
Q_INTERFACES(IPlugin)
public:
Addressbook();
protected:
void initServiceUi() Q_DECL_OVERRIDE;
};
#endif // ADDRESSBOOK_H

@ -0,0 +1,28 @@
{
"id" : "ADDRESSBOOK",
"name" : {
"default" : "Addressbook",
"CZ" : "Adresář"
},
"descriptoin" : {
"default" : "",
"CZ" : ""
},
"schemaVersion" : 1,
"sql" : [
"CREATE TABLE \"AddressbookData\" (
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
\"title\" TEXT NULL,
\"firstName\" TEXT NULL,
\"lastName\" TEXT NULL,
\"birthDate\" TEXT NULL,
\"idCardNumber\" TEXT NULL,
\"ztp\" INTEGER NOT NULL,
\"addressCity\" TEXT NULL,
\"addressStreet\" TEXT NULL,
\"addressHouseNumber\" TEXT NULL,
\"addressZipCode\" TEXT NULL);"
],
"dependencies" : []
}

@ -0,0 +1,66 @@
#-------------------------------------------------
#
# Project created by QtCreator 2016-02-09T21:27:28
#
#-------------------------------------------------
QT += widgets sql
QT -= gui
TARGET = addressbook
TEMPLATE = lib
DEFINES += ADDRESSBOOK_LIBRARY
SOURCES += addressbook.cpp \
data/addressbookdata.cpp \
addressbookform.cpp \
addressbookgrid.cpp \
addressbooktablemodel.cpp
HEADERS += addressbook.h\
addressbook_global.h \
data/addressbookdata.h \
addressbookform.h \
addressbookgrid.h \
addressbooktablemodel.h
unix {
target.path = /usr/lib
INSTALLS += target
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -Wno-unknown-pragmas
}
win32 {
QMAKE_CXXFLAGS += -wd4995 -wd4068
}
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../core/release/ -lcore
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../core/debug/ -lcore
else:unix: LIBS += -L$$OUT_PWD/../core/ -lcore
INCLUDEPATH += $$PWD/../core
DEPENDPATH += $$PWD/../core
DESTDIR = ../plugins
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber
else:unix: LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber
INCLUDEPATH += $$PWD/../qdecimal/src
INCLUDEPATH += $$PWD/../qdecimal/decnumber
DEPENDPATH += $$PWD/../qdecimal/src
ODB_FILES = addressbook/data/addressbookdata.h
H_DIR = $$PWD/data/*.h
include(../odb.pri)
OTHER_FILES += \
addressbook.json
FORMS += \
addressbookform.ui

@ -0,0 +1,12 @@
#ifndef ADDRESSBOOK_GLOBAL_H
#define ADDRESSBOOK_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(ADDRESSBOOK_LIBRARY)
# define ADDRESSBOOKSHARED_EXPORT Q_DECL_EXPORT
#else
# define ADDRESSBOOKSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // ADDRESSBOOK_GLOBAL_H

@ -0,0 +1,24 @@
#include "addressbookform.h"
#include "ui_addressbookform.h"
AddressbookForm::AddressbookForm(QWidget *parent) :
AutoForm<AddressbookData>(parent),
ui(new Ui::AddressbookForm)
{
ui->setupUi(this);
registerBinding(ui->title);
registerBinding(ui->firstName);
registerBinding(ui->lastName);
registerBinding(ui->birthDate);
registerBinding(ui->ztp);
registerBinding(ui->idCardNumber);
registerBinding(ui->addressCity);
registerBinding(ui->addressStreet);
registerBinding(ui->addressHouseNumber);
registerBinding(ui->addressZipCode);
}
AddressbookForm::~AddressbookForm()
{
delete ui;
}

@ -0,0 +1,28 @@
#ifndef ADDRESSBOOKFORM_H
#define ADDRESSBOOKFORM_H
#include <QWidget>
#include <QWidget>
#include "autoform.h"
#include "data/addressbookdata.h"
#include "addressbook-odb.hxx"
namespace Ui {
class AddressbookForm;
}
class AddressbookForm : public AutoForm<AddressbookData>
{
Q_OBJECT
public:
explicit AddressbookForm(QWidget *parent = 0);
~AddressbookForm();
private:
Ui::AddressbookForm *ui;
};
#endif // ADDRESSBOOKFORM_H

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressbookForm</class>
<widget class="QWidget" name="AddressbookForm">
<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>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="title"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>First Name</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="firstName"/>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lastName"/>
</item>
<item row="3" column="1">
<widget class="QDateEdit" name="birthDate">
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="idCardNumber"/>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="addressCity"/>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="addressStreet"/>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="addressZipCode"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Last Name</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Day of Birth</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>ID Card Number</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>City</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="ztp">
<property name="text">
<string>ZTP</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Street</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="addressHouseNumber"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>House Number</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>ZIP</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,10 @@
#include "addressbookgrid.h"
#include "addressbooktablemodel.h"
AddressbookGrid::AddressbookGrid(QWidget *parent):
GridForm<AddressbookData>(parent)
{
setTableModel(new AddressbookTableModel());
}

@ -0,0 +1,15 @@
#ifndef ADDRESSBOOKGRID_H
#define ADDRESSBOOKGRID_H
#include <core.h>
#include "data/addressbookdata.h"
#include "addressbook-odb.hxx"
class AddressbookGrid : public GridForm<AddressbookData>
{
Q_OBJECT
public:
AddressbookGrid(QWidget *parent = NULL);
};
#endif // ADDRESSBOOKGRID_H

@ -0,0 +1,7 @@
#include "addressbooktablemodel.h"
AddressbookTableModel::AddressbookTableModel(QObject *parent)
:AutoTableModel<AddressbookData>(parent)
{
}

@ -0,0 +1,15 @@
#ifndef ADDRESSBOOKTABLEMODEL_H
#define ADDRESSBOOKTABLEMODEL_H
#include <autotablemodel.h>
#include "data/addressbookdata.h"
class AddressbookTableModel : public AutoTableModel<AddressbookData>
{
Q_OBJECT
public:
AddressbookTableModel(QObject *parent= NULL);
};
#endif // ADDRESSBOOKTABLEMODEL_H

@ -0,0 +1,108 @@
#include "addressbookdata.h"
AddressbookData::AddressbookData(QObject * parent)
:QObject(parent)
{
}
QString AddressbookData::title() const
{
return m_title;
}
void AddressbookData::setTitle(const QString &title)
{
m_title = title;
}
QString AddressbookData::firstName() const
{
return m_firstName;
}
void AddressbookData::setFirstName(const QString &firstName)
{
m_firstName = firstName;
}
QString AddressbookData::lastName() const
{
return m_lastName;
}
void AddressbookData::setLastName(const QString &lastName)
{
m_lastName = lastName;
}
QDate AddressbookData::birthDate() const
{
return m_birthDate;
}
void AddressbookData::setBirthDate(const QDate &birthDate)
{
m_birthDate = birthDate;
}
QString AddressbookData::idCardNumber() const
{
return m_idCardNumber;
}
void AddressbookData::setIdCardNumber(const QString &idCardNumber)
{
m_idCardNumber = idCardNumber;
}
bool AddressbookData::ztp() const
{
return m_ztp;
}
void AddressbookData::setZtp(bool ztp)
{
m_ztp = ztp;
}
QString AddressbookData::addressCity() const
{
return m_addressCity;
}
void AddressbookData::setAddressCity(const QString &addressCity)
{
m_addressCity = addressCity;
}
QString AddressbookData::addressStreet() const
{
return m_addressStreet;
}
void AddressbookData::setAddressStreet(const QString &addressStreet)
{
m_addressStreet = addressStreet;
}
QString AddressbookData::addressHouseNumber() const
{
return m_addressHouseNumber;
}
void AddressbookData::setAddressHouseNumber(const QString &addressHouseNumber)
{
m_addressHouseNumber = addressHouseNumber;
}
QString AddressbookData::addressZipCode() const
{
return m_addressZipCode;
}
void AddressbookData::setAddressZipCode(const QString &addressZipCode)
{
m_addressZipCode = addressZipCode;
}
int AddressbookData::id() const
{
return m_id;
}
void AddressbookData::setId(int id)
{
m_id = id;
}

@ -0,0 +1,75 @@
#ifndef ADDRESSBOOKDATA_H
#define ADDRESSBOOKDATA_H
#include <QObject>
#include <QString>
#include <QDate>
#include "odb/core.hxx"
#pragma db object
class AddressbookData : public QObject
{
Q_OBJECT
Q_PROPERTY(QString title READ title WRITE setTitle)
Q_PROPERTY(QString firstName READ firstName WRITE setFirstName)
Q_PROPERTY(QString lastName READ lastName WRITE setLastName)
Q_PROPERTY(QDate birthDate READ birthDate WRITE setBirthDate)
Q_PROPERTY(QString idCardNumber READ idCardNumber WRITE setIdCardNumber)
Q_PROPERTY(bool ztp READ ztp WRITE setZtp)
Q_PROPERTY(QString addressCity READ addressCity WRITE setAddressCity)
Q_PROPERTY(QString addressStreet READ addressStreet WRITE setAddressStreet)
Q_PROPERTY(QString addressHouseNumber READ addressHouseNumber WRITE setAddressHouseNumber)
Q_PROPERTY(QString addressZipCode READ addressZipCode WRITE setAddressZipCode)
public:
AddressbookData(QObject *parent = 0);
QString title() const;
void setTitle(const QString &title);
QString firstName() const;
void setFirstName(const QString &firstName);
QString lastName() const;
void setLastName(const QString &lastName);
QDate birthDate() const;
void setBirthDate(const QDate &birthDate);
QString idCardNumber() const;
void setIdCardNumber(const QString &idCardNumber);
bool ztp() const;
void setZtp(bool ztp);
QString addressCity() const;
void setAddressCity(const QString &addressCity);
QString addressStreet() const;
void setAddressStreet(const QString &addressStreet);
QString addressHouseNumber() const;
void setAddressHouseNumber(const QString &addressHouseNumber);
QString addressZipCode() const;
void setAddressZipCode(const QString &addressZipCode);
int id() const;
void setId(int id);
private:
friend class odb::access;
#pragma db id auto
int m_id;
QString m_title;
QString m_firstName;
QString m_lastName;
QDate m_birthDate;
QString m_idCardNumber;
bool m_ztp;
QString m_addressCity;
QString m_addressStreet;
QString m_addressHouseNumber;
QString m_addressZipCode;
};
#endif // ADDRESSBOOKDATA_H
Loading…
Cancel
Save