summaryrefslogtreecommitdiffstats
path: root/examples/tutorials/modelview/4_headers/mymodel.cpp
diff options
context:
space:
mode:
authorMichael D Scull <ext-michael.scull@nokia.com>2010-05-27 13:12:58 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2010-07-07 15:07:53 (GMT)
commitf574700f920ae5d5bda25ba217d6face9f3d3902 (patch)
treea4db1390147f7b6041ca763be6715078b1ddd9ab /examples/tutorials/modelview/4_headers/mymodel.cpp
parent4df3fb13821e13ecf581d87f2d224b2f1b964609 (diff)
downloadQt-f574700f920ae5d5bda25ba217d6face9f3d3902.zip
Qt-f574700f920ae5d5bda25ba217d6face9f3d3902.tar.gz
Qt-f574700f920ae5d5bda25ba217d6face9f3d3902.tar.bz2
Rolands ModelView Source
Diffstat (limited to 'examples/tutorials/modelview/4_headers/mymodel.cpp')
-rwxr-xr-xexamples/tutorials/modelview/4_headers/mymodel.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/tutorials/modelview/4_headers/mymodel.cpp b/examples/tutorials/modelview/4_headers/mymodel.cpp
new file mode 100755
index 0000000..a032fe5
--- /dev/null
+++ b/examples/tutorials/modelview/4_headers/mymodel.cpp
@@ -0,0 +1,50 @@
+#include "mymodel.h"
+
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+}
+
+//-------------------------------------------------------
+int MyModel::rowCount(const QModelIndex & /*parent*/ ) const
+{
+ return 2;
+}
+
+//-------------------------------------------------------
+int MyModel::columnCount(const QModelIndex & /*parent*/ ) const
+{
+ return 3;
+}
+
+//-------------------------------------------------------
+QVariant MyModel::data(const QModelIndex &index, int role ) const
+{
+ if(role == Qt::DisplayRole)
+ {
+ return QString("Row%1, Column%2")
+ .arg(index.row() + 1)
+ .arg(index.column() +1);
+ }
+ return QVariant();
+}
+
+
+QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ if (orientation == Qt::Horizontal) {
+ switch (section)
+ {
+ case 0:
+ return QString("first");
+ case 1:
+ return QString("second");
+ case 2:
+ return QString("third");
+ }
+ }
+ }
+ return QVariant();
+}