Commit 14d515df authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: stabilize majorQtQuickVersion()

We have to think of Window/ApplicationWindow as root item.
First we check the import for the major version and if this fails,
we fallback to the root item.

Change-Id: Id24c0d1846a1fe4e6f32f3be834b552fcbed5421
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 66a1b52f
......@@ -232,6 +232,36 @@ int ModelNode::majorVersion() const
return m_internalNode->majorVersion();
}
int getMajorVersionFromImport(Model *model)
{
foreach (const Import &import, model->imports()) {
if (import.isLibraryImport() && import.url() == QLatin1String("QtQuick")) {
const QString versionString = import.version();
if (versionString.contains(QLatin1String("."))) {
const QString majorVersionString = versionString.split(QLatin1String(".")).first();
return majorVersionString.toInt();
}
}
}
return -1;
}
int getMajorVersionFromNode(const ModelNode &modelNode)
{
if (modelNode.metaInfo().isValid()) {
if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item")
return modelNode.majorVersion();
foreach (const NodeMetaInfo &superClass, modelNode.metaInfo().superClasses()) {
if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item")
return superClass.majorVersion();
}
}
return 1; //default
}
/*! \brief major number of the QtQuick version used
\return major number of QtQuickVersion
*/
......@@ -242,19 +272,11 @@ int ModelNode::majorQtQuickVersion() const
throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
}
if (metaInfo().isValid()) {
if (type() == "QtQuick.QtObject")
return majorVersion();
NodeMetaInfo superClass = metaInfo().directSuperClass();
int majorVersionFromImport = getMajorVersionFromImport(model());
if (majorVersionFromImport >= 0)
return majorVersionFromImport;
while (superClass.isValid()) {
if (superClass.typeName() == "QtQuick.QtObject")
return superClass.majorVersion();
superClass = superClass.directSuperClass();
}
return 1; //default
}
return 1; //default
return getMajorVersionFromNode(*this);
}
......
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