kima2/src/gui/pricedialog.cpp

36 lines
1.2 KiB
C++
Raw Normal View History

2018-07-21 19:24:56 +02:00
#include "pricedialog.h"
2018-07-22 20:56:20 +02:00
#include <cmath>
#include <QMessageBox>
PriceDialog::PriceDialog(QWidget* parent, bool forceDesc, Qt::WindowFlags f) : QDialog(parent, f)
2018-07-21 19:24:56 +02:00
{
forceDesc_ = forceDesc;
2018-07-21 19:24:56 +02:00
ui_.setupUi(this);
ui_.priceSpinBox->setFocus();
}
2018-07-22 20:56:20 +02:00
int PriceDialog::getPrice() const { return static_cast<int>(ui_.priceSpinBox->value() * 100); }
std::string PriceDialog::getDescription() const { return ui_.descEdit->text().toStdString(); }
2018-07-22 20:56:20 +02:00
void PriceDialog::accept()
2018-07-21 19:24:56 +02:00
{
2018-07-22 20:56:20 +02:00
if (static_cast<int>(std::round(ui_.priceSpinBox->value() * 100.0L)) % 50 != 0) {
QMessageBox(QMessageBox::Icon::Warning, "Falsche Preiseingabe",
2018-07-23 08:21:05 +02:00
"Es sind nur 0,50 Cent-Schritte erlaubt.", QMessageBox::StandardButton::Ok,
this)
2018-07-22 20:56:20 +02:00
.exec();
} else if (forceDesc_ && ui_.descEdit->text().trimmed().isEmpty()) {
QMessageBox(QMessageBox::Icon::Warning, "Artikelbeschreibung fehlt",
"Da Sie auf das Sonderkonto buchen ist eine Artikelbeschreibung erforderlich.",
QMessageBox::StandardButton::Ok, this)
.exec();
ui_.descEdit->setFocus();
2018-07-22 20:56:20 +02:00
} else {
QDialog::accept();
}
}
2019-10-07 14:08:01 +02:00
void PriceDialog::setForceDesc(bool force) { forceDesc_ = force; }