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

View File

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