diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-10-20 21:48:28 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-11-12 13:01:30 +0000 |
commit | 8c685b765bf4ceba3c4cf8fdd9c9d680f338b7a9 (patch) | |
tree | 51c5eafe87638e79961c63898cc63bce87edcadd /examples/widgets/tutorials/modelview/5_edit/mymodel.cpp | |
parent | 1c957bb8e57adf7674716f40b67c5d6877b32f86 (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/5_edit/mymodel.cpp')
-rw-r--r-- | examples/widgets/tutorials/modelview/5_edit/mymodel.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp b/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp index fb2954baf2..eeca2ce0a0 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp @@ -48,12 +48,10 @@ ** ****************************************************************************/ - #include "mymodel.h" - MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } @@ -72,33 +70,31 @@ int MyModel::columnCount(const QModelIndex & /*parent*/) const //----------------------------------------------------------------- QVariant MyModel::data(const QModelIndex &index, int role) const { - if (role == Qt::DisplayRole) - { - return m_gridData[index.row()][index.column()]; - } + if (role == Qt::DisplayRole && checkIndex(index)) + return m_gridData[index.row()][index.column()]; + return QVariant(); } //----------------------------------------------------------------- //! [quoting mymodel_e] -bool MyModel::setData(const QModelIndex & index, const QVariant & value, int role) +bool MyModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (role == Qt::EditRole) - { + if (role == Qt::EditRole) { + if (!checkIndex(index)) + return false; //save value from editor to member m_gridData m_gridData[index.row()][index.column()] = value.toString(); //for presentation purposes only: build and emit a joined string QString result; - for (int row= 0; row < ROWS; row++) - { - for(int col= 0; col < COLS; col++) - { + for (int row = 0; row < ROWS; row++) { + for (int col= 0; col < COLS; col++) result += m_gridData[row][col] + ' '; - } } - emit editCompleted( result ); + emit editCompleted(result); + return true; } - return true; + return false; } //! [quoting mymodel_e] |