diff --git a/addressbook/addressbook.pro b/addressbook/addressbook.pro index af561c0..869a60b 100644 --- a/addressbook/addressbook.pro +++ b/addressbook/addressbook.pro @@ -17,14 +17,16 @@ SOURCES += addressbook.cpp \ data/addressbookdata.cpp \ addressbookform.cpp \ addressbookgrid.cpp \ - addressbooktablemodel.cpp + addressbooktablemodel.cpp \ + addressbookservice.cpp HEADERS += addressbook.h\ addressbook_global.h \ data/addressbookdata.h \ addressbookform.h \ addressbookgrid.h \ - addressbooktablemodel.h + addressbooktablemodel.h \ + addressbookservice.h unix { target.path = /usr/lib diff --git a/addressbook/addressbookservice.cpp b/addressbook/addressbookservice.cpp new file mode 100644 index 0000000..1f491fd --- /dev/null +++ b/addressbook/addressbookservice.cpp @@ -0,0 +1,18 @@ +#include +#include "addressbookservice.h" +#include "addressbook-odb.hxx" + +AddressBookService::AddressBookService() +{ +} + +AddressBookService::~AddressBookService() +{ +} + +QList > AddressBookService::all(const QString &where) +{ + Service srv; + return srv.all(where); +} + diff --git a/addressbook/addressbookservice.h b/addressbook/addressbookservice.h new file mode 100644 index 0000000..6b8ee4d --- /dev/null +++ b/addressbook/addressbookservice.h @@ -0,0 +1,19 @@ +#ifndef ADDRESSBOOKSERVICE_H +#define ADDRESSBOOKSERVICE_H + +#include +#include + +#include "data/addressbookdata.h" +#include "addressbook_global.h" + +class ADDRESSBOOKSHARED_EXPORT AddressBookService +{ +public: + AddressBookService(); + ~AddressBookService(); + + QList > all(const QString &where = ""); +}; + +#endif // ADDRESSBOOKSERVICE_H diff --git a/addressbook/data/addressbookdata.cpp b/addressbook/data/addressbookdata.cpp index c339309..0b002d0 100644 --- a/addressbook/data/addressbookdata.cpp +++ b/addressbook/data/addressbookdata.cpp @@ -1,108 +1,119 @@ #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; - } + :ComboItem(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; +} + +bool AddressbookData::eq(ComboItem *other) +{ + AddressbookData *adb = qobject_cast(other); + return adb != NULL && adb->id() == this->id(); +} + +QString AddressbookData::toString() +{ + return m_firstName + " " + m_lastName + ", " + m_addressStreet + " " + m_addressHouseNumber + ", " + m_addressCity; +} diff --git a/addressbook/data/addressbookdata.h b/addressbook/data/addressbookdata.h index bcfc735..114d4dc 100644 --- a/addressbook/data/addressbookdata.h +++ b/addressbook/data/addressbookdata.h @@ -7,6 +7,8 @@ #include #include +#include + #if defined(ADDRESSBOOK_LIBRARY) # define ADDRESSBOOKSHARED_EXPORT Q_DECL_EXPORT #else @@ -14,7 +16,7 @@ #endif #pragma db object -class ADDRESSBOOKSHARED_EXPORT AddressbookData : public QObject +class ADDRESSBOOKSHARED_EXPORT AddressbookData : public ComboItem { Q_OBJECT Q_PROPERTY(QString title READ title WRITE setTitle) @@ -77,6 +79,11 @@ private: QString m_addressStreet; QString m_addressHouseNumber; QString m_addressZipCode; + + // ComboItem interface +public: + virtual bool eq(ComboItem *other); + virtual QString toString(); }; #endif // ADDRESSBOOKDATA_H diff --git a/shop/receiptsaveform.cpp b/shop/receiptsaveform.cpp index c341f95..4d7fbf1 100644 --- a/shop/receiptsaveform.cpp +++ b/shop/receiptsaveform.cpp @@ -1,14 +1,88 @@ #include "receiptsaveform.h" #include "ui_receiptsaveform.h" +#include +#include +#include + +#include +#include +#include +#include + +#include "data/voucher.h" +#include "shop-odb.hxx" + ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) : QDialog(parent), ui(new Ui::ReceiptSaveForm) { ui->setupUi(this); + + m_voucherModel = new AutoTableModel(this); + Service srv; + m_voucherModel->setData(srv.all()); + m_voucherModel->setTranslations(Context::instance().plugin("SHOP")->translations()); + ui->tabVouchers->setModel(m_voucherModel); + ui->tabVouchers->hideColumn(3); + ui->tabVouchers->hideColumn(4); + ui->tabVouchers->hideColumn(5); + ui->tabVouchers->hideColumn(6); + ui->tabVouchers->hideColumn(7); + ui->tabVouchers->hideColumn(8); + ui->tabVouchers->hideColumn(10); + ui->tabVouchers->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); + ui->tabVouchers->setColumnWidth(0, 190); + ui->tabVouchers->setColumnWidth(2, 200); + + AddressBookService srvAdb; + QList comboData; + foreach (QSharedPointer adb, srvAdb.all()) { + comboData << ComboData(adb); + } + + m_binder.setData(new Voucher); + m_binder.registerBinding(ui->contact, comboData); + m_binder.bindToUi(); + + ui->contact->completer()->setCompletionMode(QCompleter::PopupCompletion); + ui->contact->setCurrentIndex(-1); + + m_saveAsNew = false; + ui->groupBox_2->setEnabled(false); } ReceiptSaveForm::~ReceiptSaveForm() { delete ui; } + +void ReceiptSaveForm::on_lineEdit_textChanged(const QString &text) +{ + QSortFilterProxyModel proxy; + proxy.setSourceModel(m_voucherModel); + proxy.setFilterKeyColumn(0); + proxy.setFilterFixedString(text); + + QModelIndex matchingIndex = proxy.mapToSource(proxy.index(0,0)); + if(matchingIndex.isValid()){ + ui->tabVouchers->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible); + ui->tabVouchers->setCurrentIndex(matchingIndex); + } +} + +void ReceiptSaveForm::on_radioAdd_toggled(bool checked) +{ + if (checked) + { + m_saveAsNew = false; + ui->groupBox_2->setEnabled(false); + ui->groupBox->setEnabled(true); + } + else + { + m_saveAsNew = true; + ui->groupBox_2->setEnabled(true); + ui->groupBox->setEnabled(false); + } +} diff --git a/shop/receiptsaveform.h b/shop/receiptsaveform.h index f280d28..a65db07 100644 --- a/shop/receiptsaveform.h +++ b/shop/receiptsaveform.h @@ -2,6 +2,9 @@ #define RECEIPTSAVEFORM_H #include +#include +#include +#include "data/voucher.h" namespace Ui { class ReceiptSaveForm; @@ -15,8 +18,16 @@ public: explicit ReceiptSaveForm(QWidget *parent = 0); ~ReceiptSaveForm(); +private slots: + void on_lineEdit_textChanged(const QString &text); + + void on_radioAdd_toggled(bool checked); + private: Ui::ReceiptSaveForm *ui; + ObjectBinder m_binder; + AutoTableModel *m_voucherModel; + bool m_saveAsNew; }; #endif // RECEIPTSAVEFORM_H diff --git a/shop/receiptsaveform.ui b/shop/receiptsaveform.ui index e408356..aec56a6 100644 --- a/shop/receiptsaveform.ui +++ b/shop/receiptsaveform.ui @@ -6,14 +6,27 @@ 0 0 - 419 - 545 + 804 + 513 - Dialog + Save receipt + + + true + + + + Add to existing + + + true + + + @@ -30,18 +43,35 @@ - - + + + + + 0 + 250 + + + + + + + Save as new + + + - GroupBox + New receipt + + QFormLayout::AllNonFixedFieldsGrow + @@ -50,7 +80,7 @@ - + @@ -60,7 +90,7 @@ - + @@ -70,10 +100,11 @@ - - - - + + + true + + diff --git a/shop/shop.pro b/shop/shop.pro index 588b70b..d626e77 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -61,6 +61,7 @@ else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddre else:unix: LIBS += -L$$OUT_PWD/../plugins/ -laddressbook INCLUDEPATH += $$PWD/../addressbook/data +INCLUDEPATH += $$PWD/../addressbook DEPENDPATH += $$PWD/../addressbook DESTDIR = ../plugins