From 4b3a2e1dd79cb1a5ea22f7b1a6cc4f5b46312266 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Tue, 4 Apr 2017 21:57:36 +0200 Subject: [PATCH] Fixed crash on add item via favorite button after application start. Favorite buttons has short name labels. closes #296 refs #293 --- commodity/data/commoditydata.cpp | 2 +- commodity/data/commoditydata.h | 2 +- shop/data/favorititem.cpp | 10 ++++++++++ shop/data/favorititem.h | 5 +++++ shop/directsaleitem.cpp | 5 +++++ shop/directsaleitem.h | 1 + shop/ishopitem.h | 1 + shop/settings/shopsettingsform.cpp | 8 ++++---- shop/shop.json | 4 +++- shop/shopform.cpp | 18 +++++++----------- shop/shopitem.h | 2 ++ 11 files changed, 40 insertions(+), 18 deletions(-) diff --git a/commodity/data/commoditydata.cpp b/commodity/data/commoditydata.cpp index 2463564..77a02c7 100644 --- a/commodity/data/commoditydata.cpp +++ b/commodity/data/commoditydata.cpp @@ -26,7 +26,7 @@ void CommodityData::setName(const QString &name) { m_name = name; } -QString CommodityData::shortName() const +QString CommodityData::shortName() { return m_shortName; } diff --git a/commodity/data/commoditydata.h b/commodity/data/commoditydata.h index 1655dc9..ea3865b 100644 --- a/commodity/data/commoditydata.h +++ b/commodity/data/commoditydata.h @@ -31,7 +31,7 @@ public: QString name() override; void setName(const QString &name); - QString shortName() const; + QString shortName() override; void setShortName(const QString &shortName); QString code() const; diff --git a/shop/data/favorititem.cpp b/shop/data/favorititem.cpp index 3bbe1ff..7c94224 100644 --- a/shop/data/favorititem.cpp +++ b/shop/data/favorititem.cpp @@ -28,6 +28,16 @@ void FavoritItem::setName(const QString &name) m_name = name; } +QString FavoritItem::shortName() +{ + return m_shortName; +} + +void FavoritItem::setShortName(const QString &shortName) +{ + m_shortName = shortName; +} + QDecDouble FavoritItem::unitPrice() { return TO_DEC(m_unitPrice); diff --git a/shop/data/favorititem.h b/shop/data/favorititem.h index 6650997..02848c3 100644 --- a/shop/data/favorititem.h +++ b/shop/data/favorititem.h @@ -19,6 +19,7 @@ class FavoritItem : public QObject, public IShopItem Q_PROPERTY(int id READ id WRITE setId) Q_PROPERTY(int refId READ refId WRITE setRefId) Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString shortName READ shortName WRITE setShortName) 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) @@ -35,6 +36,9 @@ public: QString name() override; void setName(const QString &name); + virtual QString shortName() override; + void setShortName(const QString &shortName); + QDecDouble unitPrice() override; void setUnitPrice(QDecDouble unitPrice); @@ -60,6 +64,7 @@ private: Enums::VatType m_vatType; QString m_pluginId; QString m_favButtonName; + QString m_shortName; }; typedef QSharedPointer FavoritItemPtr; diff --git a/shop/directsaleitem.cpp b/shop/directsaleitem.cpp index 615d6c1..2b360a9 100644 --- a/shop/directsaleitem.cpp +++ b/shop/directsaleitem.cpp @@ -16,6 +16,11 @@ QString DirectSaleItem::name() return m_name; } +QString DirectSaleItem::shortName() +{ + return ""; +} + QDecDouble DirectSaleItem::unitPrice() { return m_unitPrice; diff --git a/shop/directsaleitem.h b/shop/directsaleitem.h index f497e28..0d3c28c 100644 --- a/shop/directsaleitem.h +++ b/shop/directsaleitem.h @@ -24,6 +24,7 @@ public slots: public: int id() override; QString name() override; + QString shortName() override; QDecDouble unitPrice() override; QString pluginId() override; Enums::VatType vatType() override; diff --git a/shop/ishopitem.h b/shop/ishopitem.h index 81c753f..87fa264 100644 --- a/shop/ishopitem.h +++ b/shop/ishopitem.h @@ -12,6 +12,7 @@ class SHOPSHARED_EXPORT IShopItem public: virtual int id() = 0; virtual QString name() = 0; + virtual QString shortName() = 0; virtual QDecDouble unitPrice() = 0; virtual Enums::VatType vatType() = 0; virtual QString pluginId() = 0; diff --git a/shop/settings/shopsettingsform.cpp b/shop/settings/shopsettingsform.cpp index 2ea5c8c..0e94462 100644 --- a/shop/settings/shopsettingsform.cpp +++ b/shop/settings/shopsettingsform.cpp @@ -36,8 +36,6 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) : registerBinding(ui->favBtnSize); m_itemModel = new AutoTableModel(); - - } ShopSettingsForm::~ShopSettingsForm() @@ -61,7 +59,7 @@ void ShopSettingsForm::drawButtons() if (m_btnMap[btn->objectName()] != NULL) { - btn->setText(m_btnMap[btn->objectName()]->name()); + btn->setText(m_btnMap[btn->objectName()]->shortName()); } if (entity()->favBtnSize() > 0) @@ -81,10 +79,11 @@ void ShopSettingsForm::drawButtons() FavoritItemPtr favItem = QSharedPointer(new FavoritItem); favItem->setFavButtonName(btn->objectName()); favItem->setName(item->name()); + favItem->setShortName(item->shortName()); favItem->setRefId(item->id()); favItem->setPluginId(item->pluginId()); m_btnMap[btn->objectName()] = favItem; - btn->setText(item->name()); + btn->setText(item->shortName()); }); } } @@ -102,6 +101,7 @@ void ShopSettingsForm::loadEntity() ui->tableItems->setModel(m_itemModel); ui->tableItems->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); ui->tableItems->setColumnHidden(0, true); + ui->tableItems->setColumnHidden(2, true); ui->tableItems->setColumnHidden(3, true); Service srvFav; diff --git a/shop/shop.json b/shop/shop.json index 100bdec..f0087a2 100644 --- a/shop/shop.json +++ b/shop/shop.json @@ -8,7 +8,7 @@ "default" : "", "CZ" : "" }, - "schemaVersion" : 4, + "schemaVersion" : 5, "sql" : [ "CREATE TABLE \"VoucherItem\" ( \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -70,6 +70,8 @@ CREATE TABLE \"Voucher\" ( \"vatType\" INTEGER NOT NULL, \"pluginId\" TEXT NULL, \"favButtonName\" TEXT NULL); +", + "ALTER TABLE \"FavoritItem\" ADD \"shortName\" TEXT NULL; " ], "dependencies" : [ "ADDRESSBOOK" ], diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 4c2d407..b8a4743 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -83,6 +83,7 @@ void ShopForm::loadLast() m_commodityModel->setData(srv.allSellableItems()); ui->commodityTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); ui->commodityTable->setColumnHidden(3, true); + ui->commodityTable->setColumnHidden(2, true); if (srv.isEetEnabled()) { @@ -124,7 +125,7 @@ void ShopForm::loadButtons() if (btnMap[btnName] != NULL) { - btn->setText(btnMap[btnName]->name()); + btn->setText(btnMap[btnName]->shortName()); connect(btn, &FavButton::clicked, [this, btnMap, btn](bool){ FavoritItemPtr item = btnMap[btn->objectName()]; @@ -161,11 +162,6 @@ void ShopForm::fillRaceiptCombo() void ShopForm::on_directSale_clicked() { - if (m_voucher.isNull()) - { - createVoucher(); - } - DirectSaleForm *form = new DirectSaleForm(this); form->setAttribute(Qt::WA_DeleteOnClose); @@ -357,6 +353,11 @@ void ShopForm::createEmptyVoucher() void ShopForm::addItem(QSharedPointer item, int count) { + if (m_voucher.isNull()) + { + createVoucher(); + } + ShopService srv; srv.addShopItem(m_voucher, item, count); this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]); @@ -443,11 +444,6 @@ void ShopForm::on_showPaiedButton_clicked() void ShopForm::on_btnAddItem_clicked() { - if (m_voucher.isNull()) - { - createVoucher(); - } - ShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex()); addItem(item, ui->spnCount->value()); } diff --git a/shop/shopitem.h b/shop/shopitem.h index 0f03f44..97c5ecc 100644 --- a/shop/shopitem.h +++ b/shop/shopitem.h @@ -12,6 +12,7 @@ class SHOPSHARED_EXPORT ShopItem : public QObject, public IShopItem Q_PROPERTY(QString code READ code) Q_PROPERTY(QString name READ name) + Q_PROPERTY(QString shortName READ shortName) Q_PROPERTY(QDecDouble unitPrice READ unitPrice) Q_PROPERTY(Enums::VatType vatType READ vatType) @@ -27,6 +28,7 @@ public: virtual int id() override { return 0; } virtual QString code() { return ""; } virtual QString name() override { return ""; } + virtual QString shortName() override { return ""; } virtual QDecDouble unitPrice() override { return QDecDouble(); } virtual Enums::VatType vatType() override { return Enums::NONE; } virtual QString pluginId() override { return ""; }