diff options
author | Oliver Wolff <oliver.wolff@digia.com> | 2012-12-06 14:54:32 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-12 00:32:24 +0100 |
commit | 87d0c02fab03b7d3bf2094af22465f029bcdd096 (patch) | |
tree | 219bce198a3cc77e44a7b2f47ba67d2490972a7e /examples | |
parent | 00f65e486a7c959bb240e1b41f641cbe538d40a1 (diff) |
Fixed abstractitemmodel example
Change-Id: I1e85fd3f35f4f3d80e3fb599ae95b771db5f949b
Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/quick/models/abstractitemmodel/model.cpp | 15 | ||||
-rw-r--r-- | examples/quick/models/abstractitemmodel/model.h | 2 | ||||
-rw-r--r-- | examples/quick/models/models.pro | 2 |
3 files changed, 12 insertions, 7 deletions
diff --git a/examples/quick/models/abstractitemmodel/model.cpp b/examples/quick/models/abstractitemmodel/model.cpp index 9c24decf2d..524ed5461b 100644 --- a/examples/quick/models/abstractitemmodel/model.cpp +++ b/examples/quick/models/abstractitemmodel/model.cpp @@ -54,16 +54,10 @@ QString Animal::size() const return m_size; } -//![0] AnimalModel::AnimalModel(QObject *parent) : QAbstractListModel(parent) { - QHash<int, QByteArray> roles; - roles[TypeRole] = "type"; - roles[SizeRole] = "size"; - setRoleNames(roles); } -//![0] void AnimalModel::addAnimal(const Animal &animal) { @@ -88,3 +82,12 @@ QVariant AnimalModel::data(const QModelIndex & index, int role) const { return QVariant(); } +//![0] +QHash<int, QByteArray> AnimalModel::roleNames() const { + QHash<int, QByteArray> roles; + roles[TypeRole] = "type"; + roles[SizeRole] = "size"; + return roles; +} +//![0] + diff --git a/examples/quick/models/abstractitemmodel/model.h b/examples/quick/models/abstractitemmodel/model.h index 9436770b19..2db178bae1 100644 --- a/examples/quick/models/abstractitemmodel/model.h +++ b/examples/quick/models/abstractitemmodel/model.h @@ -74,6 +74,8 @@ public: QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; +protected: + QHash<int, QByteArray> roleNames() const; private: QList<Animal> m_animals; //![2] diff --git a/examples/quick/models/models.pro b/examples/quick/models/models.pro index 60407a679e..95d2716836 100644 --- a/examples/quick/models/models.pro +++ b/examples/quick/models/models.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs SUBDIRS = \ -# abstractitemmodel \ #Doesn't build right now + abstractitemmodel \ objectlistmodel \ stringlistmodel |