summaryrefslogtreecommitdiffstats
path: root/examples/tutorials/modelview/1_readonly
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/1_readonly
parent4df3fb13821e13ecf581d87f2d224b2f1b964609 (diff)
downloadQt-f574700f920ae5d5bda25ba217d6face9f3d3902.zip
Qt-f574700f920ae5d5bda25ba217d6face9f3d3902.tar.gz
Qt-f574700f920ae5d5bda25ba217d6face9f3d3902.tar.bz2
Rolands ModelView Source
Diffstat (limited to 'examples/tutorials/modelview/1_readonly')
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/1_readonly.pro10
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/main.cpp10
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/modelview.cpp12
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/modelview.h18
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/mymodel.cpp30
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/mymodel.h16
6 files changed, 96 insertions, 0 deletions
diff --git a/examples/tutorials/modelview/1_readonly/1_readonly.pro b/examples/tutorials/modelview/1_readonly/1_readonly.pro
new file mode 100755
index 0000000..1162d5a
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/1_readonly.pro
@@ -0,0 +1,10 @@
+TARGET = mv_readonly
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ modelview.cpp \
+ mymodel.cpp
+
+HEADERS += modelview.h \
+ mymodel.h
diff --git a/examples/tutorials/modelview/1_readonly/main.cpp b/examples/tutorials/modelview/1_readonly/main.cpp
new file mode 100755
index 0000000..998503c
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/main.cpp
@@ -0,0 +1,10 @@
+#include <QtGui/QApplication>
+#include "modelview.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ ModelView w;
+ w.show();
+ return a.exec();
+}
diff --git a/examples/tutorials/modelview/1_readonly/modelview.cpp b/examples/tutorials/modelview/1_readonly/modelview.cpp
new file mode 100755
index 0000000..becd61d
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/modelview.cpp
@@ -0,0 +1,12 @@
+#include <QTableView>
+#include "modelview.h"
+#include "mymodel.h"
+
+ModelView::ModelView(QWidget *parent)
+ : QMainWindow(parent)
+{
+ tableView = new QTableView(this);
+ setCentralWidget(tableView);
+ tableView->setModel(new MyModel(this) );
+}
+
diff --git a/examples/tutorials/modelview/1_readonly/modelview.h b/examples/tutorials/modelview/1_readonly/modelview.h
new file mode 100755
index 0000000..f1b63bd
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/modelview.h
@@ -0,0 +1,18 @@
+#ifndef MODELVIEW_H
+#define MODELVIEW_H
+
+#include <QtGui/QMainWindow>
+
+class QTableView; //forward declaration
+
+class ModelView : public QMainWindow
+{
+ Q_OBJECT
+private:
+ QTableView *tableView;
+public:
+ ModelView(QWidget *parent = 0);
+
+};
+
+#endif // MODELVIEW_H
diff --git a/examples/tutorials/modelview/1_readonly/mymodel.cpp b/examples/tutorials/modelview/1_readonly/mymodel.cpp
new file mode 100755
index 0000000..ff3e2d2
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/mymodel.cpp
@@ -0,0 +1,30 @@
+#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();
+}
diff --git a/examples/tutorials/modelview/1_readonly/mymodel.h b/examples/tutorials/modelview/1_readonly/mymodel.h
new file mode 100755
index 0000000..01ae6cb
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/mymodel.h
@@ -0,0 +1,16 @@
+#ifndef MYMODEL_H
+#define MYMODEL_H
+
+#include <QAbstractTableModel>
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+};
+
+#endif // MYMODEL_H