diff --git a/src/core/marketplace.cpp b/src/core/marketplace.cpp index 14243f1..76efc43 100644 --- a/src/core/marketplace.cpp +++ b/src/core/marketplace.cpp @@ -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()); } \ No newline at end of file diff --git a/src/core/marketplace.h b/src/core/marketplace.h index 580e12c..2eb6492 100644 --- a/src/core/marketplace.h +++ b/src/core/marketplace.h @@ -16,6 +16,7 @@ class Marketplace std::vector>& getSellers(); int getNextSellerNo(); int getNumSellersDelete(); + void sortSellers(); private: std::vector> sellers_; diff --git a/src/core/seller.cpp b/src/core/seller.cpp index def265e..3951b93 100644 --- a/src/core/seller.cpp +++ b/src/core/seller.cpp @@ -62,4 +62,10 @@ void Seller::cleanupArticles() } } -// int Seller::numArticlesTotal() const { return static_cast(getArticles().size()); } \ No newline at end of file +// int Seller::numArticlesTotal() const { return static_cast(getArticles().size()); } + +bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; } +bool operator<(const std::unique_ptr& li, const std::unique_ptr& re) +{ + return li->sellerNo_ < re->sellerNo_; +} \ No newline at end of file diff --git a/src/core/seller.h b/src/core/seller.h index e334fb2..dd5e7d2 100644 --- a/src/core/seller.h +++ b/src/core/seller.h @@ -32,6 +32,9 @@ class Seller : public Entity // int numArticlesTotal() const; std::vector getArticles(bool onlySold = true) const; + friend bool operator<(const Seller& li, const Seller& re); + friend bool operator<(const std::unique_ptr& li, const std::unique_ptr& re); + private: int sellerNo_{-1}; int numArticlesOffered_{}; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 0839e78..a0ad153 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -22,6 +22,7 @@ void MainWindow::on_actionEditSeller_triggered() auto dialog = std::make_unique(this); int retCode = dialog->exec(); if (retCode == QDialog::Accepted) { + marketplace_->sortSellers(); marketplace_->storeToDb(); statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.", STATUSBAR_TIMEOUT);