Fixed crash on add item via favorite button after application start.

Favorite buttons has short name labels.
closes #296
refs #293
master
Josef Rokos 8 years ago
parent aa91acbe17
commit 4b3a2e1dd7

@ -26,7 +26,7 @@ void CommodityData::setName(const QString &name)
{ {
m_name = name; m_name = name;
} }
QString CommodityData::shortName() const QString CommodityData::shortName()
{ {
return m_shortName; return m_shortName;
} }

@ -31,7 +31,7 @@ public:
QString name() override; QString name() override;
void setName(const QString &name); void setName(const QString &name);
QString shortName() const; QString shortName() override;
void setShortName(const QString &shortName); void setShortName(const QString &shortName);
QString code() const; QString code() const;

@ -28,6 +28,16 @@ void FavoritItem::setName(const QString &name)
m_name = name; m_name = name;
} }
QString FavoritItem::shortName()
{
return m_shortName;
}
void FavoritItem::setShortName(const QString &shortName)
{
m_shortName = shortName;
}
QDecDouble FavoritItem::unitPrice() QDecDouble FavoritItem::unitPrice()
{ {
return TO_DEC(m_unitPrice); return TO_DEC(m_unitPrice);

@ -19,6 +19,7 @@ class FavoritItem : public QObject, public IShopItem
Q_PROPERTY(int id READ id WRITE setId) Q_PROPERTY(int id READ id WRITE setId)
Q_PROPERTY(int refId READ refId WRITE setRefId) Q_PROPERTY(int refId READ refId WRITE setRefId)
Q_PROPERTY(QString name READ name WRITE setName) 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(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice)
Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType) Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType)
Q_PROPERTY(QString pluginId READ pluginId WRITE setPluginId) Q_PROPERTY(QString pluginId READ pluginId WRITE setPluginId)
@ -35,6 +36,9 @@ public:
QString name() override; QString name() override;
void setName(const QString &name); void setName(const QString &name);
virtual QString shortName() override;
void setShortName(const QString &shortName);
QDecDouble unitPrice() override; QDecDouble unitPrice() override;
void setUnitPrice(QDecDouble unitPrice); void setUnitPrice(QDecDouble unitPrice);
@ -60,6 +64,7 @@ private:
Enums::VatType m_vatType; Enums::VatType m_vatType;
QString m_pluginId; QString m_pluginId;
QString m_favButtonName; QString m_favButtonName;
QString m_shortName;
}; };
typedef QSharedPointer<FavoritItem> FavoritItemPtr; typedef QSharedPointer<FavoritItem> FavoritItemPtr;

@ -16,6 +16,11 @@ QString DirectSaleItem::name()
return m_name; return m_name;
} }
QString DirectSaleItem::shortName()
{
return "";
}
QDecDouble DirectSaleItem::unitPrice() QDecDouble DirectSaleItem::unitPrice()
{ {
return m_unitPrice; return m_unitPrice;

@ -24,6 +24,7 @@ public slots:
public: public:
int id() override; int id() override;
QString name() override; QString name() override;
QString shortName() override;
QDecDouble unitPrice() override; QDecDouble unitPrice() override;
QString pluginId() override; QString pluginId() override;
Enums::VatType vatType() override; Enums::VatType vatType() override;

@ -12,6 +12,7 @@ class SHOPSHARED_EXPORT IShopItem
public: public:
virtual int id() = 0; virtual int id() = 0;
virtual QString name() = 0; virtual QString name() = 0;
virtual QString shortName() = 0;
virtual QDecDouble unitPrice() = 0; virtual QDecDouble unitPrice() = 0;
virtual Enums::VatType vatType() = 0; virtual Enums::VatType vatType() = 0;
virtual QString pluginId() = 0; virtual QString pluginId() = 0;

@ -36,8 +36,6 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) :
registerBinding(ui->favBtnSize); registerBinding(ui->favBtnSize);
m_itemModel = new AutoTableModel<ShopItem>(); m_itemModel = new AutoTableModel<ShopItem>();
} }
ShopSettingsForm::~ShopSettingsForm() ShopSettingsForm::~ShopSettingsForm()
@ -61,7 +59,7 @@ void ShopSettingsForm::drawButtons()
if (m_btnMap[btn->objectName()] != NULL) if (m_btnMap[btn->objectName()] != NULL)
{ {
btn->setText(m_btnMap[btn->objectName()]->name()); btn->setText(m_btnMap[btn->objectName()]->shortName());
} }
if (entity()->favBtnSize() > 0) if (entity()->favBtnSize() > 0)
@ -81,10 +79,11 @@ void ShopSettingsForm::drawButtons()
FavoritItemPtr favItem = QSharedPointer<FavoritItem>(new FavoritItem); FavoritItemPtr favItem = QSharedPointer<FavoritItem>(new FavoritItem);
favItem->setFavButtonName(btn->objectName()); favItem->setFavButtonName(btn->objectName());
favItem->setName(item->name()); favItem->setName(item->name());
favItem->setShortName(item->shortName());
favItem->setRefId(item->id()); favItem->setRefId(item->id());
favItem->setPluginId(item->pluginId()); favItem->setPluginId(item->pluginId());
m_btnMap[btn->objectName()] = favItem; 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->setModel(m_itemModel);
ui->tableItems->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); ui->tableItems->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
ui->tableItems->setColumnHidden(0, true); ui->tableItems->setColumnHidden(0, true);
ui->tableItems->setColumnHidden(2, true);
ui->tableItems->setColumnHidden(3, true); ui->tableItems->setColumnHidden(3, true);
Service<FavoritItem> srvFav; Service<FavoritItem> srvFav;

@ -8,7 +8,7 @@
"default" : "", "default" : "",
"CZ" : "" "CZ" : ""
}, },
"schemaVersion" : 4, "schemaVersion" : 5,
"sql" : [ "sql" : [
"CREATE TABLE \"VoucherItem\" ( "CREATE TABLE \"VoucherItem\" (
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
@ -70,6 +70,8 @@ CREATE TABLE \"Voucher\" (
\"vatType\" INTEGER NOT NULL, \"vatType\" INTEGER NOT NULL,
\"pluginId\" TEXT NULL, \"pluginId\" TEXT NULL,
\"favButtonName\" TEXT NULL); \"favButtonName\" TEXT NULL);
",
"ALTER TABLE \"FavoritItem\" ADD \"shortName\" TEXT NULL;
" "
], ],
"dependencies" : [ "ADDRESSBOOK" ], "dependencies" : [ "ADDRESSBOOK" ],

@ -83,6 +83,7 @@ void ShopForm::loadLast()
m_commodityModel->setData(srv.allSellableItems()); m_commodityModel->setData(srv.allSellableItems());
ui->commodityTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); ui->commodityTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
ui->commodityTable->setColumnHidden(3, true); ui->commodityTable->setColumnHidden(3, true);
ui->commodityTable->setColumnHidden(2, true);
if (srv.isEetEnabled()) if (srv.isEetEnabled())
{ {
@ -124,7 +125,7 @@ void ShopForm::loadButtons()
if (btnMap[btnName] != NULL) if (btnMap[btnName] != NULL)
{ {
btn->setText(btnMap[btnName]->name()); btn->setText(btnMap[btnName]->shortName());
connect(btn, &FavButton::clicked, [this, btnMap, btn](bool){ connect(btn, &FavButton::clicked, [this, btnMap, btn](bool){
FavoritItemPtr item = btnMap[btn->objectName()]; FavoritItemPtr item = btnMap[btn->objectName()];
@ -161,11 +162,6 @@ void ShopForm::fillRaceiptCombo()
void ShopForm::on_directSale_clicked() void ShopForm::on_directSale_clicked()
{ {
if (m_voucher.isNull())
{
createVoucher();
}
DirectSaleForm *form = new DirectSaleForm(this); DirectSaleForm *form = new DirectSaleForm(this);
form->setAttribute(Qt::WA_DeleteOnClose); form->setAttribute(Qt::WA_DeleteOnClose);
@ -357,6 +353,11 @@ void ShopForm::createEmptyVoucher()
void ShopForm::addItem(QSharedPointer<IShopItem> item, int count) void ShopForm::addItem(QSharedPointer<IShopItem> item, int count)
{ {
if (m_voucher.isNull())
{
createVoucher();
}
ShopService srv; ShopService srv;
srv.addShopItem(m_voucher, item, count); srv.addShopItem(m_voucher, item, count);
this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]); 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() void ShopForm::on_btnAddItem_clicked()
{ {
if (m_voucher.isNull())
{
createVoucher();
}
ShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex()); ShopItemPtr item = m_commodityModel->itemFromIndex(ui->commodityTable->currentIndex());
addItem(item, ui->spnCount->value()); addItem(item, ui->spnCount->value());
} }

@ -12,6 +12,7 @@ class SHOPSHARED_EXPORT ShopItem : public QObject, public IShopItem
Q_PROPERTY(QString code READ code) Q_PROPERTY(QString code READ code)
Q_PROPERTY(QString name READ name) Q_PROPERTY(QString name READ name)
Q_PROPERTY(QString shortName READ shortName)
Q_PROPERTY(QDecDouble unitPrice READ unitPrice) Q_PROPERTY(QDecDouble unitPrice READ unitPrice)
Q_PROPERTY(Enums::VatType vatType READ vatType) Q_PROPERTY(Enums::VatType vatType READ vatType)
@ -27,6 +28,7 @@ public:
virtual int id() override { return 0; } virtual int id() override { return 0; }
virtual QString code() { return ""; } virtual QString code() { return ""; }
virtual QString name() override { return ""; } virtual QString name() override { return ""; }
virtual QString shortName() override { return ""; }
virtual QDecDouble unitPrice() override { return QDecDouble(); } virtual QDecDouble unitPrice() override { return QDecDouble(); }
virtual Enums::VatType vatType() override { return Enums::NONE; } virtual Enums::VatType vatType() override { return Enums::NONE; }
virtual QString pluginId() override { return ""; } virtual QString pluginId() override { return ""; }

Loading…
Cancel
Save