kima2/src/gui/mainwindow.cpp

77 lines
2.3 KiB
C++
Raw Normal View History

2018-07-14 14:03:35 +02:00
#include "mainwindow.h"
2018-07-21 19:24:56 +02:00
#include "pricedialog.h"
2018-07-21 21:18:22 +02:00
#include "sellerdialog.h"
2018-07-16 12:00:17 +02:00
2018-07-20 22:07:42 +02:00
#include <regex>
2018-07-17 10:37:21 +02:00
constexpr int STATUSBAR_TIMEOUT = 5000;
2018-07-14 14:03:35 +02:00
MainWindow::MainWindow()
{
2018-07-14 15:54:29 +02:00
ui_.setupUi(this);
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit);
2018-07-17 10:37:21 +02:00
connect(ui_.actionEditSeller, &QAction::triggered, this,
&MainWindow::on_actionEditSeller_triggered);
2018-07-20 22:07:42 +02:00
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
&MainWindow::on_sellerNoEdit_checkSellerNo);
2018-07-14 15:54:29 +02:00
marketplace_ = std::make_unique<Marketplace>();
2018-07-17 10:37:21 +02:00
marketplace_->loadFromDb();
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
2018-07-14 15:54:29 +02:00
}
2018-07-16 12:00:17 +02:00
void MainWindow::on_actionEditSeller_triggered()
{
auto dialog = std::make_unique<SellerDialog>(this);
2018-07-16 18:04:25 +02:00
int retCode = dialog->exec();
if (retCode == QDialog::Accepted) {
2018-07-18 09:00:46 +02:00
marketplace_->sortSellers();
2018-07-16 18:04:25 +02:00
marketplace_->storeToDb();
2018-07-17 10:37:21 +02:00
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.",
STATUSBAR_TIMEOUT);
2018-07-16 18:04:25 +02:00
} else {
marketplace_->loadFromDb();
2018-07-17 11:09:35 +02:00
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten verworfen!",
2018-07-17 10:37:21 +02:00
STATUSBAR_TIMEOUT);
2018-07-16 18:04:25 +02:00
}
2018-07-20 22:07:42 +02:00
}
void MainWindow::on_sellerNoEdit_checkSellerNo()
{
using std::regex, std::regex_match, std::smatch;
auto inputText = ui_.sellerNoEdit->text().toStdString();
if (inputText.empty()) {
2018-07-21 21:18:22 +02:00
if (marketplace_->basketSize() > 0) {
marketplace_->finishCurrentSale();
}
2018-07-20 22:07:42 +02:00
return;
}
regex pattern{R"(\d{1,5})"};
smatch result;
2018-07-21 21:18:22 +02:00
2018-07-20 22:07:42 +02:00
if (!regex_match(inputText, result, pattern)) {
return;
}
2018-07-21 21:18:22 +02:00
2018-07-20 22:07:42 +02:00
int sellerNo = std::stoi(result[0]);
auto seller = marketplace_->findSellerWithSellerNo(sellerNo);
if (seller) {
2018-07-21 19:24:56 +02:00
PriceDialog priceDialog(this);
auto dialogResult = priceDialog.exec();
2018-07-21 21:18:22 +02:00
if (dialogResult == QDialog::Accepted) {
2018-07-21 19:24:56 +02:00
int price = priceDialog.getPrice();
auto article = std::make_unique<Article>(price);
article->setSeller(seller);
2018-07-21 21:18:22 +02:00
std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
2018-07-21 19:24:56 +02:00
marketplace_->addArticleToBasket(std::move(article));
}
2018-07-20 22:07:42 +02:00
}
2018-07-20 22:10:05 +02:00
2018-07-20 22:07:42 +02:00
ui_.sellerNoEdit->clear();
2018-07-16 12:00:17 +02:00
}