fill basket

This commit is contained in:
Martin Brodbeck 2018-07-21 19:24:56 +02:00
parent f315cc81a6
commit 8b534e1229
9 changed files with 62 additions and 18 deletions

View file

@ -1,6 +1,8 @@
#include "article.h" #include "article.h"
//Article::Article() : Entity() {} // Article::Article() : Entity() {}
Article::Article(int price) : price_(price) {}
// Article::Article(std::shared_ptr<Seller> sellerPtr) : Entity() { sellerPtr_ = sellerPtr; } // Article::Article(std::shared_ptr<Seller> sellerPtr) : Entity() { sellerPtr_ = sellerPtr; }

View file

@ -15,6 +15,7 @@ class Article : public Entity
{ {
public: public:
Article() = default; Article() = default;
Article(int price);
//virtual ~Article() = default; //virtual ~Article() = default;
void setArticleNo(int articleNo); void setArticleNo(int articleNo);

View file

@ -52,4 +52,9 @@ Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
if (iter == sellers_.end()) if (iter == sellers_.end())
return nullptr; return nullptr;
return (*iter).get(); return (*iter).get();
}
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
{
basket_.push_back(std::move(article));
} }

View file

@ -11,7 +11,7 @@ namespace
{ {
using SellersVec = std::vector<std::unique_ptr<Seller>>; using SellersVec = std::vector<std::unique_ptr<Seller>>;
using SalesVec = std::vector<std::unique_ptr<Sale>>; using SalesVec = std::vector<std::unique_ptr<Sale>>;
using BasketVec = std::vector<std::unique_ptr<Sale>>; using BasketVec = std::vector<std::unique_ptr<Article>>;
} // namespace } // namespace
struct Basket { struct Basket {
@ -28,6 +28,7 @@ class Marketplace
int getNumSellersDelete(); int getNumSellersDelete();
void sortSellers(); void sortSellers();
Seller* findSellerWithSellerNo(int sellerNo); Seller* findSellerWithSellerNo(int sellerNo);
void addArticleToBasket(std::unique_ptr<Article> article);
private: private:
SellersVec sellers_; SellersVec sellers_;

View file

@ -11,10 +11,9 @@ find_package(Qt5Widgets CONFIG REQUIRED)
set(GUI_SOURCES set(GUI_SOURCES
kima2.cpp kima2.cpp
mainwindow.cpp mainwindow.cpp
mainwindow.ui
sellerdialog.cpp sellerdialog.cpp
sellerdialog.ui
sellermodel.cpp sellermodel.cpp
pricedialog.cpp
) )
add_executable(kima2 ${GUI_SOURCES}) add_executable(kima2 ${GUI_SOURCES})

View file

@ -1,6 +1,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "sellerdialog.h" #include "sellerdialog.h"
#include "pricedialog.h"
#include <regex> #include <regex>
@ -58,8 +59,16 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
auto seller = marketplace_->findSellerWithSellerNo(sellerNo); auto seller = marketplace_->findSellerWithSellerNo(sellerNo);
if (seller) { if (seller) {
std::cout << "!!! Seller gefunden: " << seller->getFirstName() << "\n"; std::cout << "!!! Seller gefunden: " << seller->getFirstName() << "\n";
// TODO: Dialog für Preiseingabe anzeigen PriceDialog priceDialog(this);
// TODO: Warenkorb füllen 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));
}
} }
ui_.sellerNoEdit->clear(); ui_.sellerNoEdit->clear();

12
src/gui/pricedialog.cpp Normal file
View file

@ -0,0 +1,12 @@
#include "pricedialog.h"
PriceDialog::PriceDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
{
ui_.setupUi(this);
ui_.priceSpinBox->setFocus();
}
int PriceDialog::getPrice() const
{
return static_cast<int>(ui_.priceSpinBox->value() * 100);
}

23
src/gui/pricedialog.h Normal file
View file

@ -0,0 +1,23 @@
#ifndef PRICE_DIALOG_H
#define PRICE_DIALOG_H
#include "ui_pricedialog.h"
#include <QDialog>
class PriceDialog : public QDialog
{
Q_OBJECT
public:
PriceDialog(QWidget* parent = nullptr,
Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
int getPrice() const;
private:
void on_model_duplicateSellerNo(const QString& message);
//virtual void accept() override;
Ui::PriceDialog ui_;
};
#endif

View file

@ -1,15 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>priceDialog</class> <class>PriceDialog</class>
<widget class="QDialog" name="priceDialog"> <widget class="QDialog" name="PriceDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>311</width>
<height>114</height>
</rect>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Artikelpreis</string> <string>Artikelpreis</string>
</property> </property>
@ -65,7 +57,7 @@
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>
<signal>accepted()</signal> <signal>accepted()</signal>
<receiver>priceDialog</receiver> <receiver>PriceDialog</receiver>
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
@ -81,7 +73,7 @@
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>
<signal>rejected()</signal> <signal>rejected()</signal>
<receiver>priceDialog</receiver> <receiver>PriceDialog</receiver>
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">