diff --git a/core/itablemodel.cpp b/core/itablemodel.cpp index dfde394..50f689b 100644 --- a/core/itablemodel.cpp +++ b/core/itablemodel.cpp @@ -23,7 +23,7 @@ Qt::ItemFlags ITableModel::flags(const QModelIndex &index) const return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; } - return QAbstractTableModel::flags(index); + return QAbstractTableModel::flags(index) | Qt::ItemIsDragEnabled; } void ITableModel::setEditableCols(const QList cols) diff --git a/shop/data/favorititem.cpp b/shop/data/favorititem.cpp new file mode 100644 index 0000000..3d7e5e3 --- /dev/null +++ b/shop/data/favorititem.cpp @@ -0,0 +1,69 @@ +#include "favorititem.h" +#include + +FavoritItem::FavoritItem() +{ + m_id = 0; + m_vatType = Enums::NONE; + m_unitPrice = 0; +} + +int FavoritItem::id() +{ + return m_id; +} + +void FavoritItem::setId(int id) +{ + m_id = id; +} + +QString FavoritItem::name() +{ + return m_name; +} + +void FavoritItem::setName(const QString &name) +{ + m_name = name; +} + +QDecDouble FavoritItem::unitPrice() +{ + return TO_DEC(m_unitPrice); +} + +void FavoritItem::setUnitPrice(QDecDouble unitPrice) +{ + m_unitPrice = FROM_DEC(unitPrice); +} + +Enums::VatType FavoritItem::vatType() +{ + return m_vatType; +} + +void FavoritItem::setVatType(const Enums::VatType &vatType) +{ + m_vatType = vatType; +} + +QString FavoritItem::pluginId() +{ + return m_pluginId; +} + +void FavoritItem::setPluginId(const QString &pluginId) +{ + m_pluginId = pluginId; +} + +QString FavoritItem::favButtonName() const +{ + return m_favButtonName; +} + +void FavoritItem::setFavButtonName(const QString &favButtonName) +{ + m_favButtonName = favButtonName; +} diff --git a/shop/data/favorititem.h b/shop/data/favorititem.h new file mode 100644 index 0000000..c569838 --- /dev/null +++ b/shop/data/favorititem.h @@ -0,0 +1,62 @@ +#ifndef FAVORITITEM_H +#define FAVORITITEM_H + +#include +#include +#include +#include +#include +#include +#include + +class IShopItem; + +#pragma db object +class FavoritItem : public QObject, public IShopItem +{ + Q_OBJECT + + Q_PROPERTY(int id READ id WRITE setId) + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice) + Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType) + Q_PROPERTY(QString pluginId READ pluginId WRITE setPluginId) + Q_PROPERTY(QString favButtonName READ favButtonName WRITE setFavButtonName) + +public: + FavoritItem(); + + // IShopItem interface +public: + int id() override; + void setId(int id); + + QString name() override; + void setName(const QString &name); + + QDecDouble unitPrice() override; + void setUnitPrice(QDecDouble unitPrice); + + Enums::VatType vatType() override; + void setVatType(const Enums::VatType &vatType); + + QString pluginId() override; + void setPluginId(const QString &pluginId); + + QString favButtonName() const; + void setFavButtonName(const QString &favButtonName); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_name; + int m_unitPrice; + Enums::VatType m_vatType; + QString m_pluginId; + QString m_favButtonName; +}; + +typedef QSharedPointer FavoritItemPtr; + +#endif // FAVORITITEM_H diff --git a/shop/data/shop-data.h b/shop/data/shop-data.h index 856c470..43c0f25 100644 --- a/shop/data/shop-data.h +++ b/shop/data/shop-data.h @@ -3,5 +3,6 @@ #include "voucher.h" #include "voucheritem.h" +#include "favorititem.h" #endif // SHOPDATA_H diff --git a/shop/settings/favoriteservice.cpp b/shop/settings/favoriteservice.cpp new file mode 100644 index 0000000..b90ace2 --- /dev/null +++ b/shop/settings/favoriteservice.cpp @@ -0,0 +1,6 @@ +#include "favoriteservice.h" + +FavoriteService::FavoriteService() +{ + +} diff --git a/shop/settings/favoriteservice.h b/shop/settings/favoriteservice.h new file mode 100644 index 0000000..d99648e --- /dev/null +++ b/shop/settings/favoriteservice.h @@ -0,0 +1,13 @@ +#ifndef FAVORITESERVICE_H +#define FAVORITESERVICE_H + +#include +#include "data/favorititem.h" + +class FavoriteService : public Service +{ +public: + FavoriteService(); +}; + +#endif // FAVORITESERVICE_H diff --git a/shop/settings/shopsettingsform.cpp b/shop/settings/shopsettingsform.cpp index 18c2b1d..b7280bf 100644 --- a/shop/settings/shopsettingsform.cpp +++ b/shop/settings/shopsettingsform.cpp @@ -2,6 +2,7 @@ #include "ui_shopsettingsform.h" #include +#include "shopservice.h" ShopSettingsForm::ShopSettingsForm(QWidget *parent) : FormBinder(parent), @@ -12,6 +13,8 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) : registerBinding(ui->output); registerBinding(ui->lettersPerLine); registerBinding(ui->byMessage); + + m_itemModel = new AutoTableModel(); } ShopSettingsForm::~ShopSettingsForm() @@ -24,6 +27,10 @@ void ShopSettingsForm::loadEntity() SettingsService srv("SHOP"); ShopSettingsPtr settings = srv.loadSettings(); setEntity(settings); + + ShopService srvShop; + m_itemModel->setData(srvShop.allSellableItems()); + ui->tableItems->setModel(m_itemModel); } bool ShopSettingsForm::saveRecord() diff --git a/shop/settings/shopsettingsform.h b/shop/settings/shopsettingsform.h index 42bb46f..f46f875 100644 --- a/shop/settings/shopsettingsform.h +++ b/shop/settings/shopsettingsform.h @@ -4,6 +4,8 @@ #include #include #include "shopsettings.h" +#include +#include "shopitem.h" namespace Ui { class ShopSettingsForm; @@ -19,6 +21,7 @@ public: private: Ui::ShopSettingsForm *ui; + AutoTableModel *m_itemModel; // IForm interface public: diff --git a/shop/settings/shopsettingsform.ui b/shop/settings/shopsettingsform.ui index 405dd54..7e5b2e6 100644 --- a/shop/settings/shopsettingsform.ui +++ b/shop/settings/shopsettingsform.ui @@ -6,8 +6,8 @@ 0 0 - 608 - 450 + 645 + 463 @@ -15,42 +15,225 @@ - - - Printer + + + 0 - - - - - Output device - - - - - - - - - - Letters per line - - - - - - - - - - Footer text - - - - - - - + + + Favorite buttons + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::DragDrop + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Printer + + + + + + Output device + + + + + + + + + + Letters per line + + + + + + + + + + Footer text + + + + + + + + diff --git a/shop/shop.pro b/shop/shop.pro index 8991736..665cec6 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -28,7 +28,9 @@ SOURCES += shop.cpp \ paydialog.cpp \ paydvouchersdialog.cpp \ shopitem.cpp \ - isellableservice.cpp + isellableservice.cpp \ + data/favorititem.cpp \ + settings/favoriteservice.cpp HEADERS += shop.h\ shop_global.h \ @@ -49,7 +51,9 @@ HEADERS += shop.h\ settings/shopsettingsform.h \ paydialog.h \ paydvouchersdialog.h \ - shopitem.h + shopitem.h \ + data/favorititem.h \ + settings/favoriteservice.h unix { target.path = /usr/lib @@ -75,6 +79,7 @@ else:unix: LIBS += -L$$OUT_PWD/../plugins/ -laddressbook INCLUDEPATH += $$PWD/../addressbook/data INCLUDEPATH += $$PWD/../addressbook +INCLUDEPATH += $$PWD/ DEPENDPATH += $$PWD/../addressbook DESTDIR = ../plugins @@ -83,7 +88,7 @@ OTHER_FILES += shop.json ODB_FILES = shop/data/shop-data.h H_DIR = $$PWD/data/*.h -ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data +ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data -I $$PWD/ include(../odb.pri) win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber diff --git a/shop/shopform.cpp b/shop/shopform.cpp index f78c431..985bca5 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -11,6 +11,8 @@ #include "isellableservice.h" #include #include +#include + #include "shop-odb.hxx" ShopForm::ShopForm(QWidget *parent) : @@ -313,3 +315,31 @@ void ShopForm::on_btnAddItem_clicked() ShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex()); addItem(item, ui->spnCount->value()); } + +void ShopForm::on_commoditySearch_textChanged(const QString &text) +{ + QSortFilterProxyModel proxy; + proxy.setSourceModel(m_commodityModel); + proxy.setFilterKeyColumn(0); + proxy.setFilterFixedString(text); + + auto moveToIndex = [this](const QModelIndex &matchingIndex) { + ui->commodityTable->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible); + ui->commodityTable->setCurrentIndex(matchingIndex); + }; + + QModelIndex matchingIndex = proxy.mapToSource(proxy.index(0,0)); + if(matchingIndex.isValid()) { + moveToIndex(matchingIndex); + } + else + { + proxy.setFilterKeyColumn(1); + matchingIndex = proxy.mapToSource(proxy.index(0,0)); + + if (matchingIndex.isValid()) + { + moveToIndex(matchingIndex); + } + } +} diff --git a/shop/shopform.h b/shop/shopform.h index 301823b..d2eecd6 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -42,6 +42,8 @@ private slots: void on_btnAddItem_clicked(); + void on_commoditySearch_textChanged(const QString &text); + private: Ui::ShopForm *ui; QSharedPointer m_voucher; diff --git a/shop/shopform.ui b/shop/shopform.ui index 93f4c36..270547c 100644 --- a/shop/shopform.ui +++ b/shop/shopform.ui @@ -7,7 +7,7 @@ 0 0 959 - 582 + 643 @@ -131,6 +131,11 @@ + + + 10 + + Direct Sale @@ -177,7 +182,82 @@ 0 - + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + @@ -200,8 +280,96 @@ 0 + + + + + 75 + 75 + + + + ... + + + - + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + + 75 + 75 + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + +