diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/3rdparty/qlistmodelinterface_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmlcontext.cpp | 14 | ||||
-rw-r--r-- | src/declarative/util/qmllistmodel.cpp | 23 | ||||
-rw-r--r-- | src/declarative/util/qmllistmodel_p.h | 1 | ||||
-rw-r--r-- | src/declarative/util/qmlxmllistmodel.cpp | 7 | ||||
-rw-r--r-- | src/declarative/util/qmlxmllistmodel_p.h | 1 |
6 files changed, 44 insertions, 3 deletions
diff --git a/src/declarative/3rdparty/qlistmodelinterface_p.h b/src/declarative/3rdparty/qlistmodelinterface_p.h index f7c956a..a958ead 100644 --- a/src/declarative/3rdparty/qlistmodelinterface_p.h +++ b/src/declarative/3rdparty/qlistmodelinterface_p.h @@ -60,6 +60,7 @@ class Q_DECLARATIVE_EXPORT QListModelInterface : public QObject virtual int count() const = 0; virtual QHash<int,QVariant> data(int index, const QList<int>& roles = QList<int>()) const = 0; + virtual QVariant data(int index, int role) const = 0; virtual bool setData(int index, const QHash<int,QVariant>& values) { Q_UNUSED(index); Q_UNUSED(values); return false; } diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 445bf03..49bb59c 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -453,12 +453,20 @@ QVariant QmlContext::contextProperty(const QString &name) const if (idx == -1) { QByteArray utf8Name = name.toUtf8(); for (int ii = d->defaultObjects.count() - 1; ii >= 0; --ii) { - value = d->defaultObjects.at(ii)->property(utf8Name); - if (!value.isValid() && parentContext()) - value = parentContext()->contextProperty(name); + QObject *obj = d->defaultObjects.at(ii); + QmlDeclarativeData *data = QmlDeclarativeData::get(obj); + if (data && data->propertyCache) { + QmlPropertyCache::Data *property = data->propertyCache->property(name); + if (property) + value = obj->metaObject()->property(property->coreIndex).read(obj); + } else { + value = obj->property(utf8Name); + } if (value.isValid()) break; } + if (!value.isValid() && parentContext()) + value = parentContext()->contextProperty(name); } else { value = d->propertyValues[idx]; } diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index f4317af..de6ee2e 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -421,6 +421,29 @@ QHash<int,QVariant> QmlListModel::data(int index, const QList<int> &roles) const return rv; } +QVariant QmlListModel::data(int index, int role) const +{ + checkRoles(); + QVariant rv; + if (index >= count()) + return rv; + + ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(index)); + if (!node) + return rv; + + const QString &roleString = roleStrings.at(role); + + QHash<QString, ModelNode *>::ConstIterator iter = + node->properties.find(roleString); + if (iter != node->properties.end()) { + ModelNode *row = *iter; + rv = valueForNode(row); + } + + return rv; +} + /*! \qmlproperty int ListModel::count The number of data entries in the model. diff --git a/src/declarative/util/qmllistmodel_p.h b/src/declarative/util/qmllistmodel_p.h index 2a1a57d..47236d0 100644 --- a/src/declarative/util/qmllistmodel_p.h +++ b/src/declarative/util/qmllistmodel_p.h @@ -72,6 +72,7 @@ public: virtual QString toString(int role) const; virtual int count() const; virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const; + virtual QVariant data(int index, int role) const; Q_INVOKABLE void clear(); Q_INVOKABLE void remove(int index); diff --git a/src/declarative/util/qmlxmllistmodel.cpp b/src/declarative/util/qmlxmllistmodel.cpp index 46ef739..d31fadf 100644 --- a/src/declarative/util/qmlxmllistmodel.cpp +++ b/src/declarative/util/qmlxmllistmodel.cpp @@ -462,6 +462,13 @@ QHash<int,QVariant> QmlXmlListModel::data(int index, const QList<int> &roles) co return rv; } +QVariant QmlXmlListModel::data(int index, int role) const +{ + Q_D(const QmlXmlListModel); + int roleIndex = d->roles.indexOf(role); + return (roleIndex == -1) ? QVariant() : d->data.at(roleIndex).at(index); +} + /*! \qmlproperty int XmlListModel::count The number of data entries in the model. diff --git a/src/declarative/util/qmlxmllistmodel_p.h b/src/declarative/util/qmlxmllistmodel_p.h index 67fc751..e4b8cab 100644 --- a/src/declarative/util/qmlxmllistmodel_p.h +++ b/src/declarative/util/qmlxmllistmodel_p.h @@ -79,6 +79,7 @@ public: ~QmlXmlListModel(); virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const; + virtual QVariant data(int index, int role) const; virtual int count() const; virtual QList<int> roles() const; virtual QString toString(int role) const; |