diff options
author | Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> | 2014-11-11 11:17:04 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> | 2014-11-11 11:31:38 +0200 |
commit | c6ed50e68438e5558e7cda0e36c194a4b99f7f83 (patch) | |
tree | 8cbb330dc82eae3cb11b2202ba0f34bc6e6988bf /examples | |
parent | a686cb49be8689c5e306e895062f47c37a4f908d (diff) |
Plugged some memory leaks.
Autotests were also made Valgrind friendly by adding
a final one millisecond wait to the end of the test to
allow pending deleteLaters to run.
Also some minor cosmetic cleanup done to autotests.
Change-Id: Ic3719167a22949f243eaf54614e174a681dbe34a
Reviewed-by: Titta Heikkala <titta.heikkala@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/charts/barmodelmapper/customtablemodel.cpp | 5 | ||||
-rw-r--r-- | examples/charts/barmodelmapper/customtablemodel.h | 1 | ||||
-rw-r--r-- | examples/charts/barmodelmapper/tablewidget.cpp | 10 | ||||
-rw-r--r-- | examples/charts/barmodelmapper/tablewidget.h | 4 |
4 files changed, 15 insertions, 5 deletions
diff --git a/examples/charts/barmodelmapper/customtablemodel.cpp b/examples/charts/barmodelmapper/customtablemodel.cpp index e70fdf34..0a536760 100644 --- a/examples/charts/barmodelmapper/customtablemodel.cpp +++ b/examples/charts/barmodelmapper/customtablemodel.cpp @@ -45,6 +45,11 @@ CustomTableModel::CustomTableModel(QObject *parent) : } } +CustomTableModel::~CustomTableModel() +{ + qDeleteAll(m_data); +} + int CustomTableModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) diff --git a/examples/charts/barmodelmapper/customtablemodel.h b/examples/charts/barmodelmapper/customtablemodel.h index 7294d289..48527e45 100644 --- a/examples/charts/barmodelmapper/customtablemodel.h +++ b/examples/charts/barmodelmapper/customtablemodel.h @@ -30,6 +30,7 @@ class CustomTableModel : public QAbstractTableModel Q_OBJECT public: explicit CustomTableModel(QObject *parent = 0); + virtual ~CustomTableModel(); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; diff --git a/examples/charts/barmodelmapper/tablewidget.cpp b/examples/charts/barmodelmapper/tablewidget.cpp index ba07e757..8c434da2 100644 --- a/examples/charts/barmodelmapper/tablewidget.cpp +++ b/examples/charts/barmodelmapper/tablewidget.cpp @@ -19,7 +19,6 @@ ****************************************************************************/ #include "tablewidget.h" -#include "customtablemodel.h" #include <QtWidgets/QGridLayout> #include <QtWidgets/QTableView> #include <QtCharts/QChart> @@ -40,16 +39,17 @@ TableWidget::TableWidget(QWidget *parent) // create simple model for storing data // user's table data model //! [1] - CustomTableModel *model = new CustomTableModel; + m_model = new CustomTableModel; //! [1] //! [2] // create table view and add model to it QTableView *tableView = new QTableView; - tableView->setModel(model); + tableView->setModel(m_model); tableView->setMinimumWidth(300); tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); + m_model->setParent(tableView); //! [2] //! [3] @@ -69,7 +69,7 @@ TableWidget::TableWidget(QWidget *parent) mapper->setFirstRow(first); mapper->setRowCount(count); mapper->setSeries(series); - mapper->setModel(model); + mapper->setModel(m_model); chart->addSeries(series); //! [4] @@ -81,7 +81,7 @@ TableWidget::TableWidget(QWidget *parent) QList<QBarSet *> barsets = series->barSets(); for (int i = 0; i < barsets.count(); i++) { seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); - model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); + m_model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); } //! [5] diff --git a/examples/charts/barmodelmapper/tablewidget.h b/examples/charts/barmodelmapper/tablewidget.h index 126d3066..d19a00b1 100644 --- a/examples/charts/barmodelmapper/tablewidget.h +++ b/examples/charts/barmodelmapper/tablewidget.h @@ -22,6 +22,7 @@ #define TABLEWIDGET_H #include <QtWidgets/QWidget> +#include "customtablemodel.h" class TableWidget : public QWidget { @@ -29,6 +30,9 @@ class TableWidget : public QWidget public: TableWidget(QWidget *parent = 0); + +private: + CustomTableModel *m_model; }; #endif // TABLEWIDGET_H |