Qml-C++: Find C++ qmlRegisterType calls and populate QML code model.

Reviewed-by: Erik Verbruggen
This commit is contained in:
Christian Kamm
2010-12-03 10:13:15 +01:00
parent 16542241c9
commit 0194da7300
12 changed files with 359 additions and 2 deletions

View File

@@ -1947,6 +1947,7 @@ const Value *Function::invoke(const Activation *activation) const
////////////////////////////////////////////////////////////////////////////////
QList<const FakeMetaObject *> CppQmlTypesLoader::builtinObjects;
QList<const FakeMetaObject *> CppQmlTypesLoader::cppObjects;
QStringList CppQmlTypesLoader::load(const QFileInfoList &xmlFiles)
{
@@ -2440,6 +2441,7 @@ Engine::Engine()
initializePrototypes();
_cppQmlTypes.load(this, CppQmlTypesLoader::builtinObjects);
_cppQmlTypes.load(this, CppQmlTypesLoader::cppObjects);
// the 'Qt' object is dumped even though it is not exported
// it contains useful information, in particular on enums - add the

View File

@@ -593,6 +593,7 @@ public:
/** \return an empty list when successful, error messages otherwise. */
static QStringList load(const QFileInfoList &xmlFiles);
static QList<const LanguageUtils::FakeMetaObject *> builtinObjects;
static QList<const LanguageUtils::FakeMetaObject *> cppObjects;
// parses the xml string and fills the newObjects map
static QString parseQmlTypeXml(const QByteArray &xml,

View File

@@ -162,9 +162,26 @@ void Link::populateImportedTypes(TypeEnvironment *typeEnv, Document::Ptr doc)
{
Q_D(Link);
if (! (doc->qmlProgram() && doc->qmlProgram()->imports))
if (! doc->qmlProgram())
return;
// implicit imports: the <default> package is always available
const QLatin1String defaultPackage("<default>");
if (engine()->cppQmlTypes().hasPackage(defaultPackage)) {
ImportInfo info(ImportInfo::LibraryImport, defaultPackage);
ObjectValue *import = d->importCache.value(ImportCacheKey(info));
if (!import) {
import = new ObjectValue(engine());
foreach (QmlObjectValue *object,
engine()->cppQmlTypes().typesForImport(defaultPackage, ComponentVersion())) {
import->setProperty(object->className(), object);
}
d->importCache.insert(ImportCacheKey(info), import);
}
typeEnv->addImport(import, info);
}
// implicit imports:
// qml files in the same directory are available without explicit imports
ImportInfo implcitImportInfo(ImportInfo::ImplicitDirectoryImport, doc->path());