More on basket

This commit is contained in:
Martin Brodbeck 2018-07-22 20:10:22 +02:00
parent d0f0d604ed
commit ee8c059441
9 changed files with 183 additions and 7 deletions

View file

@ -1,5 +1,6 @@
#include "mainwindow.h"
#include "basketmodel.h"
#include "pricedialog.h"
#include "sellerdialog.h"
@ -20,6 +21,11 @@ MainWindow::MainWindow()
marketplace_ = std::make_unique<Marketplace>();
marketplace_->loadFromDb();
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView);
ui_.basketView->setModel(model);
ui_.basketView->setColumnHidden(0, true); // hide the uuid
}
void MainWindow::on_actionEditSeller_triggered()
@ -46,14 +52,14 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
if (inputText.empty()) {
if (marketplace_->basketSize() > 0) {
marketplace_->finishCurrentSale();
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
}
return;
}
regex pattern{R"(\d{1,5})"};
smatch result;
if (!regex_match(inputText, result, pattern)) {
return;
}
@ -66,10 +72,7 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
auto dialogResult = priceDialog.exec();
if (dialogResult == QDialog::Accepted) {
int price = priceDialog.getPrice();
auto article = std::make_unique<Article>(price);
article->setSeller(seller);
std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
marketplace_->addArticleToBasket(std::move(article));
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price);
}
}