diff options
author | Michael D Scull <ext-michael.scull@nokia.com> | 2010-05-27 13:12:58 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2010-07-07 15:07:53 (GMT) |
commit | f574700f920ae5d5bda25ba217d6face9f3d3902 (patch) | |
tree | a4db1390147f7b6041ca763be6715078b1ddd9ab /examples/tutorials/modelview/1_readonly | |
parent | 4df3fb13821e13ecf581d87f2d224b2f1b964609 (diff) | |
download | Qt-f574700f920ae5d5bda25ba217d6face9f3d3902.zip Qt-f574700f920ae5d5bda25ba217d6face9f3d3902.tar.gz Qt-f574700f920ae5d5bda25ba217d6face9f3d3902.tar.bz2 |
Rolands ModelView Source
Diffstat (limited to 'examples/tutorials/modelview/1_readonly')
-rwxr-xr-x | examples/tutorials/modelview/1_readonly/1_readonly.pro | 10 | ||||
-rwxr-xr-x | examples/tutorials/modelview/1_readonly/main.cpp | 10 | ||||
-rwxr-xr-x | examples/tutorials/modelview/1_readonly/modelview.cpp | 12 | ||||
-rwxr-xr-x | examples/tutorials/modelview/1_readonly/modelview.h | 18 | ||||
-rwxr-xr-x | examples/tutorials/modelview/1_readonly/mymodel.cpp | 30 | ||||
-rwxr-xr-x | examples/tutorials/modelview/1_readonly/mymodel.h | 16 |
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 |