remove article (incomplete)
This commit is contained in:
parent
99bc19f7a3
commit
9ab8ca7a4b
3 changed files with 30 additions and 7 deletions
|
@ -184,7 +184,7 @@ void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
|
|||
|
||||
// Deleting the rows, beginning with the last one!
|
||||
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
|
||||
ui_.salesView->model()->removeRow(iter->row());
|
||||
ui_.salesView->model()->removeRow(iter->row(), iter->parent());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -166,3 +166,25 @@ void SaleModel::onBasketDataChanged()
|
|||
});
|
||||
emit endResetModel();
|
||||
}
|
||||
|
||||
bool SaleModel::removeRows(int row, int count, const QModelIndex& parent)
|
||||
{
|
||||
if (!parent.isValid()) {
|
||||
// remove complete sale
|
||||
|
||||
} else if (!parent.parent().isValid()) {
|
||||
// remove one article from a sale
|
||||
auto sale = static_cast<Sale*>(parent.internalPointer());
|
||||
auto articles = sale->getArticles();
|
||||
emit beginRemoveRows(parent, row, row + count -1);
|
||||
articles.at(row)->setState(Article::State::DELETE);
|
||||
sale->removeArticle(articles.at(row));
|
||||
marketplace_->storeToDb();
|
||||
if (articles.size() == 0) {
|
||||
std::cout << "No articles left.\n";
|
||||
}
|
||||
emit endRemoveRows();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -11,13 +11,14 @@ class SaleModel : public QAbstractItemModel
|
|||
|
||||
public:
|
||||
explicit SaleModel(Marketplace* market, QObject* parent = nullptr);
|
||||
QModelIndex index(int row, int column,
|
||||
virtual QModelIndex index(int row, int column,
|
||||
const QModelIndex& parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex& index) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
int rowCount(const QModelIndex& parent) const override;
|
||||
int columnCount(const QModelIndex& parent) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
virtual QModelIndex parent(const QModelIndex& index) const override;
|
||||
virtual QVariant data(const QModelIndex& index, int role) const override;
|
||||
virtual int rowCount(const QModelIndex& parent) const override;
|
||||
virtual int columnCount(const QModelIndex& parent) const override;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||
|
||||
public slots:
|
||||
void onBasketDataChanged();
|
||||
|
|
Loading…
Reference in a new issue