Browse Source

sorting sellers

allow_new_sellers
Martin Brodbeck 4 years ago
parent
commit
de95d5f341
  1. 5
      src/core/marketplace.cpp
  2. 1
      src/core/marketplace.h
  3. 8
      src/core/seller.cpp
  4. 3
      src/core/seller.h
  5. 1
      src/gui/mainwindow.cpp

5
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());
}

1
src/core/marketplace.h

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

8
src/core/seller.cpp

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

3
src/core/seller.h

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

1
src/gui/mainwindow.cpp

@ -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);

Loading…
Cancel
Save