summaryrefslogtreecommitdiffstats
path: root/examples/tutorials/modelview/5_edit/mymodel.cpp
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2010-09-01 11:20:14 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2010-09-01 11:20:14 (GMT)
commit61403e81d411b82e8a9ac5e3228267bf9ae0e8e1 (patch)
tree0562a4dcf0bcc5365f6cfe7a630f370ef3d471fc /examples/tutorials/modelview/5_edit/mymodel.cpp
parent2e8419e43ce4d5be64bddf1b5b5f5ea9e28c55de (diff)
parent63129c8bd21bfdc8110680296bb3bc1ab5e43343 (diff)
downloadQt-61403e81d411b82e8a9ac5e3228267bf9ae0e8e1.zip
Qt-61403e81d411b82e8a9ac5e3228267bf9ae0e8e1.tar.gz
Qt-61403e81d411b82e8a9ac5e3228267bf9ae0e8e1.tar.bz2
Merge branch '4.7' into qmldocs
Conflicts: src/declarative/graphicsitems/qdeclarativetext.cpp src/declarative/graphicsitems/qdeclarativetextedit.cpp
Diffstat (limited to 'examples/tutorials/modelview/5_edit/mymodel.cpp')
-rwxr-xr-x[-rw-r--r--]examples/tutorials/modelview/5_edit/mymodel.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/examples/tutorials/modelview/5_edit/mymodel.cpp b/examples/tutorials/modelview/5_edit/mymodel.cpp
index 67181ca..e2fd391 100644..100755
--- a/examples/tutorials/modelview/5_edit/mymodel.cpp
+++ b/examples/tutorials/modelview/5_edit/mymodel.cpp
@@ -38,62 +38,64 @@
**
****************************************************************************/
-//! [quoting mymodel_d]
+
#include "mymodel.h"
-const int COLS= 3;
-const int ROWS= 2;
MyModel::MyModel(QObject *parent)
:QAbstractTableModel(parent)
{
- //gridData needs to have 6 element, one for each table cell
- m_gridData << "1/1" << "1/2" << "1/3" << "2/1" << "2/2" << "2/3" ;
}
-//! [quoting mymodel_d]
-//! [quoting mymodel_e]
+//-----------------------------------------------------------------
int MyModel::rowCount(const QModelIndex & /*parent*/) const
{
return ROWS;
}
+//-----------------------------------------------------------------
int MyModel::columnCount(const QModelIndex & /*parent*/) const
{
return COLS;
}
+//-----------------------------------------------------------------
QVariant MyModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole)
{
- return m_gridData[modelIndexToOffset(index)];
+ return m_gridData[index.row()][index.column()];
}
return QVariant();
}
-//! [quoting mymodel_e]
//-----------------------------------------------------------------
-
-//! [quoting mymodel_f]
+//! [quoting mymodel_e]
bool MyModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
if (role == Qt::EditRole)
{
- m_gridData[modelIndexToOffset(index)] = value.toString();
- emit editCompleted(m_gridData.join(" | "));
+ //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++)
+ {
+ result += m_gridData[row][col] + " ";
+ }
+ }
+ emit editCompleted( result );
}
return true;
}
+//! [quoting mymodel_e]
+//-----------------------------------------------------------------
+//! [quoting mymodel_f]
Qt::ItemFlags MyModel::flags(const QModelIndex & /*index*/) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ;
}
-
-//convert row and column information to array offset
-int MyModel::modelIndexToOffset(const QModelIndex & index) const
-{
- return index.row()*COLS + index.column();
-}
//! [quoting mymodel_f]