Commit 55520a38 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Simplify loading types defined in C++.

parent b13ebc62
......@@ -2034,36 +2034,12 @@ void CppQmlTypes::load(Engine *engine, const T &objects)
foreach (FakeMetaObject::ConstPtr metaObject, objects) {
foreach (const FakeMetaObject::Export &exp, metaObject->exports())
makeObject(engine, metaObject, exp, &newObjects);
FakeMetaObject::Export cppExport;
cppExport.package = cppPackage;
cppExport.type = metaObject->className();
cppExport.packageNameVersion = qualifiedName(cppPackage, cppExport.type, cppExport.version);
makeObject(engine, metaObject, cppExport, &newObjects);
}
// set prototypes
foreach (FakeMetaObject::ConstPtr metaObject, newObjects) {
foreach (const FakeMetaObject::Export &exp, metaObject->exports()) {
QmlObjectValue *objectValue = _typesByFullyQualifiedName.value(exp.packageNameVersion);
if (!objectValue || !metaObject->superClass())
continue;
// set prototypes for whole chain, creating new QmlObjectValues if necessary
// for instance, if an type isn't exported in the package of the super type
// Example: QObject (Qt, QtQuick) -> Positioner (not exported) -> Column (Qt, QtQuick)
// needs to create Positioner (Qt) and Positioner (QtQuick)
bool created = true;
QmlObjectValue *v = objectValue;
FakeMetaObject::ConstPtr fmo = metaObject;
while (created && fmo->superClass()) {
QmlObjectValue *superValue = getOrCreate(exp.package, fmo->superclassName(),
fmo->superClass(), engine, &created);
v->setPrototype(superValue);
v = superValue;
fmo = fmo->superClass();
}
}
foreach (const FakeMetaObject::Export &exp, metaObject->exports())
setPrototypes(engine, metaObject, exp);
}
}
// explicitly instantiate load for list and hash
......@@ -2138,6 +2114,30 @@ void CppQmlTypes::makeObject(Engine *engine,
_typesByFullyQualifiedName[exp.packageNameVersion] = objectValue;
}
void CppQmlTypes::setPrototypes(Engine *engine,
FakeMetaObject::ConstPtr metaObject,
const LanguageUtils::FakeMetaObject::Export &exp)
{
QmlObjectValue *objectValue = _typesByFullyQualifiedName.value(exp.packageNameVersion);
if (!objectValue || !metaObject->superClass())
return;
// set prototypes for whole chain, creating new QmlObjectValues if necessary
// for instance, if an type isn't exported in the package of the super type
// Example: QObject (Qt, QtQuick) -> Positioner (not exported) -> Column (Qt, QtQuick)
// needs to create Positioner (Qt) and Positioner (QtQuick)
bool created = true;
QmlObjectValue *v = objectValue;
FakeMetaObject::ConstPtr fmo = metaObject;
while (created && fmo->superClass()) {
QmlObjectValue *superValue = getOrCreate(exp.package, fmo->superclassName(),
fmo->superClass(), engine, &created);
v->setPrototype(superValue);
v = superValue;
fmo = fmo->superClass();
}
}
QmlObjectValue *CppQmlTypes::getOrCreate(const QString &package, const QString &cppName,
FakeMetaObject::ConstPtr metaObject, Engine *engine, bool *created)
{
......
......@@ -625,6 +625,9 @@ private:
LanguageUtils::FakeMetaObject::ConstPtr metaObject,
const LanguageUtils::FakeMetaObject::Export &exp,
QList<LanguageUtils::FakeMetaObject::ConstPtr> *newObjects);
void setPrototypes(Engine *engine,
LanguageUtils::FakeMetaObject::ConstPtr metaObject,
const LanguageUtils::FakeMetaObject::Export &exp);
QmlObjectValue *getOrCreate(const QString &package, const QString &cppName,
LanguageUtils::FakeMetaObject::ConstPtr metaObject,
Engine *engine, bool *created);
......
......@@ -8,6 +8,7 @@
#include "parser/qmljsastvisitor_p.h"
#include "qmljsbind.h"
#include "qmljsinterpreter.h"
#include <QtCore/QIODevice>
#include <QtCore/QBuffer>
......@@ -172,6 +173,8 @@ void TypeDescriptionReader::readComponent(UiObjectDefinition *ast)
return;
}
// ### add implicit export into the package of c++ types
fmo->addExport(fmo->className(), QmlJS::Interpreter::CppQmlTypes::cppPackage, ComponentVersion());
_objects->insert(fmo->className(), fmo);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment