sorting sellers

This commit is contained in:
Martin Brodbeck 2018-07-18 09:00:46 +02:00
parent f5ba2f6014
commit de95d5f341
5 changed files with 17 additions and 1 deletions

View file

@ -41,4 +41,9 @@ int Marketplace::getNumSellersDelete()
int count = std::count_if(sellers_.begin(), sellers_.end(),
[](const auto& a) { return a->getState() == Seller::State::DELETE; });
return count;
}
void Marketplace::sortSellers()
{
std::sort(sellers_.begin(), sellers_.end());
}

View file

@ -16,6 +16,7 @@ class Marketplace
std::vector<std::unique_ptr<Seller>>& getSellers();
int getNextSellerNo();
int getNumSellersDelete();
void sortSellers();
private:
std::vector<std::unique_ptr<Seller>> sellers_;

View file

@ -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_;
}

View file

@ -32,6 +32,9 @@ class Seller : public Entity
// int numArticlesTotal() 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:
int sellerNo_{-1};
int numArticlesOffered_{};

View file

@ -22,6 +22,7 @@ void MainWindow::on_actionEditSeller_triggered()
auto dialog = std::make_unique<SellerDialog>(this);
int retCode = dialog->exec();
if (retCode == QDialog::Accepted) {
marketplace_->sortSellers();
marketplace_->storeToDb();
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.",
STATUSBAR_TIMEOUT);