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;
}
QString CommodityData::shortName() const
QString CommodityData::shortName()
{
return m_shortName;
}

@ -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;

@ -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);

@ -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<FavoritItem> FavoritItemPtr;

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

@ -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;

@ -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;

@ -36,8 +36,6 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) :
registerBinding(ui->favBtnSize);
m_itemModel = new AutoTableModel<ShopItem>();
}
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<FavoritItem>(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<FavoritItem> srvFav;

@ -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" ],

@ -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<IShopItem> 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());
}

@ -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 ""; }

Loading…
Cancel
Save