Commit 6a6dffb9 authored by Tim Jenssen's avatar Tim Jenssen

QmlDesigner: improve check class hierarchy code

 - improve existing superClasses() via using transform (internal it uses
   reserve, shorter, ...)
 - remove unused superClassNames() if necessary it can be done by a
   simple transform call
 - introduce and use classHierarchy() and fix foreach loop which was using
   wrong "modelNode" instead of "superClass"

Change-Id: Ia52bcbd322f3a047a020faf4a67aca2a1b8fd19a
Reviewed-by: Thomas Hartmann's avatarThomas Hartmann <thomas.hartmann@qt.io>
parent c5d37af0
......@@ -527,11 +527,7 @@ void PropertyEditorQmlBackend::setValueforLayoutAttachedProperties(const QmlObje
QUrl PropertyEditorQmlBackend::getQmlUrlForModelNode(const ModelNode &modelNode, TypeName &className)
{
if (modelNode.isValid()) {
QList<NodeMetaInfo> hierarchy;
hierarchy.append(modelNode.metaInfo());
hierarchy.append(modelNode.metaInfo().superClasses());
foreach (const NodeMetaInfo &info, hierarchy) {
foreach (const NodeMetaInfo &info, modelNode.metaInfo().classHierarchy()) {
QUrl fileUrl = fileToUrl(locateQmlFile(info, QString::fromUtf8(qmlFileName(info))));
if (fileUrl.isValid()) {
className = info.typeName();
......
......@@ -434,11 +434,7 @@ void PropertyEditorView::setupQmlBackend()
TypeName diffClassName;
if (m_selectedNode.isValid()) {
diffClassName = m_selectedNode.metaInfo().typeName();
QList<NodeMetaInfo> hierarchy;
hierarchy << m_selectedNode.metaInfo();
hierarchy << m_selectedNode.metaInfo().superClasses();
foreach (const NodeMetaInfo &metaInfo, hierarchy) {
foreach (const NodeMetaInfo &metaInfo, m_selectedNode.metaInfo().classHierarchy()) {
if (PropertyEditorQmlBackend::checkIfUrlExists(qmlSpecificsFile))
break;
qmlSpecificsFile = PropertyEditorQmlBackend::getQmlFileUrl(metaInfo.typeName() + "Specifics", metaInfo);
......
......@@ -78,11 +78,10 @@ public:
QStringList propertyKeysForEnum(const PropertyName &propertyName) const;
QVariant propertyCastedValue(const PropertyName &propertyName, const QVariant &value) const;
QList<NodeMetaInfo> classHierarchy() const;
QList<NodeMetaInfo> superClasses() const;
NodeMetaInfo directSuperClass() const;
QStringList superClassNames() const;
bool defaultPropertyIsComponent() const;
TypeName typeName() const;
......
......@@ -41,6 +41,7 @@
#include <languageutils/fakemetaobject.h>
#include <utils/qtcassert.h>
#include <utils/algorithm.h>
namespace QmlDesigner {
......@@ -1449,32 +1450,24 @@ QVariant NodeMetaInfo::propertyCastedValue(const PropertyName &propertyName, con
return Internal::PropertyParser::variantFromString(variant.toString());
}
QList<NodeMetaInfo> NodeMetaInfo::superClasses() const
QList<NodeMetaInfo> NodeMetaInfo::classHierarchy() const
{
QList<NodeMetaInfo> list;
foreach (const Internal::TypeDescription &type, m_privateData->prototypes()) {
list.append(NodeMetaInfo(m_privateData->model(), type.className.toUtf8(), type.majorVersion, type.minorVersion));
}
return list;
QList<NodeMetaInfo> hierarchy = {*this};
hierarchy.append(superClasses());
return hierarchy;
}
NodeMetaInfo NodeMetaInfo::directSuperClass() const
QList<NodeMetaInfo> NodeMetaInfo::superClasses() const
{
QList<NodeMetaInfo> superClassesList = superClasses();
if (superClassesList.count() > 1)
return superClassesList.at(1);
return NodeMetaInfo();
Model *model = m_privateData->model();
return Utils::transform(m_privateData->prototypes(), [model](const Internal::TypeDescription &type) {
return NodeMetaInfo(model, type.className.toUtf8(), type.majorVersion, type.minorVersion);
});
}
QStringList NodeMetaInfo::superClassNames() const
NodeMetaInfo NodeMetaInfo::directSuperClass() const
{
QStringList list;
foreach (const Internal::TypeDescription &type, m_privateData->prototypes()) {
list.append(type.className);
}
return list;
return superClasses().value(1, NodeMetaInfo());
}
bool NodeMetaInfo::defaultPropertyIsComponent() const
......
......@@ -721,12 +721,9 @@ static int getMajorVersionFromImport(const Model *model)
static 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();
foreach (const NodeMetaInfo &info, modelNode.metaInfo().classHierarchy()) {
if (info.typeName() == "QtQuick.QtObject" || info.typeName() == "QtQuick.Item")
return info.majorVersion();
}
}
......@@ -736,12 +733,9 @@ static int getMajorVersionFromNode(const ModelNode &modelNode)
static int getMinorVersionFromNode(const ModelNode &modelNode)
{
if (modelNode.metaInfo().isValid()) {
if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item")
return modelNode.minorVersion();
foreach (const NodeMetaInfo &superClass, modelNode.metaInfo().superClasses()) {
if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item")
return superClass.minorVersion();
foreach (const NodeMetaInfo &info, modelNode.metaInfo().classHierarchy()) {
if (info.typeName() == "QtQuick.QtObject" || info.typeName() == "QtQuick.Item")
return info.minorVersion();
}
}
......
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