From 2b0f93c8d8135868c3377b4d0e5f99ec728101d8 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 9 Aug 2013 13:28:15 +0200 Subject: [PATCH] QmlDesigner.PropertyEditorView: further cleanup Cleaning up/renaming the functions used to resolve .qml files. Change-Id: I80ccb9346d89c0841ad0109147d8a9e07cf20408 Reviewed-by: Marco Bubke --- .../propertyeditorqmlbackend.cpp | 11 +++++++++- .../propertyeditor/propertyeditorqmlbackend.h | 17 +++++++++----- .../propertyeditor/propertyeditorview.cpp | 22 +++++++------------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index c9a18571db..120fe6851f 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -403,6 +403,10 @@ QString PropertyEditorQmlBackend::templateGeneration(NodeMetaInfo type, return qmlTemplate; } +QUrl PropertyEditorQmlBackend::getQmlFileUrl(const QString &relativeTypeName, const NodeMetaInfo &info) +{ + return fileToUrl(locateQmlFile(info, fixTypeNameForPanes(relativeTypeName) + QLatin1String(".qml"))); +} QString PropertyEditorQmlBackend::fixTypeNameForPanes(const QString &typeName) { @@ -447,7 +451,12 @@ QString PropertyEditorQmlBackend::fileFromUrl(const QUrl &url) return url.toLocalFile(); } -QUrl PropertyEditorQmlBackend::qmlForNode(const ModelNode &modelNode, TypeName &className) +bool PropertyEditorQmlBackend::checkIfUrlExists(const QUrl &url) +{ + return (QFileInfo(fileFromUrl(url)).exists()); +} + +QUrl PropertyEditorQmlBackend::getQmlUrlForModelNode(const ModelNode &modelNode, TypeName &className) { if (modelNode.isValid()) { QList hierarchy; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h index a1fbb398c4..8d1d7482d4 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h @@ -36,6 +36,8 @@ #include "propertyeditorcontextobject.h" #include "quickpropertyeditorview.h" +#include + class PropertyEditorValue; namespace QmlDesigner { @@ -66,13 +68,10 @@ public: static QString templateGeneration(NodeMetaInfo type, NodeMetaInfo superType, const QmlObjectNode &objectNode); - static QString qmlFileName(const NodeMetaInfo &nodeInfo) ; - static QUrl fileToUrl(const QString &filePath) ; - static QString fileFromUrl(const QUrl &url) ; - static QUrl qmlForNode(const ModelNode &modelNode, TypeName &className) ; - static QString locateQmlFile(const NodeMetaInfo &info, const QString &relativePath) ; + static QUrl getQmlFileUrl(const QString &relativeTypeName, const NodeMetaInfo &info = NodeMetaInfo()); + static QUrl getQmlUrlForModelNode(const ModelNode &modelNode, TypeName &className); - static QString fixTypeNameForPanes(const QString &typeName); + static bool checkIfUrlExists(const QUrl &url); private: void createPropertyEditorValue(const QmlObjectNode &qmlObjectNode, @@ -80,6 +79,12 @@ private: PropertyEditorView *propertyEditor); void setupPropertyEditorValue(const PropertyName &name, PropertyEditorView *propertyEditor, const QString &type); + static QString qmlFileName(const NodeMetaInfo &nodeInfo); + static QUrl fileToUrl(const QString &filePath); + static QString fileFromUrl(const QUrl &url); + static QString locateQmlFile(const NodeMetaInfo &info, const QString &relativePath); + static QString fixTypeNameForPanes(const QString &typeName); + private: QuickPropertyEditorView *m_view; Internal::QmlAnchorBindingProxy m_backendAnchorBinding; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp index c0efd96cf0..ab58e84ef3 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp @@ -100,13 +100,10 @@ void PropertyEditorView::setupPane(const TypeName &typeName) { NodeMetaInfo metaInfo = model()->metaInfo(typeName); - QUrl qmlFile = PropertyEditorQmlBackend::fileToUrl( - PropertyEditorQmlBackend::locateQmlFile(metaInfo, QLatin1String("Qt/ItemPane.qml"))); + QUrl qmlFile = PropertyEditorQmlBackend::getQmlFileUrl(QLatin1String("Qt/ItemPane"), metaInfo); QUrl qmlSpecificsFile; - qmlSpecificsFile = PropertyEditorQmlBackend::fileToUrl(PropertyEditorQmlBackend::locateQmlFile( - metaInfo, PropertyEditorQmlBackend::fixTypeNameForPanes(typeName) - + "Specifics.qml")); + qmlSpecificsFile = PropertyEditorQmlBackend::getQmlFileUrl(typeName + "Specifics", metaInfo); PropertyEditorQmlBackend *qmlBackend = m_qmlBackendHash.value(qmlFile.toString()); @@ -364,7 +361,7 @@ void PropertyEditorView::resetView() m_selectedNode = ModelNode(); TypeName specificsClassName; - QUrl qmlFile(PropertyEditorQmlBackend::qmlForNode(m_selectedNode, specificsClassName)); + QUrl qmlFile(PropertyEditorQmlBackend::getQmlUrlForModelNode(m_selectedNode, specificsClassName)); QUrl qmlSpecificsFile; TypeName diffClassName; @@ -374,18 +371,15 @@ void PropertyEditorView::resetView() hierarchy << m_selectedNode.metaInfo(); hierarchy << m_selectedNode.metaInfo().superClasses(); - foreach (const NodeMetaInfo &info, hierarchy) { - if (QFileInfo(PropertyEditorQmlBackend::fileFromUrl(qmlSpecificsFile)).exists()) + foreach (const NodeMetaInfo &metaInfo, hierarchy) { + if (PropertyEditorQmlBackend::checkIfUrlExists(qmlSpecificsFile)) break; - qmlSpecificsFile = PropertyEditorQmlBackend::fileToUrl(PropertyEditorQmlBackend::locateQmlFile( - info, - PropertyEditorQmlBackend::fixTypeNameForPanes(info.typeName()) - + "Specifics.qml")); - diffClassName = info.typeName(); + qmlSpecificsFile = PropertyEditorQmlBackend::getQmlFileUrl(metaInfo.typeName() + QLatin1String("Specifics"), metaInfo); + diffClassName = metaInfo.typeName(); } } - if (!QFileInfo(PropertyEditorQmlBackend::fileFromUrl(qmlSpecificsFile)).exists()) + if (!PropertyEditorQmlBackend::checkIfUrlExists(qmlSpecificsFile)) diffClassName = specificsClassName; QString specificQmlData; -- GitLab