Compare commits
No commits in common. "ee8c059441d2090450efc9d1f3fd9c71f1ec1f7c" and "150ce946d12320619a38064c8d8363d15782e137" have entirely different histories.
ee8c059441
...
150ce946d1
9 changed files with 7 additions and 195 deletions
|
@ -34,16 +34,6 @@ int Marketplace::getNextSellerNo()
|
||||||
return (*iter)->getSellerNo() + 1;
|
return (*iter)->getSellerNo() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Marketplace::getNextArticleNo()
|
|
||||||
{
|
|
||||||
auto iter = std::max_element(
|
|
||||||
sellers_.begin(), sellers_.end(),
|
|
||||||
[](const auto& a, const auto& b) -> bool { return a->getMaxArticleNo() < b->getMaxArticleNo(); });
|
|
||||||
if (iter == sellers_.end())
|
|
||||||
return 1;
|
|
||||||
return (*iter)->getMaxArticleNo() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Marketplace::getNumSellersDelete()
|
int Marketplace::getNumSellersDelete()
|
||||||
{
|
{
|
||||||
int count = std::count_if(sellers_.begin(), sellers_.end(),
|
int count = std::count_if(sellers_.begin(), sellers_.end(),
|
||||||
|
@ -82,10 +72,4 @@ void Marketplace::finishCurrentSale()
|
||||||
}
|
}
|
||||||
|
|
||||||
sales_.push_back(std::move(sale));
|
sales_.push_back(std::move(sale));
|
||||||
basket_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
BasketVec& Marketplace::getBasket()
|
|
||||||
{
|
|
||||||
return basket_;
|
|
||||||
}
|
}
|
|
@ -24,13 +24,9 @@ class Marketplace
|
||||||
|
|
||||||
void storeToDb(bool onlyDelete = false);
|
void storeToDb(bool onlyDelete = false);
|
||||||
void loadFromDb();
|
void loadFromDb();
|
||||||
|
|
||||||
SellersVec& getSellers();
|
SellersVec& getSellers();
|
||||||
int getNextSellerNo();
|
int getNextSellerNo();
|
||||||
int getNextArticleNo();
|
|
||||||
int getNumSellersDelete();
|
int getNumSellersDelete();
|
||||||
BasketVec& getBasket();
|
|
||||||
|
|
||||||
void sortSellers();
|
void sortSellers();
|
||||||
Seller* findSellerWithSellerNo(int sellerNo);
|
Seller* findSellerWithSellerNo(int sellerNo);
|
||||||
void addArticleToBasket(std::unique_ptr<Article> article);
|
void addArticleToBasket(std::unique_ptr<Article> article);
|
||||||
|
|
|
@ -46,15 +46,6 @@ int Seller::numArticlesSold() const { return static_cast<int>(getArticles(true).
|
||||||
|
|
||||||
int Seller::numArticlesOffered() const { return numArticlesOffered_; }
|
int Seller::numArticlesOffered() const { return numArticlesOffered_; }
|
||||||
|
|
||||||
int Seller::getMaxArticleNo() const{
|
|
||||||
auto iter = std::max_element(
|
|
||||||
articles_.begin(), articles_.end(),
|
|
||||||
[](const auto& a, const auto& b) -> bool { return a->getArticleNo() < b->getArticleNo(); });
|
|
||||||
if (iter == articles_.end())
|
|
||||||
return 0;
|
|
||||||
return (*iter)->getArticleNo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Seller::cleanupArticles()
|
void Seller::cleanupArticles()
|
||||||
{
|
{
|
||||||
articles_.erase(std::remove_if(articles_.begin(), articles_.end(),
|
articles_.erase(std::remove_if(articles_.begin(), articles_.end(),
|
||||||
|
|
|
@ -32,7 +32,6 @@ class Seller : public Entity
|
||||||
int numArticlesSold() const;
|
int numArticlesSold() const;
|
||||||
// int numArticlesTotal() const;
|
// int numArticlesTotal() const;
|
||||||
std::vector<Article*> getArticles(bool onlySold = true) const;
|
std::vector<Article*> getArticles(bool onlySold = true) const;
|
||||||
int getMaxArticleNo() const;
|
|
||||||
|
|
||||||
friend bool operator<(const Seller& li, const Seller& re);
|
friend bool operator<(const Seller& li, const Seller& re);
|
||||||
friend bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re);
|
friend bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re);
|
||||||
|
|
|
@ -17,7 +17,6 @@ set(GUI_SOURCES
|
||||||
sellermodel.cpp
|
sellermodel.cpp
|
||||||
pricedialog.cpp
|
pricedialog.cpp
|
||||||
pricedialog.ui
|
pricedialog.ui
|
||||||
basketmodel.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(kima2 ${GUI_SOURCES})
|
add_executable(kima2 ${GUI_SOURCES})
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
#include "basketmodel.h"
|
|
||||||
|
|
||||||
BasketModel::BasketModel(Marketplace* market, QObject* parent)
|
|
||||||
: QAbstractTableModel(parent), marketplace_(market)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int BasketModel::rowCount([[maybe_unused]] const QModelIndex& parent) const
|
|
||||||
{
|
|
||||||
return static_cast<int>(marketplace_->basketSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
int BasketModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 4; }
|
|
||||||
|
|
||||||
QVariant BasketModel::data(const QModelIndex& index, int role) const
|
|
||||||
{
|
|
||||||
if (role != Qt::DisplayRole)
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
if (marketplace_->basketSize() == 0)
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
Article* article = marketplace_->getBasket().at(index.row()).get();
|
|
||||||
|
|
||||||
switch (index.column()) {
|
|
||||||
case 0:
|
|
||||||
return article->getUuidAsString().c_str();
|
|
||||||
case 1:
|
|
||||||
return article->getArticleNo();
|
|
||||||
case 2:
|
|
||||||
return article->getSeller()->getSellerNo();
|
|
||||||
case 3:
|
|
||||||
return article->getPrice();
|
|
||||||
default:
|
|
||||||
return "???";
|
|
||||||
}
|
|
||||||
return QVariant{};
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant BasketModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
|
||||||
if (role != Qt::DisplayRole)
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
if (orientation == Qt::Horizontal) {
|
|
||||||
switch (section) {
|
|
||||||
case 0:
|
|
||||||
return "ID";
|
|
||||||
case 1:
|
|
||||||
return "Art.Nr.";
|
|
||||||
case 2:
|
|
||||||
return "Verk.Nr.";
|
|
||||||
case 3:
|
|
||||||
return "Preis";
|
|
||||||
default:
|
|
||||||
return "???";
|
|
||||||
}
|
|
||||||
return QStringLiteral("%1").arg(section);
|
|
||||||
} else
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* bool BasketModel::insertRows(int row, int count, const QModelIndex& parent)
|
|
||||||
{
|
|
||||||
//emit beginInsertRows(parent, row, row + count - 1);
|
|
||||||
//auto article = std::make_unique<Article>();
|
|
||||||
//article->createUuid();
|
|
||||||
//article->setArticleNo(marketplace_->getNextArticleNo());
|
|
||||||
//marketplace_->addArticleToBasket(std::move(article));
|
|
||||||
//emit endInsertRows();
|
|
||||||
|
|
||||||
emit layoutChanged();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} */
|
|
||||||
|
|
||||||
void BasketModel::addArticle(Seller* seller, int price)
|
|
||||||
{
|
|
||||||
emit beginInsertRows(QModelIndex(), marketplace_->getBasket().size(), marketplace_->getBasket().size());
|
|
||||||
auto article = std::make_unique<Article>(price);
|
|
||||||
article->createUuid();
|
|
||||||
article->setArticleNo(marketplace_->getNextArticleNo() + marketplace_->getBasket().size());
|
|
||||||
article->setSeller(seller);
|
|
||||||
std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
|
|
||||||
marketplace_->addArticleToBasket(std::move(article));
|
|
||||||
emit endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BasketModel::finishSale()
|
|
||||||
{
|
|
||||||
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size()-1);
|
|
||||||
marketplace_->finishCurrentSale();
|
|
||||||
emit endRemoveRows();
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
#ifndef BASKET_MODEL_H
|
|
||||||
#define BASKET_MODEL_H
|
|
||||||
|
|
||||||
#include <marketplace.h>
|
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
|
||||||
|
|
||||||
class BasketModel : public QAbstractTableModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit BasketModel(Marketplace* market, QObject* parent = nullptr);
|
|
||||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
||||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
||||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
|
||||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
|
||||||
//virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
|
||||||
//virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
|
|
||||||
//virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
|
||||||
void addArticle(Seller* seller, int price);
|
|
||||||
void finishSale();
|
|
||||||
//virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Marketplace* marketplace_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include "basketmodel.h"
|
|
||||||
#include "pricedialog.h"
|
#include "pricedialog.h"
|
||||||
#include "sellerdialog.h"
|
#include "sellerdialog.h"
|
||||||
|
|
||||||
|
@ -21,11 +20,6 @@ MainWindow::MainWindow()
|
||||||
marketplace_ = std::make_unique<Marketplace>();
|
marketplace_ = std::make_unique<Marketplace>();
|
||||||
marketplace_->loadFromDb();
|
marketplace_->loadFromDb();
|
||||||
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
|
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()
|
void MainWindow::on_actionEditSeller_triggered()
|
||||||
|
@ -52,7 +46,7 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
|
||||||
|
|
||||||
if (inputText.empty()) {
|
if (inputText.empty()) {
|
||||||
if (marketplace_->basketSize() > 0) {
|
if (marketplace_->basketSize() > 0) {
|
||||||
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
|
marketplace_->finishCurrentSale();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +66,10 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
|
||||||
auto dialogResult = priceDialog.exec();
|
auto dialogResult = priceDialog.exec();
|
||||||
if (dialogResult == QDialog::Accepted) {
|
if (dialogResult == QDialog::Accepted) {
|
||||||
int price = priceDialog.getPrice();
|
int price = priceDialog.getPrice();
|
||||||
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price);
|
auto article = std::make_unique<Article>(price);
|
||||||
|
article->setSeller(seller);
|
||||||
|
std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
|
||||||
|
marketplace_->addArticleToBasket(std::move(article));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,34 +170,12 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="basketView">
|
<widget class="QTableView" name="tableView"/>
|
||||||
<property name="selectionMode">
|
|
||||||
<enum>QAbstractItemView::SingleSelection</enum>
|
|
||||||
</property>
|
|
||||||
<property name="selectionBehavior">
|
|
||||||
<enum>QAbstractItemView::SelectRows</enum>
|
|
||||||
</property>
|
|
||||||
<property name="showGrid">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
|
||||||
<number>75</number>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="horizontalHeaderStretchLastSection">
|
|
||||||
<bool>true</bool>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="verticalHeaderStretchLastSection">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_5">
|
<widget class="QPushButton" name="pushButton_5">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Stornieren</string>
|
<string>Stornieren</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -205,9 +183,6 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_4">
|
<widget class="QPushButton" name="pushButton_4">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Alles stornieren</string>
|
<string>Alles stornieren</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -260,9 +235,6 @@
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="pushButton">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Nachträglich
|
<string>Nachträglich
|
||||||
stornieren</string>
|
stornieren</string>
|
||||||
|
@ -271,9 +243,6 @@ stornieren</string>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_2">
|
<widget class="QPushButton" name="pushButton_2">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Quittung
|
<string>Quittung
|
||||||
drucken</string>
|
drucken</string>
|
||||||
|
|
Loading…
Reference in a new issue