draback information added

This commit is contained in:
Martin Brodbeck 2018-08-08 13:36:49 +02:00
parent 801b4cba62
commit 3a2e8d05cb
4 changed files with 67 additions and 10 deletions

View file

@ -3,7 +3,7 @@ set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.62 COMPONENTS date_time REQUIRED) find_package(Boost 1.62 COMPONENTS date_time REQUIRED)
find_package(SQLite3 REQUIRED) find_package(SQLite3 REQUIRED)
#find_package(PkgConfig REQUIRED) #find_package(PkgConfig REQUIRED)
find_package(XLNT REQUIRED) find_package(XLNT REQUIRED STATIC)
find_package(JSONCPP REQUIRED) find_package(JSONCPP REQUIRED)
#pkg_check_modules(XLNT REQUIRED xlnt>=1.3) #pkg_check_modules(XLNT REQUIRED xlnt>=1.3)
#pkg_check_modules(JSONCPP REQUIRED jsoncpp) #pkg_check_modules(JSONCPP REQUIRED jsoncpp)

View file

@ -9,6 +9,8 @@
#include "sellerdialog.h" #include "sellerdialog.h"
#include "settingsdialog.h" #include "settingsdialog.h"
#include <utils.h>
#include <excelreader.h> #include <excelreader.h>
#include <posprinter.h> #include <posprinter.h>
@ -58,11 +60,15 @@ MainWindow::MainWindow()
marketplace_->clear(); marketplace_->clear();
setSaleModel(); setSaleModel();
}); });
ui_.sellerNoEdit->installEventFilter(this);
ui_.givenSpinBox->installEventFilter(this);
connect(ui_.actionEditSeller, &QAction::triggered, this, connect(ui_.actionEditSeller, &QAction::triggered, this,
&MainWindow::onActionEditSellerTriggered); &MainWindow::onActionEditSellerTriggered);
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
&MainWindow::onSellerNoEditCheckSellerNo);
connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered); connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered);
connect(ui_.givenSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&MainWindow::onGivenSpinBoxValueChanged);
connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&MainWindow::onBasketViewSelectionChanged); &MainWindow::onBasketViewSelectionChanged);
connect(ui_.cancelArticleButton, &QPushButton::clicked, this, connect(ui_.cancelArticleButton, &QPushButton::clicked, this,
@ -108,7 +114,6 @@ MainWindow::MainWindow()
&MainWindow::onImportSalesJsonActionTriggered); &MainWindow::onImportSalesJsonActionTriggered);
readGeometry(); readGeometry();
ui_.drawbackContainerWidget->setVisible(false);
setWindowIcon(QIcon(":/misc/kima2.ico")); setWindowIcon(QIcon(":/misc/kima2.ico"));
} }
@ -151,19 +156,61 @@ void MainWindow::onPaidButtonTriggered()
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale(); dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
ui_.lastPriceLabel1->setText(lastPrice); ui_.lastPriceLabel1->setText(lastPrice);
ui_.lastPriceLabel2->setText(lastPrice); ui_.lastPriceLabel2->setText(lastPrice);
ui_.basketSumLabel->setText(" 0,00 €"); ui_.basketSumLabel->setText(formatCentAsEuroString(0).c_str());
ui_.drawbackLabel->setText(formatCentAsEuroString(0).c_str());
ui_.drawbackContainerWidget->setEnabled(false);
ui_.sellerNoEdit->setFocus();
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT); statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
} }
} }
void MainWindow::onSellerNoEditCheckSellerNo() bool MainWindow::eventFilter(QObject* target, QEvent* event)
{
if (target == ui_.sellerNoEdit) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) {
if (keyEvent->modifiers() == Qt::ControlModifier) {
checkSellerNo(true);
} else {
checkSellerNo(false);
}
return true;
}
}
} else if (target == ui_.givenSpinBox) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) {
if (keyEvent->modifiers() == Qt::ControlModifier) {
onPaidButtonTriggered();
return true;
}
} else if (keyEvent->key() == Qt::Key::Key_Escape) {
ui_.drawbackLabel->setText(formatCentAsEuroString(0).c_str());
ui_.drawbackContainerWidget->setEnabled(false);
ui_.sellerNoEdit->setFocus();
}
}
}
return QMainWindow::eventFilter(target, event);
}
void MainWindow::checkSellerNo(bool ctrlPressed)
{ {
using std::regex, std::regex_match, std::smatch; using std::regex, std::regex_match, std::smatch;
auto inputText = ui_.sellerNoEdit->text().toStdString(); auto inputText = ui_.sellerNoEdit->text().toStdString();
if (inputText.empty()) { if (inputText.empty()) {
if (ctrlPressed == false) {
onPaidButtonTriggered(); onPaidButtonTriggered();
} else if (marketplace_->getBasket().size() > 0) {
ui_.drawbackContainerWidget->setEnabled(true);
ui_.givenSpinBox->setFocus();
ui_.givenSpinBox->selectAll();
}
return; return;
} }
@ -192,6 +239,14 @@ void MainWindow::onSellerNoEditCheckSellerNo()
ui_.sellerNoEdit->clear(); ui_.sellerNoEdit->clear();
} }
void MainWindow::onGivenSpinBoxValueChanged(double value)
{
int givenInCent = std::round(value * 100);
int basketSumInCent = marketplace_->getBasketSumInCent();
int drawback = givenInCent - basketSumInCent;
ui_.drawbackLabel->setText(formatCentAsEuroString(drawback).c_str());
}
void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected, void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
[[maybe_unused]] const QItemSelection& deselected) [[maybe_unused]] const QItemSelection& deselected)
{ {

View file

@ -29,14 +29,16 @@ class MainWindow : public QMainWindow
void onCancelAllArticlesButtonClicked(bool checked); void onCancelAllArticlesButtonClicked(bool checked);
void onAboutQt(); void onAboutQt();
void onAbout(); void onAbout();
virtual bool eventFilter(QObject *target, QEvent *event) override;
protected: protected:
virtual void closeEvent(QCloseEvent* event) override; virtual void closeEvent(QCloseEvent* event) override;
private: private:
void onActionEditSellerTriggered(); void onActionEditSellerTriggered();
void onSellerNoEditCheckSellerNo(); void checkSellerNo(bool ctrlPressed = false);
void onPaidButtonTriggered(); void onPaidButtonTriggered();
void onGivenSpinBoxValueChanged(double value);
void onImportSellerExcelActionTriggered(); void onImportSellerExcelActionTriggered();
void onImportSellerJsonActionTriggered(); void onImportSellerJsonActionTriggered();
void onExportSellerJsonActionTriggered(); void onExportSellerJsonActionTriggered();

View file

@ -112,7 +112,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="doubleSpinBox"/> <widget class="QDoubleSpinBox" name="givenSpinBox"/>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
@ -125,7 +125,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="drawbackLabel">
<property name="font"> <property name="font">
<font> <font>
<weight>75</weight> <weight>75</weight>