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
-6
View File
@@ -1,6 +0,0 @@
#include "favoriteservice.h"
FavoriteService::FavoriteService()
{
}
-13
View File
@@ -1,13 +0,0 @@
#ifndef FAVORITESERVICE_H
#define FAVORITESERVICE_H
#include <core.h>
#include "data/favorititem.h"
class FavoriteService : public Service<FavoritItem>
{
public:
FavoriteService();
};
#endif // FAVORITESERVICE_H
+34
View File
@@ -9,6 +9,10 @@ ShopSettings::ShopSettings(QObject *parent) : QObject(parent)
m_eetMode = 1;
m_eetTest = 0;
m_eetPlayground = 0;
m_favBtnCols = 0;
m_favBtnRows = 0;
m_favBtnSize = 0;
}
QString ShopSettings::output() const
@@ -130,3 +134,33 @@ void ShopSettings::setEetPlayground(bool eetPlayground)
{
m_eetPlayground = eetPlayground;
}
int ShopSettings::favBtnCols() const
{
return m_favBtnCols;
}
void ShopSettings::setFavBtnCols(int favBtnCols)
{
m_favBtnCols = favBtnCols;
}
int ShopSettings::favBtnRows() const
{
return m_favBtnRows;
}
void ShopSettings::setFavBtnRows(int favBtnRows)
{
m_favBtnRows = favBtnRows;
}
int ShopSettings::favBtnSize() const
{
return m_favBtnSize;
}
void ShopSettings::setFavBtnSize(int favBtnSize)
{
m_favBtnSize = favBtnSize;
}
+17
View File
@@ -18,6 +18,10 @@ class ShopSettings : public QObject
Q_PROPERTY(bool eetTest READ eetTest WRITE setEetTest)
Q_PROPERTY(bool eetPlayground READ eetPlayground WRITE setEetPlayground)
Q_PROPERTY(int favBtnCols READ favBtnCols WRITE setFavBtnCols)
Q_PROPERTY(int favBtnRows READ favBtnRows WRITE setFavBtnRows)
Q_PROPERTY(int favBtnSize READ favBtnSize WRITE setFavBtnSize)
Q_OBJECT
public:
@@ -64,6 +68,15 @@ public:
bool eetPlayground() const;
void setEetPlayground(bool eetPlayground);
int favBtnCols() const;
void setFavBtnCols(int favBtnCols);
int favBtnRows() const;
void setFavBtnRows(int favBtnRows);
int favBtnSize() const;
void setFavBtnSize(int favBtnSize);
private:
QString m_output;
CODEPAGE m_codepage;
@@ -78,6 +91,10 @@ private:
QString m_eetKeyPassword;
bool m_eetTest;
bool m_eetPlayground;
int m_favBtnCols;
int m_favBtnRows;
int m_favBtnSize;
};
typedef QSharedPointer<ShopSettings> ShopSettingsPtr;
+110
View File
@@ -4,7 +4,11 @@
#include <settingsservice.h>
#include <combodata.h>
#include <QFileDialog>
#include <QDragEnterEvent>
#include <QDebug>
#include "shopservice.h"
#include "shop-odb.hxx"
ShopSettingsForm::ShopSettingsForm(QWidget *parent) :
FormBinder<ShopSettings>(parent),
@@ -27,7 +31,13 @@ ShopSettingsForm::ShopSettingsForm(QWidget *parent) :
registerBinding(ui->eetTest);
registerBinding(ui->eetPlayground);
registerBinding(ui->favBtnCols);
registerBinding(ui->favBtnRows);
registerBinding(ui->favBtnSize);
m_itemModel = new AutoTableModel<ShopItem>();
}
ShopSettingsForm::~ShopSettingsForm()
@@ -35,6 +45,51 @@ ShopSettingsForm::~ShopSettingsForm()
delete ui;
}
void ShopSettingsForm::drawButtons()
{
foreach (QWidget *child, ui->btnWidget->findChildren<QWidget*>()) {
delete child;
}
for (int i = 0; i < entity()->favBtnRows(); i++)
{
for (int j = 0; j < entity()->favBtnCols(); j++)
{
FavButton *btn = new FavButton(ui->btnWidget);
btn->setObjectName(QString::number(i) + "_" + QString::number(j));
btn->setAcceptDrops(true);
if (m_btnMap[btn->objectName()] != NULL)
{
btn->setText(m_btnMap[btn->objectName()]->name());
}
if (entity()->favBtnSize() > 0)
{
btn->setMinimumHeight(entity()->favBtnSize());
btn->setMinimumWidth(entity()->favBtnSize());
}
((QGridLayout*)ui->btnWidget->layout())->addWidget(btn, i, j);
connect(btn, &FavButton::clicked, [this, btn](bool){
btn->setText("");
m_btnMap.remove(btn->objectName());
});
connect(btn, &FavButton::itemDropped, [this, btn](){
ShopItemPtr item = m_itemModel->itemFromIndex(ui->tableItems->currentIndex());
FavoritItemPtr favItem = QSharedPointer<FavoritItem>(new FavoritItem);
favItem->setFavButtonName(btn->objectName());
favItem->setName(item->name());
favItem->setRefId(item->id());
favItem->setPluginId(item->pluginId());
m_btnMap[btn->objectName()] = favItem;
btn->setText(item->name());
});
}
}
}
void ShopSettingsForm::loadEntity()
{
SettingsService srv("SHOP");
@@ -43,7 +98,18 @@ void ShopSettingsForm::loadEntity()
ShopService srvShop;
m_itemModel->setData(srvShop.allSellableItems());
m_itemModel->setTranslations(Context::instance().plugin("SHOP")->translations());
ui->tableItems->setModel(m_itemModel);
ui->tableItems->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
ui->tableItems->setColumnHidden(0, true);
ui->tableItems->setColumnHidden(3, true);
Service<FavoritItem> srvFav;
foreach (FavoritItemPtr favItem, srvFav.all()) {
m_btnMap[favItem->favButtonName()] = favItem;
}
drawButtons();
}
bool ShopSettingsForm::saveRecord()
@@ -52,6 +118,18 @@ bool ShopSettingsForm::saveRecord()
SettingsService srv("SHOP");
srv.saveSettings(entity());
Service<FavoritItem> srvFav;
foreach (FavoritItemPtr item, srvFav.all()) {
srvFav.erase(item);
}
foreach (QString btnName, m_btnMap.keys()) {
if (m_btnMap[btnName] != NULL)
{
srvFav.save(m_btnMap[btnName]);
}
}
return true;
}
@@ -64,3 +142,35 @@ void ShopSettingsForm::on_btnCertBrowse_clicked()
ui->eetCertificate->setText(certFile);
}
}
void ShopSettingsForm::on_favBtnCols_textChanged(const QString &arg1)
{
entity()->setFavBtnCols(arg1.toInt());
drawButtons();
}
void ShopSettingsForm::on_favBtnRows_textChanged(const QString &arg1)
{
entity()->setFavBtnRows(arg1.toInt());
drawButtons();
}
void ShopSettingsForm::on_favBtnSize_textChanged(const QString &arg1)
{
entity()->setFavBtnSize(arg1.toInt());
drawButtons();
}
FavButton::FavButton(QWidget *parent) : QToolButton(parent)
{
}
void FavButton::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
void FavButton::dropEvent(QDropEvent *)
{
emit itemDropped();
}
+13
View File
@@ -2,10 +2,14 @@
#define SHOPSETTINGSFORM_H
#include <QWidget>
#include <QToolButton>
#include <formbinder.h>
#include <QMap>
#include "shopsettings.h"
#include <core.h>
#include "shopitem.h"
#include "data/favorititem.h"
#include "favbutton.h"
namespace Ui {
class ShopSettingsForm;
@@ -22,6 +26,11 @@ public:
private:
Ui::ShopSettingsForm *ui;
AutoTableModel<ShopItem> *m_itemModel;
int m_favBtnRows;
int m_favBtnCols;
int m_favBtnSize;
QMap<QString, FavoritItemPtr> m_btnMap;
void drawButtons();
// IForm interface
public:
@@ -29,8 +38,12 @@ public:
public slots:
bool saveRecord();
private slots:
void on_btnCertBrowse_clicked();
void on_favBtnCols_textChanged(const QString &arg1);
void on_favBtnRows_textChanged(const QString &arg1);
void on_favBtnSize_textChanged(const QString &arg1);
};
#endif // SHOPSETTINGSFORM_H
+56 -132
View File
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>645</width>
<height>463</height>
<width>760</width>
<height>505</height>
</rect>
</property>
<property name="windowTitle">
@@ -33,7 +33,7 @@
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
<enum>QAbstractItemView::DragOnly</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
@@ -48,138 +48,13 @@
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="3">
<widget class="QToolButton" name="toolButton_9">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QToolButton" name="toolButton_10">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="toolButton_3">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QToolButton" name="toolButton_6">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
<widget class="QWidget" name="btnWidget" native="true">
<layout class="QGridLayout" name="gridLayout"/>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="toolButton_4">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="toolButton">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="toolButton_8">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="toolButton_2">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QToolButton" name="toolButton_5">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QToolButton" name="toolButton_7">
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="2" column="2">
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -192,6 +67,55 @@
</property>
</spacer>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QWidget" name="widget_4" native="true">
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Columns</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="favBtnCols"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Rows</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="favBtnRows"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="favBtnSize"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>