Compare commits
No commits in common. "527241a0f355e43826e0a76d77ad5d0f50068668" and "42c5f35576f2fd741390d4006ced09842ad522f9" have entirely different histories.
527241a0f3
...
42c5f35576
7 changed files with 14 additions and 93 deletions
|
@ -36,25 +36,13 @@ int Marketplace::getNextSellerNo()
|
||||||
|
|
||||||
int Marketplace::getNextArticleNo()
|
int Marketplace::getNextArticleNo()
|
||||||
{
|
{
|
||||||
int maxArtNoInDb{0};
|
|
||||||
int maxArtNoInBasket{0};
|
|
||||||
|
|
||||||
auto iter = std::max_element(sellers_.begin(), sellers_.end(),
|
auto iter = std::max_element(sellers_.begin(), sellers_.end(),
|
||||||
[](const auto& a, const auto& b) -> bool {
|
[](const auto& a, const auto& b) -> bool {
|
||||||
return a->getMaxArticleNo() < b->getMaxArticleNo();
|
return a->getMaxArticleNo() < b->getMaxArticleNo();
|
||||||
});
|
});
|
||||||
if (iter != sellers_.end())
|
if (iter == sellers_.end())
|
||||||
maxArtNoInDb = (*iter)->getMaxArticleNo();
|
return 1;
|
||||||
|
return (*iter)->getMaxArticleNo() + 1;
|
||||||
auto iter2 =
|
|
||||||
std::max_element(basket_.begin(), basket_.end(), [](const auto& a, const auto& b) -> bool {
|
|
||||||
return a->getArticleNo() < b->getArticleNo();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (iter2 != basket_.end())
|
|
||||||
maxArtNoInBasket = (*iter2)->getArticleNo();
|
|
||||||
|
|
||||||
return maxArtNoInBasket > maxArtNoInDb ? maxArtNoInBasket + 1 : maxArtNoInDb + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Marketplace::getNumSellersDelete()
|
int Marketplace::getNumSellersDelete()
|
||||||
|
|
|
@ -76,40 +76,19 @@ QVariant BasketModel::headerData(int section, Qt::Orientation orientation, int r
|
||||||
|
|
||||||
void BasketModel::addArticle(Seller* seller, int price)
|
void BasketModel::addArticle(Seller* seller, int price)
|
||||||
{
|
{
|
||||||
emit beginInsertRows(QModelIndex(), marketplace_->getBasket().size(),
|
emit beginInsertRows(QModelIndex(), marketplace_->getBasket().size(), marketplace_->getBasket().size());
|
||||||
marketplace_->getBasket().size());
|
|
||||||
auto article = std::make_unique<Article>(price);
|
auto article = std::make_unique<Article>(price);
|
||||||
article->createUuid();
|
article->createUuid();
|
||||||
article->setArticleNo(marketplace_->getNextArticleNo());
|
article->setArticleNo(marketplace_->getNextArticleNo() + marketplace_->getBasket().size());
|
||||||
article->setSeller(seller);
|
article->setSeller(seller);
|
||||||
// std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
|
std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
|
||||||
marketplace_->addArticleToBasket(std::move(article));
|
marketplace_->addArticleToBasket(std::move(article));
|
||||||
emit endInsertRows();
|
emit endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasketModel::finishSale()
|
void BasketModel::finishSale()
|
||||||
{
|
{
|
||||||
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1);
|
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size()-1);
|
||||||
marketplace_->finishCurrentSale();
|
marketplace_->finishCurrentSale();
|
||||||
emit endRemoveRows();
|
emit endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasketModel::cancelSale()
|
|
||||||
{
|
|
||||||
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1);
|
|
||||||
marketplace_->getBasket().clear();
|
|
||||||
emit endRemoveRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BasketModel::removeRows(int row, int count, const QModelIndex& parent)
|
|
||||||
{
|
|
||||||
auto article = marketplace_->getBasket().at(row).get();
|
|
||||||
|
|
||||||
emit beginRemoveRows(parent, row, row + count - 1);
|
|
||||||
marketplace_->getBasket().erase(
|
|
||||||
std::remove_if(marketplace_->getBasket().begin(), marketplace_->getBasket().end(),
|
|
||||||
[&article](const auto& a) { return a->getUuid() == article->getUuid(); }),
|
|
||||||
marketplace_->getBasket().end());
|
|
||||||
emit endRemoveRows();
|
|
||||||
return true;
|
|
||||||
}
|
|
|
@ -20,8 +20,7 @@ class BasketModel : public QAbstractTableModel
|
||||||
//virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
//virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||||
void addArticle(Seller* seller, int price);
|
void addArticle(Seller* seller, int price);
|
||||||
void finishSale();
|
void finishSale();
|
||||||
void cancelSale();
|
//virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||||
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Marketplace* marketplace_;
|
Marketplace* marketplace_;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QItemSelectionModel>
|
||||||
|
|
||||||
constexpr int STATUSBAR_TIMEOUT = 5000;
|
constexpr int STATUSBAR_TIMEOUT = 5000;
|
||||||
|
|
||||||
|
@ -28,12 +28,9 @@ MainWindow::MainWindow()
|
||||||
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
|
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
|
||||||
&MainWindow::on_sellerNoEdit_checkSellerNo);
|
&MainWindow::on_sellerNoEdit_checkSellerNo);
|
||||||
connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::on_paidButton_triggered);
|
connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::on_paidButton_triggered);
|
||||||
|
|
||||||
connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||||
&MainWindow::onBasketViewSelectionChanged);
|
&MainWindow::onBasketViewSelectionChanged);
|
||||||
connect(ui_.cancelArticleButton, &QPushButton::clicked, this,
|
|
||||||
&MainWindow::onCancelArticleButtonClicked);
|
|
||||||
connect(ui_.cancelAllArticlesButton, &QPushButton::clicked, this,
|
|
||||||
&MainWindow::onCancelAllArticlesButtonClicked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionEditSeller_triggered()
|
void MainWindow::on_actionEditSeller_triggered()
|
||||||
|
@ -57,6 +54,7 @@ void MainWindow::on_paidButton_triggered()
|
||||||
if (marketplace_->basketSize() > 0) {
|
if (marketplace_->basketSize() > 0) {
|
||||||
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_sellerNoEdit_checkSellerNo()
|
void MainWindow::on_sellerNoEdit_checkSellerNo()
|
||||||
|
@ -95,7 +93,7 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
|
void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
|
||||||
[[maybe_unused]] const QItemSelection& deselected)
|
[[maybe_unused]] const QItemSelection& deselected)
|
||||||
{
|
{
|
||||||
if (selected.size() > 0) {
|
if (selected.size() > 0) {
|
||||||
ui_.cancelArticleButton->setEnabled(true);
|
ui_.cancelArticleButton->setEnabled(true);
|
||||||
|
@ -103,42 +101,3 @@ void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
|
||||||
ui_.cancelArticleButton->setEnabled(false);
|
ui_.cancelArticleButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
|
|
||||||
{
|
|
||||||
auto selModel = ui_.basketView->selectionModel();
|
|
||||||
if (selModel->hasSelection() == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto dlgResult =
|
|
||||||
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
|
|
||||||
"Möchten Sie wirklich den Artikel stornieren?",
|
|
||||||
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
|
|
||||||
.exec();
|
|
||||||
if (dlgResult == QMessageBox::No)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto indexes = selModel->selectedRows();
|
|
||||||
std::sort(indexes.begin(), indexes.end());
|
|
||||||
|
|
||||||
// Deleting the rows, beginning with the last one!
|
|
||||||
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
|
|
||||||
ui_.basketView->model()->removeRow(iter->row());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
|
|
||||||
{
|
|
||||||
if (ui_.basketView->model()->rowCount() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto dlgResult =
|
|
||||||
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
|
|
||||||
"Möchten Sie wirklich *alle* Artikel des aktuellen Einkaufs stornieren?",
|
|
||||||
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
|
|
||||||
.exec();
|
|
||||||
if (dlgResult == QMessageBox::No)
|
|
||||||
return;
|
|
||||||
|
|
||||||
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale();
|
|
||||||
}
|
|
|
@ -19,9 +19,7 @@ class MainWindow : public QMainWindow
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onBasketViewSelectionChanged(const QItemSelection& selected,
|
void onBasketViewSelectionChanged(const QItemSelection& selected,
|
||||||
const QItemSelection& deselected);
|
const QItemSelection& deselected);
|
||||||
void onCancelArticleButtonClicked(bool checked);
|
|
||||||
void onCancelAllArticlesButtonClicked(bool checked);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void on_actionEditSeller_triggered();
|
void on_actionEditSeller_triggered();
|
||||||
|
|
|
@ -204,7 +204,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="cancelAllArticlesButton">
|
<widget class="QPushButton" name="cancleAllArticlesButton">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -146,13 +146,11 @@ bool SellerModel::removeRows(int row, int count, const QModelIndex& parent)
|
||||||
}),
|
}),
|
||||||
marketplace_->getSellers().end());
|
marketplace_->getSellers().end());
|
||||||
emit endRemoveRows();
|
emit endRemoveRows();
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
emit beginRemoveRows(parent, row, row + count - 1);
|
emit beginRemoveRows(parent, row, row + count - 1);
|
||||||
seller->setState(Seller::State::DELETE);
|
seller->setState(Seller::State::DELETE);
|
||||||
marketplace_->storeToDb(true);
|
marketplace_->storeToDb(true);
|
||||||
emit endRemoveRows();
|
emit endRemoveRows();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue