Added settings for seasons and number series. Added static method

ComboData::createComboData for easier combo bindings.
print
Josef Rokos 9 years ago committed by Rokos Josef
parent b33ff1b169
commit a89b0381b1

@ -30,11 +30,6 @@ CommodityForm::~CommodityForm()
void CommodityForm::registerCombos() void CommodityForm::registerCombos()
{ {
QList<ComboData> ct; Service<CommodityTypeData> srvComTypes;
Service<CommodityTypeData> cts; registerBinding(ui->type, ComboData::createComboData(srvComTypes.all()));
foreach (QSharedPointer<CommodityTypeData> ctd , cts.all()) {
ComboData cd(ctd);
ct << cd;
}
registerBinding(ui->type,ct);
} }

@ -20,6 +20,20 @@ public:
QString label() const; QString label() const;
void setLabel(const QString &label); void setLabel(const QString &label);
template<class T>
static QList<ComboData> createComboData(QList<QSharedPointer<T> > list) {
QList<ComboData> data;
foreach (QSharedPointer<T> item, list) {
QSharedPointer<QObject> qObj = qSharedPointerDynamicCast<QObject, T>(item);
if (!qObj.isNull())
{
data << ComboData(qObj);
}
}
return data;
}
private: private:
QVariant m_index; QVariant m_index;
QString m_label; QString m_label;

@ -125,6 +125,16 @@ Context::Context()
m_dbOpened = false; m_dbOpened = false;
} }
SeasonPtr Context::currentSeason() const
{
return m_currentSeason;
}
void Context::setCurrentSeason(const SeasonPtr &currentSeason)
{
m_currentSeason = currentSeason;
}
QSharedPointer<User> Context::currentUser() const QSharedPointer<User> Context::currentUser() const
{ {
return m_currentUser; return m_currentUser;
@ -271,6 +281,8 @@ void Context::checkSeason()
season->setActive(true); season->setActive(true);
srv.save(season); srv.save(season);
} }
m_currentSeason = season;
} }
void Context::checkNumberSeries() void Context::checkNumberSeries()

@ -39,6 +39,11 @@ public:
odb::session &session(); odb::session &session();
SeasonPtr currentSeason() const;
void setCurrentSeason(const SeasonPtr &currentSeason);
void checkNumberSeries();
private: private:
Context(); Context();
QList<IPlugin*> m_plugins; QList<IPlugin*> m_plugins;
@ -47,6 +52,7 @@ private:
bool m_dbOpened; bool m_dbOpened;
odb::session m_session; odb::session m_session;
QSharedPointer<User> m_currentUser; QSharedPointer<User> m_currentUser;
SeasonPtr m_currentSeason;
QStringList m_solved; QStringList m_solved;
@ -56,7 +62,6 @@ private:
void createSchema(IPlugin *plugin, const QSqlDatabase &db, const QMap<QString, int> &schemaMap); void createSchema(IPlugin *plugin, const QSqlDatabase &db, const QMap<QString, int> &schemaMap);
void checkPermissions(); void checkPermissions();
void checkSeason(); void checkSeason();
void checkNumberSeries();
}; };
#endif // CONTEXT_H #endif // CONTEXT_H

@ -56,7 +56,8 @@ SOURCES += \
data/numberseries.cpp \ data/numberseries.cpp \
data/season.cpp \ data/season.cpp \
seasonservice.cpp \ seasonservice.cpp \
numberseriesservice.cpp numberseriesservice.cpp \
settings/seasonnamedialog.cpp
HEADERS += core.h\ HEADERS += core.h\
core_global.h \ core_global.h \
@ -112,7 +113,8 @@ HEADERS += core.h\
data/numberseries.h \ data/numberseries.h \
data/season.h \ data/season.h \
seasonservice.h \ seasonservice.h \
numberseriesservice.h numberseriesservice.h \
settings/seasonnamedialog.h
unix { unix {
target.path = /usr/lib target.path = /usr/lib
@ -146,7 +148,8 @@ FORMS += \
savefilterdialog.ui \ savefilterdialog.ui \
filterdialog.ui \ filterdialog.ui \
settingsform.ui \ settingsform.ui \
settings/globalsettingsform.ui settings/globalsettingsform.ui \
settings/seasonnamedialog.ui
OTHER_FILES += \ OTHER_FILES += \
users/metaData.json \ users/metaData.json \
@ -154,6 +157,9 @@ OTHER_FILES += \
CONFIG(debug, release|debug):DEFINES += _DEBUG CONFIG(debug, release|debug):DEFINES += _DEBUG
win32:CONFIG(release, debug|release):DEFINES += PLUGIN_ROOT=\\\"/plugins\\\"
else:unix:CONFIG(release, debug|release):DEFINES += PLUGIN_ROOT=\\\"/usr/lib/prodejna/plugins\\\"
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber
else:unix: LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber else:unix: LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber

@ -49,4 +49,6 @@ private:
QSharedPointer<Season> m_season; QSharedPointer<Season> m_season;
}; };
typedef QSharedPointer<NumberSeries> NumberSeriesPtr;
#endif // NUMBERSERIES_H #endif // NUMBERSERIES_H

@ -46,4 +46,6 @@ private:
bool m_active; bool m_active;
}; };
typedef QSharedPointer<Season> SeasonPtr;
#endif // SEASON_H #endif // SEASON_H

@ -1,8 +1,14 @@
#include "globalsettingsform.h" #include "globalsettingsform.h"
#include "ui_globalsettingsform.h" #include "ui_globalsettingsform.h"
#include <QMessageBox>
#include "seasonnamedialog.h"
#include "globalsettings.h" #include "globalsettings.h"
#include "../settingsservice.h" #include "../settingsservice.h"
#include "../seasonservice.h"
#include "../numberseriesservice.h"
#include "core-odb.hxx"
GlobalSettingsForm::GlobalSettingsForm(QWidget *parent) : GlobalSettingsForm::GlobalSettingsForm(QWidget *parent) :
FormBinder<GlobalSettings>(parent), FormBinder<GlobalSettings>(parent),
@ -21,6 +27,10 @@ GlobalSettingsForm::GlobalSettingsForm(QWidget *parent) :
registerBinding(ui->vatHigh); registerBinding(ui->vatHigh);
registerBinding(ui->vatFirstLower); registerBinding(ui->vatFirstLower);
registerBinding(ui->vatSecondLower); registerBinding(ui->vatSecondLower);
m_seriesModel = new AutoTableModel<NumberSeries>(this);
m_seriesModel->setEditableCols(QList<int>() << 0);
ui->tableNumSer->setModel(m_seriesModel);
} }
GlobalSettingsForm::~GlobalSettingsForm() GlobalSettingsForm::~GlobalSettingsForm()
@ -28,8 +38,61 @@ GlobalSettingsForm::~GlobalSettingsForm()
delete ui; delete ui;
} }
void GlobalSettingsForm::loadSeasons()
{
ui->season->clear();
SeasonService srv;
m_seasons = srv.all();
foreach (SeasonPtr season, m_seasons) {
ui->season->addItem(season->name());
if (season->active())
{
ui->season->setCurrentIndex(ui->season->count() - 1);
}
}
}
void GlobalSettingsForm::loadNumSeries()
{
NumberSeriesService srvNumSer;
SeasonService srvSeason;
if (ui->season->currentIndex() >= 0)
{
SeasonPtr currentSeason = m_seasons[ui->season->currentIndex()];
m_seriesModel->setData(srvNumSer.allForSeason(currentSeason));
}
}
bool GlobalSettingsForm::saveRecord() bool GlobalSettingsForm::saveRecord()
{ {
SeasonService srvSeason;
NumberSeriesService srvNumSer;
SeasonPtr selSeason = m_seasons[ui->season->currentIndex()];
if (selSeason->id() != Context::instance().currentSeason()->id())
{
if (QMessageBox::question(this, tr("Switch season"), tr("Realy switch active season?")) == QMessageBox::Yes)
{
srvSeason.activate(selSeason);
Context::instance().setCurrentSeason(selSeason);
}
else
{
return false;
}
}
foreach (SeasonPtr season, m_seasons) {
srvSeason.update(season);
}
foreach (NumberSeriesPtr numSer, m_seriesModel->list()) {
srvNumSer.update(numSer);
}
bindToData(); bindToData();
SettingsService srv("CORE"); SettingsService srv("CORE");
srv.saveSettings(entity()); srv.saveSettings(entity());
@ -43,9 +106,52 @@ void GlobalSettingsForm::loadEntity()
QSharedPointer<GlobalSettings> settings = srv.loadSettings<GlobalSettings>(); QSharedPointer<GlobalSettings> settings = srv.loadSettings<GlobalSettings>();
setEntity(settings); setEntity(settings);
ui->grpVat->setEnabled(settings->vatPayer()); ui->grpVat->setEnabled(settings->vatPayer());
loadSeasons();
loadNumSeries();
} }
void GlobalSettingsForm::on_vatPayer_toggled(bool checked) void GlobalSettingsForm::on_vatPayer_toggled(bool checked)
{ {
ui->grpVat->setEnabled(checked); ui->grpVat->setEnabled(checked);
} }
void GlobalSettingsForm::on_season_currentIndexChanged(int)
{
loadNumSeries();
}
void GlobalSettingsForm::on_btnEditName_clicked()
{
SeasonPtr selSeason = m_seasons[ui->season->currentIndex()];
SeasonNameDialog *dialog = new SeasonNameDialog(selSeason, this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
connect(dialog, &QDialog::accepted, [this](){
this->loadSeasons();
});
}
void GlobalSettingsForm::on_btnNew_clicked()
{
if (QMessageBox::question(this, tr("New season"), tr("Realy create new season and switch to it?")) == QMessageBox::Yes)
{
SeasonPtr newSeason = SeasonPtr(new Season);
SeasonNameDialog *dialog = new SeasonNameDialog(newSeason, this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
connect(dialog, &QDialog::accepted, [this, newSeason](){
SeasonService srv;
newSeason->setValidFrom(QDate::currentDate());
srv.save(newSeason);
srv.activate(newSeason);
Context::instance().setCurrentSeason(newSeason);
Context::instance().checkNumberSeries();
this->loadSeasons();
this->loadNumSeries();
});
}
}

@ -4,6 +4,8 @@
#include <QWidget> #include <QWidget>
#include "../formbinder.h" #include "../formbinder.h"
#include "globalsettings.h" #include "globalsettings.h"
#include "../autotablemodel.h"
#include "../data/numberseries.h"
namespace Ui { namespace Ui {
class GlobalSettingsForm; class GlobalSettingsForm;
@ -19,6 +21,11 @@ public:
private: private:
Ui::GlobalSettingsForm *ui; Ui::GlobalSettingsForm *ui;
AutoTableModel<NumberSeries> *m_seriesModel;
QList<SeasonPtr> m_seasons;
void loadSeasons();
void loadNumSeries();
// IForm interface // IForm interface
public slots: public slots:
@ -29,6 +36,9 @@ public:
void loadEntity() override; void loadEntity() override;
private slots: private slots:
void on_vatPayer_toggled(bool checked); void on_vatPayer_toggled(bool checked);
void on_season_currentIndexChanged(int index);
void on_btnEditName_clicked();
void on_btnNew_clicked();
}; };
#endif // GLOBALSETTINGSFORM_H #endif // GLOBALSETTINGSFORM_H

@ -6,14 +6,115 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>586</width> <width>759</width>
<height>419</height> <height>552</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::North</enum>
</property>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="elideMode">
<enum>Qt::ElideNone</enum>
</property>
<widget class="QWidget" name="tabBase">
<attribute name="title">
<string>Base settings</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Contact</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Firm Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="firmName"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Street</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="street"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>House Number</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="houseNumber"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>City</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="city"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>ZIP code</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="zipCode"/>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Logo</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Logo</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Select file</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
@ -110,90 +211,88 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0"> </layout>
<widget class="QGroupBox" name="groupBox"> </widget>
<property name="title"> <widget class="QWidget" name="tabNumSer">
<string>Contact</string> <attribute name="title">
<string>Number series</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="4">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <property name="sizeHint" stdset="0">
<item row="0" column="0"> <size>
<widget class="QLabel" name="label"> <width>40</width>
<property name="text"> <height>20</height>
<string>Firm Name</string> </size>
</property> </property>
</widget> </spacer>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="firmName"/> <widget class="QComboBox" name="season">
</item> <property name="minimumSize">
<item row="1" column="0"> <size>
<widget class="QLabel" name="label_2"> <width>120</width>
<property name="text"> <height>0</height>
<string>Street</string> </size>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="0" column="2">
<widget class="QLineEdit" name="street"/> <widget class="QPushButton" name="btnEditName">
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>House Number</string> <string>Edit name</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/edit.svg</normaloff>:/icons/edit.svg</iconset>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="0" column="0">
<widget class="QLineEdit" name="houseNumber"/> <widget class="QLabel" name="label_12">
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
<string>City</string> <string>Season</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="0" column="3">
<widget class="QLineEdit" name="city"/> <widget class="QPushButton" name="btnNew">
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>ZIP code</string> <string>Create new</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/new.svg</normaloff>:/icons/new.svg</iconset>
</property>
<property name="flat">
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="1" column="0" colspan="5">
<widget class="QLineEdit" name="zipCode"/> <widget class="QGroupBox" name="groupBox_4">
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="groupBox_3">
<property name="title"> <property name="title">
<string>Logo</string> <string>Number series</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QLabel" name="label_8"> <widget class="QTableView" name="tableNumSer"/>
<property name="text">
<string>Logo</string>
</property>
</widget>
</item> </item>
<item> </layout>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Select file</string>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/> <resources>
<include location="../rc.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

@ -0,0 +1,24 @@
#include "seasonnamedialog.h"
#include "ui_seasonnamedialog.h"
SeasonNameDialog::SeasonNameDialog(SeasonPtr season, QWidget *parent) :
QDialog(parent),
ui(new Ui::SeasonNameDialog)
{
ui->setupUi(this);
m_binder.registerBinding(ui->name);
m_binder.setData(season.data());
m_binder.bindToUi();
}
SeasonNameDialog::~SeasonNameDialog()
{
delete ui;
}
void SeasonNameDialog::accept()
{
m_binder.bindToData();
QDialog::accept();
}

@ -0,0 +1,30 @@
#ifndef SEASONNAMEDIALOG_H
#define SEASONNAMEDIALOG_H
#include <QDialog>
#include "../data/season.h"
#include "../objectbinder.h"
namespace Ui {
class SeasonNameDialog;
}
class SeasonNameDialog : public QDialog
{
Q_OBJECT
public:
explicit SeasonNameDialog(SeasonPtr season, QWidget *parent = 0);
~SeasonNameDialog();
private:
Ui::SeasonNameDialog *ui;
ObjectBinder m_binder;
// QDialog interface
public slots:
void accept();
};
#endif // SEASONNAMEDIALOG_H

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SeasonNameDialog</class>
<widget class="QDialog" name="SeasonNameDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>406</width>
<height>82</height>
</rect>
</property>
<property name="windowTitle">
<string>Season</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Season name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="name"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>SeasonNameDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>SeasonNameDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

@ -16,6 +16,10 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Settings</string> <string>Settings</string>
</property> </property>
<property name="windowIcon">
<iconset resource="../application/appRc.qrc">
<normaloff>:/icons/settings.svg</normaloff>:/icons/settings.svg</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
@ -39,6 +43,8 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/> <resources>
<include location="../application/appRc.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

@ -44,14 +44,9 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
}); });
AddressBookService srvAdb;
QList<ComboData> comboData;
foreach (QSharedPointer<AddressbookData> adb, srvAdb.all()) {
comboData << ComboData(adb);
}
m_binder.setData(new Voucher); m_binder.setData(new Voucher);
m_binder.registerBinding(ui->contact, comboData); AddressBookService srvAdb;
m_binder.registerBinding(ui->contact, ComboData::createComboData(srvAdb.all()));
m_binder.bindToUi(); m_binder.bindToUi();
ui->contact->completer()->setCompletionMode(QCompleter::PopupCompletion); ui->contact->completer()->setCompletionMode(QCompleter::PopupCompletion);

Loading…
Cancel
Save