use unique_ptr for model

This commit is contained in:
Martin Brodbeck 2018-07-27 10:34:27 +02:00
parent fcf5f04539
commit a130fa33c2
2 changed files with 6 additions and 10 deletions

View file

@ -10,23 +10,17 @@ SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent,
ui_.setupUi(this); ui_.setupUi(this);
ui_.editButton->setVisible(false); ui_.editButton->setVisible(false);
market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace(); market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace();
SellerModel* model = model_ = std::make_unique<SellerModel>(market_, ui_.tableView);
new SellerModel(market_, ui_.tableView); ui_.tableView->setModel(model_.get());
ui_.tableView->setModel(model);
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, connect(model_.get(), &SellerModel::duplicateSellerNo, this,
&SellerDialog::on_model_duplicateSellerNo); &SellerDialog::on_model_duplicateSellerNo);
connect(ui_.tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(ui_.tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&SellerDialog::onSellerViewSelectionChanged); &SellerDialog::onSellerViewSelectionChanged);
} }
SellerDialog::~SellerDialog()
{
delete ui_.tableView->model();
}
void SellerDialog::on_newButton_clicked() void SellerDialog::on_newButton_clicked()
{ {
ui_.tableView->reset(); ui_.tableView->reset();

View file

@ -5,6 +5,8 @@
#include "sellermodel.h" #include "sellermodel.h"
#include <memory>
#include <QDialog> #include <QDialog>
class SellerDialog : public QDialog class SellerDialog : public QDialog
@ -14,7 +16,6 @@ class SellerDialog : public QDialog
public: public:
SellerDialog(QWidget* parent = nullptr, SellerDialog(QWidget* parent = nullptr,
Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint); Qt::WindowFlags f = Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
~SellerDialog();
private slots: private slots:
void onSellerViewSelectionChanged(const QItemSelection& selected, void onSellerViewSelectionChanged(const QItemSelection& selected,
@ -27,6 +28,7 @@ class SellerDialog : public QDialog
virtual void accept() override; virtual void accept() override;
Ui::SellerDialog ui_; Ui::SellerDialog ui_;
Marketplace* market_; Marketplace* market_;
std::unique_ptr<SellerModel> model_;
}; };
#endif #endif