From 200353058704581223f56d4856a9a14613b614c0 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 27 Jul 2018 09:55:47 +0200 Subject: [PATCH 1/2] replace model correctly --- src/gui/mainwindow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 2631952..8652de4 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -49,7 +49,8 @@ void MainWindow::on_actionEditSeller_triggered() auto dialog = std::make_unique(this); int retCode = dialog->exec(); - delete ui_.salesView->model(); + auto oldModel = ui_.salesView->model(); + ui_.salesView->setModel(nullptr); if (retCode == QDialog::Accepted) { marketplace_->sortSellers(); @@ -63,6 +64,7 @@ void MainWindow::on_actionEditSeller_triggered() } ui_.salesView->setModel(new SaleModel(getMarketplace(), ui_.salesView)); + delete oldModel; ui_.salesView->setColumnHidden(2, true); ui_.salesView->resizeColumnToContents(0); connect(static_cast(ui_.basketView->model()), &BasketModel::basketDataChanged, From fb8bcc71e2901681e635d8a7d7ca823999f5ae29 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 27 Jul 2018 10:10:48 +0200 Subject: [PATCH 2/2] delete model to prevent memory leak --- src/gui/sellerdialog.cpp | 16 +++++++++++++++- src/gui/sellerdialog.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/gui/sellerdialog.cpp b/src/gui/sellerdialog.cpp index 63f2461..110244c 100644 --- a/src/gui/sellerdialog.cpp +++ b/src/gui/sellerdialog.cpp @@ -9,8 +9,9 @@ SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, { ui_.setupUi(this); ui_.editButton->setVisible(false); + market_ = dynamic_cast(parent)->getMarketplace(); SellerModel* model = - new SellerModel(dynamic_cast(parent)->getMarketplace(), ui_.tableView); + new SellerModel(market_, ui_.tableView); ui_.tableView->setModel(model); ui_.tableView->setColumnHidden(0, true); // hide the uuid connect(ui_.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked); @@ -21,6 +22,11 @@ SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, &SellerDialog::onSellerViewSelectionChanged); } +SellerDialog::~SellerDialog() +{ + delete ui_.tableView->model(); +} + void SellerDialog::on_newButton_clicked() { ui_.tableView->reset(); @@ -38,6 +44,14 @@ void SellerDialog::on_deleteButton_clicked() if (selModel->hasSelection() == false) return; + if (market_->getSales().size() > 0) { + QMessageBox(QMessageBox::Icon::Warning, "Hinweis", + "Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) können Sie keine Verkäufer mehr löschen.", + QMessageBox::StandardButton::Ok, this) + .exec(); + return; + } + auto dlgResult = QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?", "Löschen wirkt sich direkt auf die Datenbank aus. Möchten Sie fortfahren?", diff --git a/src/gui/sellerdialog.h b/src/gui/sellerdialog.h index d48556b..dbf6257 100644 --- a/src/gui/sellerdialog.h +++ b/src/gui/sellerdialog.h @@ -14,6 +14,7 @@ class SellerDialog : public QDialog public: SellerDialog(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint); + ~SellerDialog(); private slots: void onSellerViewSelectionChanged(const QItemSelection& selected, @@ -25,6 +26,7 @@ class SellerDialog : public QDialog void on_model_duplicateSellerNo(const QString& message); virtual void accept() override; Ui::SellerDialog ui_; + Marketplace* market_; }; #endif \ No newline at end of file