QmlJS: Find setContextProperty calls in C++ and expose to QML.

Task-number: QTCREATORBUG-3199

Change-Id: I591490ceafadc0f5a07c63ec063f1bdfa7055f47
Reviewed-on: http://codereview.qt-project.org/4074
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
Christian Kamm
2011-08-25 12:35:55 +02:00
parent c2f31f16dc
commit 10a956a8f7
8 changed files with 327 additions and 71 deletions

View File

@@ -120,11 +120,29 @@ Link::Link(const Snapshot &snapshot, const QStringList &importPaths, const Libra
d->diagnosticMessages = 0;
d->allDiagnosticMessages = 0;
// populate engine with types from C++
ModelManagerInterface *modelManager = ModelManagerInterface::instance();
if (modelManager) {
foreach (const QList<FakeMetaObject::ConstPtr> &cppTypes, modelManager->cppQmlTypes()) {
d->valueOwner->cppQmlTypes().load(d->valueOwner, cppTypes);
ModelManagerInterface::CppDataHash cppDataHash = modelManager->cppData();
// populate engine with types from C++
foreach (const ModelManagerInterface::CppData &cppData, cppDataHash) {
d->valueOwner->cppQmlTypes().load(d->valueOwner, cppData.exportedTypes);
}
// populate global object with context properties from C++
ObjectValue *global = d->valueOwner->globalObject();
foreach (const ModelManagerInterface::CppData &cppData, cppDataHash) {
QMapIterator<QString, QString> it(cppData.contextProperties);
while (it.hasNext()) {
it.next();
const Value *value = 0;
const QString cppTypeName = it.value();
if (!cppTypeName.isEmpty())
value = d->valueOwner->cppQmlTypes().typeByCppName(cppTypeName);
if (!value)
value = d->valueOwner->undefinedValue();
global->setMember(it.key(), value);
}
}
}
}

View File

@@ -110,7 +110,14 @@ public:
Table _elements;
};
typedef QHash<QString, QList<LanguageUtils::FakeMetaObject::ConstPtr> > CppQmlTypeHash;
class CppData
{
public:
QList<LanguageUtils::FakeMetaObject::ConstPtr> exportedTypes;
QMap<QString, QString> contextProperties;
};
typedef QHash<QString, CppData> CppDataHash;
public:
ModelManagerInterface(QObject *parent = 0);
@@ -138,7 +145,7 @@ public:
virtual void loadPluginTypes(const QString &libraryPath, const QString &importPath,
const QString &importUri, const QString &importVersion) = 0;
virtual CppQmlTypeHash cppQmlTypes() const = 0;
virtual CppDataHash cppData() const = 0;
virtual LibraryInfo builtins(const Document::Ptr &doc) const = 0;