aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2011-07-25 16:24:01 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-25 09:43:14 +0200
commitafaf155cf41682378d23ef8da12752f415e70273 (patch)
treec4c98c7d8d54d864bd259e4574f9fa3dd999b72c /src
parent3bb8c0d3f2115765b519f795a2898456bf31924b (diff)
Reverse lookup ids by object pointer
Task-number: QTBUG-18554 Change-Id: Ia4effb629d19aa36b835f6c09a63d9495e5c26e7 Reviewed-on: http://codereview.qt.nokia.com/2079 Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp29
-rw-r--r--src/declarative/qml/qdeclarativecontext.h2
2 files changed, 27 insertions, 4 deletions
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index caa3b0c7d8..d625a1fd98 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -402,6 +402,20 @@ QVariant QDeclarativeContext::contextProperty(const QString &name) const
}
/*!
+Returns the name of \a object in this context, or an empty string if \a object
+is not named in the context. Objects are named by setContextProperty(), or by ids in
+the case of QML created contexts.
+
+If the object has multiple names, the first is returned.
+*/
+QString QDeclarativeContext::nameForObject(QObject *object) const
+{
+ Q_D(const QDeclarativeContext);
+
+ return d->data->findObjectId(object);
+}
+
+/*!
Resolves the URL \a src relative to the URL of the
containing component.
@@ -693,12 +707,19 @@ void QDeclarativeContextData::setIdPropertyData(QDeclarativeIntegerCache *data)
QString QDeclarativeContextData::findObjectId(const QObject *obj) const
{
- if (!idValues || !propertyNames)
+ if (!propertyNames)
return QString();
- for (int i=0; i<idValueCount; i++) {
- if (idValues[i] == obj)
- return propertyNames->findId(i);
+ for (int ii = 0; ii < idValueCount; ii++) {
+ if (idValues[ii] == obj)
+ return propertyNames->findId(ii);
+ }
+
+ if (publicContext) {
+ QDeclarativeContextPrivate *p = QDeclarativeContextPrivate::get(publicContext);
+ for (int ii = 0; ii < p->propertyValues.count(); ++ii)
+ if (p->propertyValues.at(ii) == QVariant::fromValue((QObject *)obj))
+ return propertyNames->findId(ii);
}
if (linkedContext)
diff --git a/src/declarative/qml/qdeclarativecontext.h b/src/declarative/qml/qdeclarativecontext.h
index fd33ccdabe..d8e8506dad 100644
--- a/src/declarative/qml/qdeclarativecontext.h
+++ b/src/declarative/qml/qdeclarativecontext.h
@@ -83,6 +83,8 @@ public:
void setContextProperty(const QString &, QObject *);
void setContextProperty(const QString &, const QVariant &);
+ QString nameForObject(QObject *) const;
+
QUrl resolvedUrl(const QUrl &);
void setBaseUrl(const QUrl &);