summaryrefslogtreecommitdiffstats
path: root/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-10-20 21:48:28 +0200
committerLiang Qi <liang.qi@qt.io>2018-11-12 13:01:30 +0000
commit8c685b765bf4ceba3c4cf8fdd9c9d680f338b7a9 (patch)
tree51c5eafe87638e79961c63898cc63bce87edcadd /examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp
parent1c957bb8e57adf7674716f40b67c5d6877b32f86 (diff)
Itemviews: Cleanup examples
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 <aha_1980@gmx.de> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp')
-rw-r--r--examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp23
1 files changed, 9 insertions, 14 deletions
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 <QBrush>
-#include <QTime>
#include "mymodel.h"
+#include <QTime>
+
//! [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 ]