more on sellerdialog (deleting still not ok)
This commit is contained in:
parent
ffbf27c1f8
commit
4fdaba01d3
4 changed files with 24 additions and 9 deletions
|
@ -14,6 +14,8 @@ SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent,
|
|||
ui_.tableView->setColumnHidden(0, true); // hide the uuid
|
||||
connect(ui_.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked);
|
||||
connect(ui_.deleteButton, &QPushButton::clicked, this, &SellerDialog::on_deleteButton_clicked);
|
||||
connect(model, &SellerModel::duplicateSellerNo, this,
|
||||
&SellerDialog::on_model_duplicateSellerNo);
|
||||
}
|
||||
|
||||
void SellerDialog::on_newButton_clicked()
|
||||
|
@ -42,6 +44,13 @@ void SellerDialog::on_deleteButton_clicked()
|
|||
}
|
||||
}
|
||||
|
||||
void SellerDialog::on_model_duplicateSellerNo(const QString& message)
|
||||
{
|
||||
QMessageBox(QMessageBox::Icon::Warning, "Fehler", message, QMessageBox::StandardButton::Ok,
|
||||
this)
|
||||
.exec();
|
||||
}
|
||||
|
||||
void SellerDialog::accept()
|
||||
{
|
||||
Marketplace* market = dynamic_cast<MainWindow*>(parentWidget())->getMarketplace();
|
||||
|
|
|
@ -18,6 +18,7 @@ class SellerDialog : public QDialog
|
|||
private:
|
||||
void on_newButton_clicked();
|
||||
void on_deleteButton_clicked();
|
||||
void on_model_duplicateSellerNo(const QString& message);
|
||||
virtual void accept() override;
|
||||
Ui::SellerDialog ui_;
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const
|
|||
|
||||
Seller* seller = marketplace_->getSellers().at(index.row()).get();
|
||||
|
||||
/* if (seller->getState() == Seller::State::DELETE)
|
||||
/* if (seller->getState() == Seller::State::DELETE)
|
||||
return QVariant();
|
||||
*/
|
||||
switch (index.column()) {
|
||||
|
@ -93,9 +93,9 @@ bool SellerModel::setData(const QModelIndex& index, const QVariant& value, int r
|
|||
return value.toInt() == seller->getSellerNo();
|
||||
});
|
||||
if (iter != marketplace_->getSellers().end()) {
|
||||
/* QMessageBox(QMessageBox::Icon::Warning, "Fehler",
|
||||
"Die Verkäufernummer muss eindeutig sein.", QMessageBox::StandardButton::Ok)
|
||||
.exec(); */
|
||||
emit duplicateSellerNo(
|
||||
"Die Verkäufernummer muss eindeutig sein.\n(Möglicherweise wird die Nummer von einem "
|
||||
"Eintrag, der zum Löschen vorgemerkt ist, verwendet.)");
|
||||
return false;
|
||||
}
|
||||
seller->setSellerNo(value.toInt());
|
||||
|
@ -133,19 +133,19 @@ bool SellerModel::insertRows(int row, int count, const QModelIndex& parent)
|
|||
|
||||
bool SellerModel::removeRows(int row, int count, const QModelIndex& parent)
|
||||
{
|
||||
emit beginRemoveRows(parent, row, row + count - 1);
|
||||
auto seller = marketplace_->getSellers().at(row).get();
|
||||
if (seller->getState() == Seller::State::NEW) {
|
||||
emit beginRemoveRows(parent, row, row + count - 1);
|
||||
marketplace_->getSellers().erase(
|
||||
std::remove_if(marketplace_->getSellers().begin(), marketplace_->getSellers().end(),
|
||||
[&seller](const std::unique_ptr<Seller>& a) {
|
||||
return a->getUuid() == seller->getUuid();
|
||||
}),
|
||||
marketplace_->getSellers().end());
|
||||
emit endRemoveRows();
|
||||
} else {
|
||||
seller->setState(Seller::State::DELETE);
|
||||
}
|
||||
emit endRemoveRows();
|
||||
|
||||
return false;
|
||||
}
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
class SellerModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SellerModel(Marketplace* market, QObject* parent = nullptr);
|
||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
@ -18,6 +20,9 @@ class SellerModel : public QAbstractTableModel
|
|||
virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||
|
||||
signals:
|
||||
void duplicateSellerNo(const QString& message);
|
||||
|
||||
private:
|
||||
Marketplace* marketplace_;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue