cancel article / complete sale
This commit is contained in:
parent
3c318ffab9
commit
527241a0f3
7 changed files with 92 additions and 13 deletions
|
@ -76,19 +76,40 @@ QVariant BasketModel::headerData(int section, Qt::Orientation orientation, int r
|
|||
|
||||
void BasketModel::addArticle(Seller* seller, int price)
|
||||
{
|
||||
emit beginInsertRows(QModelIndex(), marketplace_->getBasket().size(), marketplace_->getBasket().size());
|
||||
emit beginInsertRows(QModelIndex(), marketplace_->getBasket().size(),
|
||||
marketplace_->getBasket().size());
|
||||
auto article = std::make_unique<Article>(price);
|
||||
article->createUuid();
|
||||
article->setArticleNo(marketplace_->getNextArticleNo() + marketplace_->getBasket().size());
|
||||
article->setArticleNo(marketplace_->getNextArticleNo());
|
||||
article->setSeller(seller);
|
||||
std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
|
||||
// std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n";
|
||||
marketplace_->addArticleToBasket(std::move(article));
|
||||
emit endInsertRows();
|
||||
}
|
||||
|
||||
void BasketModel::finishSale()
|
||||
{
|
||||
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size()-1);
|
||||
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1);
|
||||
marketplace_->finishCurrentSale();
|
||||
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue