Added favorite buttons to shop form.

closes #276
This commit is contained in:
2017-03-28 22:13:54 +02:00
parent 7aa00f1b1e
commit b0d67cf93a
19 changed files with 361 additions and 384 deletions
+52 -1
View File
@@ -13,6 +13,8 @@
#include <QSharedPointer>
#include <QSortFilterProxyModel>
#include <QMessageBox>
#include "data/favorititem.h"
#include "favbutton.h"
#include "shop-odb.hxx"
@@ -36,6 +38,8 @@ ShopForm::~ShopForm()
void ShopForm::loadLast()
{
loadButtons();
if (m_itemsModel == NULL)
{
m_itemsModel = new AutoTableModel<VoucherItem>(this);
@@ -91,6 +95,53 @@ void ShopForm::loadLast()
}
}
void ShopForm::loadButtons()
{
SettingsService srv("SHOP");
ShopSettingsPtr settings = srv.loadSettings<ShopSettings>();
Service<FavoritItem> srvFav;
QMap<QString, FavoritItemPtr> btnMap;
foreach (FavoritItemPtr item, srvFav.all()) {
btnMap[item->favButtonName()] = item;
}
for (int i = 0; i < settings->favBtnRows(); i++)
{
for (int j = 0; j < settings->favBtnCols(); j++)
{
FavButton *btn = new FavButton(ui->favorites);
QString btnName = QString::number(i) + "_" + QString::number(j);
btn->setObjectName(btnName);
if (settings->favBtnSize() > 0)
{
btn->setMinimumHeight(settings->favBtnSize());
btn->setMinimumWidth(settings->favBtnSize());
}
((QGridLayout*)ui->favorites->layout())->addWidget(btn, i + 1, j);
if (btnMap[btnName] != NULL)
{
btn->setText(btnMap[btnName]->name());
connect(btn, &FavButton::clicked, [this, btnMap, btn](bool){
FavoritItemPtr item = btnMap[btn->objectName()];
IPlugin *plugin = Context::instance().plugin(item->pluginId());
IService *service = (plugin != NULL ? plugin->service<IService>() : NULL);
ISellableService *selSrv = dynamic_cast<ISellableService*>(service);
if (selSrv != NULL)
{
addItem(selSrv->shopItem(item->refId()), 1);
}
});
}
}
}
}
void ShopForm::fillRaceiptCombo()
{
bool oldState = ui->receiptCombo->blockSignals(true);
@@ -430,7 +481,7 @@ void ShopForm::on_commoditySearch_textChanged(const QString &text)
}
}
void ShopForm::on_lblEetState_linkActivated(const QString &link)
void ShopForm::on_lblEetState_linkActivated(const QString &)
{
ShopService srv;
srv.setEetOnline(!srv.isEetOnline());