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(SQLite3 REQUIRED)
#find_package(PkgConfig REQUIRED)
find_package(XLNT REQUIRED)
find_package(XLNT REQUIRED STATIC)
find_package(JSONCPP REQUIRED)
#pkg_check_modules(XLNT REQUIRED xlnt>=1.3)
#pkg_check_modules(JSONCPP REQUIRED jsoncpp)

View File

@ -9,6 +9,8 @@
#include "sellerdialog.h"
#include "settingsdialog.h"
#include <utils.h>
#include <excelreader.h>
#include <posprinter.h>
@ -58,11 +60,15 @@ MainWindow::MainWindow()
marketplace_->clear();
setSaleModel();
});
ui_.sellerNoEdit->installEventFilter(this);
ui_.givenSpinBox->installEventFilter(this);
connect(ui_.actionEditSeller, &QAction::triggered, this,
&MainWindow::onActionEditSellerTriggered);
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
&MainWindow::onSellerNoEditCheckSellerNo);
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,
&MainWindow::onBasketViewSelectionChanged);
connect(ui_.cancelArticleButton, &QPushButton::clicked, this,
@ -108,7 +114,6 @@ MainWindow::MainWindow()
&MainWindow::onImportSalesJsonActionTriggered);
readGeometry();
ui_.drawbackContainerWidget->setVisible(false);
setWindowIcon(QIcon(":/misc/kima2.ico"));
}
@ -151,19 +156,61 @@ void MainWindow::onPaidButtonTriggered()
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
ui_.lastPriceLabel1->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);
}
}
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;
auto inputText = ui_.sellerNoEdit->text().toStdString();
if (inputText.empty()) {
onPaidButtonTriggered();
if (ctrlPressed == false) {
onPaidButtonTriggered();
} else if (marketplace_->getBasket().size() > 0) {
ui_.drawbackContainerWidget->setEnabled(true);
ui_.givenSpinBox->setFocus();
ui_.givenSpinBox->selectAll();
}
return;
}
@ -192,6 +239,14 @@ void MainWindow::onSellerNoEditCheckSellerNo()
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,
[[maybe_unused]] const QItemSelection& deselected)
{

View File

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

View File

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