Compare commits

..

3 commits

Author SHA1 Message Date
74ac9f6299 more on selling 2018-07-20 22:10:05 +02:00
0ad460346c Find seller by sellerno 2018-07-20 22:07:42 +02:00
19375a7752 ... 2018-07-20 22:07:10 +02:00
6 changed files with 62 additions and 11 deletions

View file

@ -60,8 +60,12 @@
"typeinfo": "cpp",
"utility": "cpp",
"variant": "cpp",
"algorithm": "cpp"
"algorithm": "cpp",
"cinttypes": "cpp",
"condition_variable": "cpp",
"mutex": "cpp"
},
"C_Cpp.clang_format_path": "/usr/bin/clang-format",
"cmake.configureOnOpen": true
"cmake.configureOnOpen": true,
"C_Cpp.configurationWarnings": "Disabled"
}

View file

@ -42,3 +42,14 @@ int Marketplace::getNumSellersDelete()
}
void Marketplace::sortSellers() { std::sort(sellers_.begin(), sellers_.end()); }
Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
{
auto iter =
std::find_if(sellers_.begin(), sellers_.end(), [sellerNo](const auto& a) {
return a->getSellerNo() == sellerNo;
});
if (iter == sellers_.end())
return nullptr;
return (*iter).get();
}

View file

@ -11,6 +11,7 @@ namespace
{
using SellersVec = std::vector<std::unique_ptr<Seller>>;
using SalesVec = std::vector<std::unique_ptr<Sale>>;
using BasketVec = std::vector<std::unique_ptr<Sale>>;
} // namespace
struct Basket {
@ -26,10 +27,12 @@ class Marketplace
int getNextSellerNo();
int getNumSellersDelete();
void sortSellers();
Seller* findSellerWithSellerNo(int sellerNo);
private:
SellersVec sellers_;
SalesVec sales_;
BasketVec basket_;
};
#endif

View file

@ -2,6 +2,8 @@
#include "sellerdialog.h"
#include <regex>
constexpr int STATUSBAR_TIMEOUT = 5000;
MainWindow::MainWindow()
@ -11,6 +13,8 @@ MainWindow::MainWindow()
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit);
connect(ui_.actionEditSeller, &QAction::triggered, this,
&MainWindow::on_actionEditSeller_triggered);
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
&MainWindow::on_sellerNoEdit_checkSellerNo);
marketplace_ = std::make_unique<Marketplace>();
marketplace_->loadFromDb();
@ -32,3 +36,31 @@ void MainWindow::on_actionEditSeller_triggered()
STATUSBAR_TIMEOUT);
}
}
void MainWindow::on_sellerNoEdit_checkSellerNo()
{
using std::regex, std::regex_match, std::smatch;
auto inputText = ui_.sellerNoEdit->text().toStdString();
if (inputText.empty()) {
return;
}
regex pattern{R"(\d{1,5})"};
smatch result;
if (!regex_match(inputText, result, pattern)) {
return;
}
int sellerNo = std::stoi(result[0]);
auto seller = marketplace_->findSellerWithSellerNo(sellerNo);
if (seller) {
std::cout << "!!! Seller gefunden: " << seller->getFirstName() << "\n";
// TODO: Dialog für Preiseingabe anzeigen
// TODO: Warenkorb füllen
}
ui_.sellerNoEdit->clear();
}

View file

@ -19,6 +19,7 @@ class MainWindow : public QMainWindow
private:
void on_actionEditSeller_triggered();
void on_sellerNoEdit_checkSellerNo();
Ui::MainWindow ui_;
std::unique_ptr<Marketplace> marketplace_;

View file

@ -52,10 +52,10 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLineEdit" name="lineEdit"/>
<widget class="QLineEdit" name="sellerNoEdit"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<widget class="QPushButton" name="paidButton">
<property name="text">
<string>Bezahlt!</string>
</property>