Added country combo to addressbook. Addressbook plugin depends on Countryregister which must be loaded first.

master
Josef Rokos 8 years ago
parent 4c00364698
commit d5ead1b187

@ -8,7 +8,7 @@
"default" : "", "default" : "",
"CZ" : "" "CZ" : ""
}, },
"schemaVersion" : 1, "schemaVersion" : 2,
"sql" : [ "sql" : [
"CREATE TABLE \"AddressbookData\" ( "CREATE TABLE \"AddressbookData\" (
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
@ -21,10 +21,14 @@
\"addressCity\" TEXT NULL, \"addressCity\" TEXT NULL,
\"addressStreet\" TEXT NULL, \"addressStreet\" TEXT NULL,
\"addressHouseNumber\" TEXT NULL, \"addressHouseNumber\" TEXT NULL,
\"addressZipCode\" TEXT NULL);" \"addressZipCode\" TEXT NULL);
",
"ALTER TABLE AddressbookData ADD \"country\" INTEGER NULL;
"
], ],
"dependencies" : [], "dependencies" : [ "COUNTRYREGISTER" ],
"translations" : { "translations" : {
"CZ" : { "CZ" : {
"title" : "Titul", "title" : "Titul",

@ -32,6 +32,7 @@ include(../config_plugin.pri)
ODB_FILES = addressbook/data/addressbookdata.h ODB_FILES = addressbook/data/addressbookdata.h
H_DIR = $$PWD/data/*.h H_DIR = $$PWD/data/*.h
ODB_OTHER_INCLUDES = -I $$PWD/../countryregister/data
include(../odb.pri) include(../odb.pri)
OTHER_FILES += \ OTHER_FILES += \
@ -43,3 +44,11 @@ FORMS += \
RESOURCES += \ RESOURCES += \
addressbookrc.qrc addressbookrc.qrc
TRANSLATIONS = translations/addressbook_cs_CZ.ts TRANSLATIONS = translations/addressbook_cs_CZ.ts
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lcountryregister
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lcountryregister
else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lcountryregister
INCLUDEPATH += $$PWD/../countryregister/data
INCLUDEPATH += $$PWD/../countryregister

@ -1,5 +1,6 @@
#include "addressbookform.h" #include "addressbookform.h"
#include "ui_addressbookform.h" #include "ui_addressbookform.h"
#include <countrydata.h>
AddressbookForm::AddressbookForm(QWidget *parent) : AddressbookForm::AddressbookForm(QWidget *parent) :
AutoForm<AddressbookData>(parent), AutoForm<AddressbookData>(parent),
@ -22,3 +23,9 @@ AddressbookForm::~AddressbookForm()
{ {
delete ui; delete ui;
} }
void AddressbookForm::registerCombos()
{
Service<CountryData> srv;
registerBinding(ui->country, ComboData::createComboData(srv.all()));
}

@ -20,6 +20,10 @@ public:
private: private:
Ui::AddressbookForm *ui; Ui::AddressbookForm *ui;
// FormBinder interface
protected:
void registerCombos();
}; };

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>610</width>
<height>300</height> <height>407</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -115,8 +115,35 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Country</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QComboBox" name="country">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>title</tabstop>
<tabstop>firstName</tabstop>
<tabstop>lastName</tabstop>
<tabstop>birthDate</tabstop>
<tabstop>idCardNumber</tabstop>
<tabstop>ztp</tabstop>
<tabstop>addressCity</tabstop>
<tabstop>addressStreet</tabstop>
<tabstop>addressHouseNumber</tabstop>
<tabstop>addressZipCode</tabstop>
<tabstop>country</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

@ -106,6 +106,19 @@ void AddressbookData::setId(int id)
m_id = id; m_id = id;
} }
QSharedPointer<QObject> AddressbookData::country() const
{
return m_country;
}
void AddressbookData::setCountry(const QSharedPointer<QObject> &country)
{
if (qobject_cast<CountryData*>(country.data()) != NULL)
{
m_country = qSharedPointerDynamicCast<CountryData, QObject>(country);
}
}
bool AddressbookData::eq(ComboItem *other) bool AddressbookData::eq(ComboItem *other)
{ {
AddressbookData *adb = qobject_cast<AddressbookData*>(other); AddressbookData *adb = qobject_cast<AddressbookData*>(other);

@ -9,6 +9,7 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <data/comboitem.h> #include <data/comboitem.h>
#include <countrydata.h>
#if defined(ADDRESSBOOK_LIBRARY) #if defined(ADDRESSBOOK_LIBRARY)
# define ADDRESSBOOKSHARED_EXPORT Q_DECL_EXPORT # define ADDRESSBOOKSHARED_EXPORT Q_DECL_EXPORT
@ -30,6 +31,7 @@ class ADDRESSBOOKSHARED_EXPORT AddressbookData : public ComboItem
Q_PROPERTY(QString addressStreet READ addressStreet WRITE setAddressStreet) Q_PROPERTY(QString addressStreet READ addressStreet WRITE setAddressStreet)
Q_PROPERTY(QString addressHouseNumber READ addressHouseNumber WRITE setAddressHouseNumber) Q_PROPERTY(QString addressHouseNumber READ addressHouseNumber WRITE setAddressHouseNumber)
Q_PROPERTY(QString addressZipCode READ addressZipCode WRITE setAddressZipCode) Q_PROPERTY(QString addressZipCode READ addressZipCode WRITE setAddressZipCode)
Q_PROPERTY(QSharedPointer<QObject> country READ country WRITE setCountry)
public: public:
AddressbookData(QObject *parent = 0); AddressbookData(QObject *parent = 0);
@ -66,6 +68,9 @@ public:
int id() const; int id() const;
void setId(int id); void setId(int id);
QSharedPointer<QObject> country() const;
void setCountry(const QSharedPointer<QObject> &country);
private: private:
friend class odb::access; friend class odb::access;
#pragma db id auto #pragma db id auto
@ -80,6 +85,7 @@ private:
QString m_addressStreet; QString m_addressStreet;
QString m_addressHouseNumber; QString m_addressHouseNumber;
QString m_addressZipCode; QString m_addressZipCode;
CountryDataPtr m_country;
// ComboItem interface // ComboItem interface
public: public:

@ -50,7 +50,7 @@ include(../config_plugin.pri)
ODB_FILES = camp/data/camp-data.h ODB_FILES = camp/data/camp-data.h
H_DIR = $$PWD/data/*.h H_DIR = $$PWD/data/*.h
ODB_OTHER_INCLUDES = -I $$PWD/../shop -I $$PWD/../addressbook/data -I $$PWD/../services/data ODB_OTHER_INCLUDES = -I $$PWD/../shop -I $$PWD/../addressbook/data -I $$PWD/../countryregister/data -I $$PWD/../services/data
include(../odb.pri) include(../odb.pri)
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop
@ -68,6 +68,9 @@ INCLUDEPATH += $$PWD/../addressbook
INCLUDEPATH += $$PWD/../addressbook/data INCLUDEPATH += $$PWD/../addressbook/data
DEPENDPATH += $$PWD/../addressbook DEPENDPATH += $$PWD/../addressbook
INCLUDEPATH += $$PWD/../countryregister/data
INCLUDEPATH += $$PWD/../countryregister
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lservices win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lservices
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lservices else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lservices
else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lservices else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lservices

@ -1,6 +1,6 @@
#include "countrydata.h" #include "countrydata.h"
CountryData::CountryData(QObject *parent) : QObject(parent) CountryData::CountryData(QObject *parent) : ComboItem(parent)
{ {
} }
@ -74,3 +74,20 @@ void CountryData::setEnglishName(const QString &englishName)
{ {
m_englishName = englishName; m_englishName = englishName;
} }
bool CountryData::eq(ComboItem *other)
{
CountryData *obj = qobject_cast<CountryData*>(other);
if (obj == NULL)
{
return false;
}
return this == obj || (m_id == obj->m_id && m_code2 == obj->m_code2 && m_code3 == obj->m_code3);
}
QString CountryData::toString()
{
return m_code3 + " - " + m_czechFullName;
}

@ -4,9 +4,11 @@
#include <QString> #include <QString>
#include <QObject> #include <QObject>
#include <odb/core.hxx> #include <odb/core.hxx>
#include <QSharedPointer>
#include <data/comboitem.h>
#pragma db object #pragma db object
class CountryData : public QObject class CountryData : public ComboItem
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString code2 READ code2 WRITE setCode2) Q_PROPERTY(QString code2 READ code2 WRITE setCode2)
@ -50,6 +52,13 @@ private:
QString m_englishFullName; QString m_englishFullName;
QString m_englishName; QString m_englishName;
// ComboItem interface
public:
bool eq(ComboItem *other);
QString toString();
}; };
typedef QSharedPointer<CountryData> CountryDataPtr;
#endif // COUNTRYDATA_H #endif // COUNTRYDATA_H

@ -9,7 +9,7 @@ QT += widgets sql
TARGET = shop TARGET = shop
TEMPLATE = lib TEMPLATE = lib
#CONFIG += eet CONFIG += eet
DEFINES += SHOP_LIBRARY DEFINES += SHOP_LIBRARY
@ -63,7 +63,7 @@ OTHER_FILES += shop.json
ODB_FILES = shop/data/shop-data.h ODB_FILES = shop/data/shop-data.h
H_DIR = $$PWD/data/*.h H_DIR = $$PWD/data/*.h
ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data -I $$PWD/ ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data -I $$PWD/../countryregister/data -I $$PWD/
include(../odb.pri) include(../odb.pri)
RESOURCES += \ RESOURCES += \
@ -89,6 +89,9 @@ INCLUDEPATH += $$PWD/../addressbook
INCLUDEPATH += $$PWD/ INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/../addressbook DEPENDPATH += $$PWD/../addressbook
INCLUDEPATH += $$PWD/../countryregister/data
INCLUDEPATH += $$PWD/../countryregister
TRANSLATIONS = translations/shop_cs_CZ.ts TRANSLATIONS = translations/shop_cs_CZ.ts
win32 { win32 {

Loading…
Cancel
Save