more on sellerdialog (deleting still not ok)

This commit is contained in:
Martin Brodbeck 2018-07-17 16:37:16 +02:00
parent ffbf27c1f8
commit 4fdaba01d3
4 changed files with 24 additions and 9 deletions

View file

@ -14,6 +14,8 @@ SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent,
ui_.tableView->setColumnHidden(0, true); // hide the uuid ui_.tableView->setColumnHidden(0, true); // hide the uuid
connect(ui_.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked); connect(ui_.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked);
connect(ui_.deleteButton, &QPushButton::clicked, this, &SellerDialog::on_deleteButton_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() void SellerDialog::on_newButton_clicked()
@ -33,7 +35,7 @@ void SellerDialog::on_deleteButton_clicked()
if (selModel->hasSelection() == false) if (selModel->hasSelection() == false)
return; return;
auto indexes = selModel->selectedRows(); auto indexes = selModel->selectedRows();
std::sort(indexes.begin(), indexes.end()); std::sort(indexes.begin(), indexes.end());
// Deleting the rows, beginning with the last one! // Deleting the rows, beginning with the last one!
@ -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() void SellerDialog::accept()
{ {
Marketplace* market = dynamic_cast<MainWindow*>(parentWidget())->getMarketplace(); Marketplace* market = dynamic_cast<MainWindow*>(parentWidget())->getMarketplace();

View file

@ -18,6 +18,7 @@ class SellerDialog : public QDialog
private: private:
void on_newButton_clicked(); void on_newButton_clicked();
void on_deleteButton_clicked(); void on_deleteButton_clicked();
void on_model_duplicateSellerNo(const QString& message);
virtual void accept() override; virtual void accept() override;
Ui::SellerDialog ui_; Ui::SellerDialog ui_;
}; };

View file

@ -23,9 +23,9 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const
Seller* seller = marketplace_->getSellers().at(index.row()).get(); Seller* seller = marketplace_->getSellers().at(index.row()).get();
/* if (seller->getState() == Seller::State::DELETE) /* if (seller->getState() == Seller::State::DELETE)
return QVariant(); return QVariant();
*/ */
switch (index.column()) { switch (index.column()) {
case 0: case 0:
return seller->getUuidAsString().c_str(); return seller->getUuidAsString().c_str();
@ -93,9 +93,9 @@ bool SellerModel::setData(const QModelIndex& index, const QVariant& value, int r
return value.toInt() == seller->getSellerNo(); return value.toInt() == seller->getSellerNo();
}); });
if (iter != marketplace_->getSellers().end()) { if (iter != marketplace_->getSellers().end()) {
/* QMessageBox(QMessageBox::Icon::Warning, "Fehler", emit duplicateSellerNo(
"Die Verkäufernummer muss eindeutig sein.", QMessageBox::StandardButton::Ok) "Die Verkäufernummer muss eindeutig sein.\n(Möglicherweise wird die Nummer von einem "
.exec(); */ "Eintrag, der zum Löschen vorgemerkt ist, verwendet.)");
return false; return false;
} }
seller->setSellerNo(value.toInt()); 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) bool SellerModel::removeRows(int row, int count, const QModelIndex& parent)
{ {
emit beginRemoveRows(parent, row, row + count - 1);
auto seller = marketplace_->getSellers().at(row).get(); auto seller = marketplace_->getSellers().at(row).get();
if (seller->getState() == Seller::State::NEW) { if (seller->getState() == Seller::State::NEW) {
emit beginRemoveRows(parent, row, row + count - 1);
marketplace_->getSellers().erase( marketplace_->getSellers().erase(
std::remove_if(marketplace_->getSellers().begin(), marketplace_->getSellers().end(), std::remove_if(marketplace_->getSellers().begin(), marketplace_->getSellers().end(),
[&seller](const std::unique_ptr<Seller>& a) { [&seller](const std::unique_ptr<Seller>& a) {
return a->getUuid() == seller->getUuid(); return a->getUuid() == seller->getUuid();
}), }),
marketplace_->getSellers().end()); marketplace_->getSellers().end());
emit endRemoveRows();
} else { } else {
seller->setState(Seller::State::DELETE); seller->setState(Seller::State::DELETE);
} }
emit endRemoveRows();
return false; return false;
} }

View file

@ -7,6 +7,8 @@
class SellerModel : public QAbstractTableModel class SellerModel : public QAbstractTableModel
{ {
Q_OBJECT
public: public:
explicit SellerModel(Marketplace* market, QObject* parent = nullptr); explicit SellerModel(Marketplace* market, QObject* parent = nullptr);
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; 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 insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
virtual bool removeRows(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: private:
Marketplace* marketplace_; Marketplace* marketplace_;
}; };