sorting sellers
This commit is contained in:
parent
f5ba2f6014
commit
de95d5f341
5 changed files with 17 additions and 1 deletions
|
@ -41,4 +41,9 @@ int Marketplace::getNumSellersDelete()
|
||||||
int count = std::count_if(sellers_.begin(), sellers_.end(),
|
int count = std::count_if(sellers_.begin(), sellers_.end(),
|
||||||
[](const auto& a) { return a->getState() == Seller::State::DELETE; });
|
[](const auto& a) { return a->getState() == Seller::State::DELETE; });
|
||||||
return count;
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Marketplace::sortSellers()
|
||||||
|
{
|
||||||
|
std::sort(sellers_.begin(), sellers_.end());
|
||||||
}
|
}
|
|
@ -16,6 +16,7 @@ class Marketplace
|
||||||
std::vector<std::unique_ptr<Seller>>& getSellers();
|
std::vector<std::unique_ptr<Seller>>& getSellers();
|
||||||
int getNextSellerNo();
|
int getNextSellerNo();
|
||||||
int getNumSellersDelete();
|
int getNumSellersDelete();
|
||||||
|
void sortSellers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<Seller>> sellers_;
|
std::vector<std::unique_ptr<Seller>> sellers_;
|
||||||
|
|
|
@ -62,4 +62,10 @@ void Seller::cleanupArticles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// int Seller::numArticlesTotal() const { return static_cast<int>(getArticles().size()); }
|
// int Seller::numArticlesTotal() const { return static_cast<int>(getArticles().size()); }
|
||||||
|
|
||||||
|
bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; }
|
||||||
|
bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re)
|
||||||
|
{
|
||||||
|
return li->sellerNo_ < re->sellerNo_;
|
||||||
|
}
|
|
@ -32,6 +32,9 @@ class Seller : public Entity
|
||||||
// int numArticlesTotal() const;
|
// int numArticlesTotal() const;
|
||||||
std::vector<Article*> getArticles(bool onlySold = true) const;
|
std::vector<Article*> getArticles(bool onlySold = true) const;
|
||||||
|
|
||||||
|
friend bool operator<(const Seller& li, const Seller& re);
|
||||||
|
friend bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int sellerNo_{-1};
|
int sellerNo_{-1};
|
||||||
int numArticlesOffered_{};
|
int numArticlesOffered_{};
|
||||||
|
|
|
@ -22,6 +22,7 @@ void MainWindow::on_actionEditSeller_triggered()
|
||||||
auto dialog = std::make_unique<SellerDialog>(this);
|
auto dialog = std::make_unique<SellerDialog>(this);
|
||||||
int retCode = dialog->exec();
|
int retCode = dialog->exec();
|
||||||
if (retCode == QDialog::Accepted) {
|
if (retCode == QDialog::Accepted) {
|
||||||
|
marketplace_->sortSellers();
|
||||||
marketplace_->storeToDb();
|
marketplace_->storeToDb();
|
||||||
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.",
|
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.",
|
||||||
STATUSBAR_TIMEOUT);
|
STATUSBAR_TIMEOUT);
|
||||||
|
|
Loading…
Reference in a new issue