From 8c685b765bf4ceba3c4cf8fdd9c9d680f338b7a9 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 20 Oct 2018 21:48:28 +0200 Subject: Itemviews: Cleanup examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleanup some minor issues in the chart example: - remove unused members - use initializer list for members - pass a proper role to dataChanged() - honor roles parameter in PieView::dataChanged() - use nullptr instead 0 - use new-style connect - fix indentation and other whitespaces Change-Id: Idb212b07c006fe3ae31bee9cd9b1ba4d03043b5e Reviewed-by: André Hartmann Reviewed-by: Paul Wicking --- .../modelview/3_changingmodel/mymodel.cpp | 23 +++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp') diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp index e4580a0e01..f289d9abda 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp @@ -48,18 +48,17 @@ ** ****************************************************************************/ -#include -#include #include "mymodel.h" +#include + //! [quoting mymodel_a] MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) + , timer(new QTimer(this)) { -// selectedCell = 0; - timer = new QTimer(this); timer->setInterval(1000); - connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit())); + connect(timer, &QTimer::timeout , this, &MyModel::timerHit); timer->start(); } //! [quoting mymodel_a] @@ -82,13 +81,9 @@ QVariant MyModel::data(const QModelIndex &index, int role) const int row = index.row(); int col = index.column(); - if (role == Qt::DisplayRole) - { - if (row == 0 && col == 0) - { - return QTime::currentTime().toString(); - } - } + if (role == Qt::DisplayRole && row == 0 && col == 0) + return QTime::currentTime().toString(); + return QVariant(); } //! [quoting mymodel_QVariant ] @@ -99,6 +94,6 @@ void MyModel::timerHit() //we identify the top left cell QModelIndex topLeft = createIndex(0,0); //emit a signal to make the view reread identified data - emit dataChanged(topLeft, topLeft); + emit dataChanged(topLeft, topLeft, {Qt::DisplayRole}); } //! [quoting mymodel_b ] -- cgit v1.2.3