diff options
author | Thomas Hartmann <Thomas.Hartmann@digia.com> | 2013-08-12 18:09:36 +0200 |
---|---|---|
committer | Thomas Hartmann <Thomas.Hartmann@digia.com> | 2013-08-12 18:17:37 +0200 |
commit | 7a5cce92c23b1bd091714550ee4ab95e0e3f8e9f (patch) | |
tree | d44161c4a01df96161b4aed241401ef5ca0adf70 /src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp | |
parent | a01f70c089c27b8f7d1a331db900beed92aecaa0 (diff) | |
download | qt-creator-7a5cce92c23b1bd091714550ee4ab95e0e3f8e9f.tar.gz |
QmlDesigner.PropertyEditorView: move code to QmlBackEnd
Moving QML related code from PropertyEditorView to
PropertyEditorQmlBackend.
PropertyEditorView should not contain any code related to QML anymore.
Change-Id: Ia58db399e2f7a4b8cbe1119c4176257344d78ea9
Reviewed-by: Marco Bubke <marco.bubke@digia.com>
Diffstat (limited to 'src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp')
-rw-r--r-- | src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index 98a7c2bcae..c9a18571db 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -31,6 +31,7 @@ #include "propertyeditorvalue.h" #include "propertyeditortransaction.h" +#include <qmldesignerconstants.h> #include <qmlobjectnode.h> #include <nodemetainfo.h> @@ -38,6 +39,7 @@ #include <bindingproperty.h> #include <QApplication> +#include <QDir> #include <QFileInfo> #include <qmljs/qmljssimplereader.h> @@ -50,6 +52,8 @@ enum { debug = false }; +const char resourcePropertyEditorPath[] = ":/propertyeditor"; + static QmlJS::SimpleReaderNode::Ptr s_templateConfiguration; static inline QString propertyTemplatesPath() @@ -399,4 +403,106 @@ QString PropertyEditorQmlBackend::templateGeneration(NodeMetaInfo type, return qmlTemplate; } + +QString PropertyEditorQmlBackend::fixTypeNameForPanes(const QString &typeName) +{ + QString fixedTypeName = typeName; + fixedTypeName.replace('.', '/'); + return fixedTypeName; +} + +QString PropertyEditorQmlBackend::qmlFileName(const NodeMetaInfo &nodeInfo) +{ + if (nodeInfo.typeName().split('.').last() == "QDeclarativeItem") + return "QtQuick/ItemPane.qml"; + const QString fixedTypeName = fixTypeNameForPanes(nodeInfo.typeName()); + return fixedTypeName + QLatin1String("Pane.qml"); +} + +QUrl PropertyEditorQmlBackend::fileToUrl(const QString &filePath) { + QUrl fileUrl; + + if (filePath.isEmpty()) + return fileUrl; + + if (filePath.startsWith(QLatin1Char(':'))) { + fileUrl.setScheme("qrc"); + QString path = filePath; + path.remove(0, 1); // remove trailing ':' + fileUrl.setPath(path); + } else { + fileUrl = QUrl::fromLocalFile(filePath); + } + + return fileUrl; +} + +QString PropertyEditorQmlBackend::fileFromUrl(const QUrl &url) +{ + if (url.scheme() == QLatin1String("qrc")) { + const QString &path = url.path(); + return QLatin1String(":") + path; + } + + return url.toLocalFile(); +} + +QUrl PropertyEditorQmlBackend::qmlForNode(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) { + QUrl fileUrl = fileToUrl(locateQmlFile(info, qmlFileName(info))); + if (fileUrl.isValid()) { + className = info.typeName(); + return fileUrl; + } + } + } + return fileToUrl(QDir(propertyEditorResourcesPath()).filePath("QtQuick/emptyPane.qml")); +} + +QString PropertyEditorQmlBackend::locateQmlFile(const NodeMetaInfo &info, const QString &relativePath) +{ + QDir fileSystemDir(PropertyEditorQmlBackend::propertyEditorResourcesPath()); + + static QDir resourcesDir(resourcePropertyEditorPath); + QDir importDir(info.importDirectoryPath() + QLatin1String(Constants::QML_DESIGNER_SUBFOLDER)); + + const QString versionString = QLatin1String("_") + QString::number(info.majorVersion()) + + QLatin1String("_") + + QString::number(info.minorVersion()); + + QString relativePathWithoutEnding = relativePath; + relativePathWithoutEnding.chop(4); + const QString relativePathWithVersion = relativePathWithoutEnding + versionString + QLatin1String(".qml"); + + //Check for qml files with versions first + const QString withoutDirWithVersion = relativePathWithVersion.split(QLatin1String("/")).last(); + if (importDir.exists(relativePathWithVersion)) + return importDir.absoluteFilePath(relativePathWithVersion); + if (importDir.exists(withoutDirWithVersion)) //Since we are in a subfolder of the import we do not require the directory + return importDir.absoluteFilePath(withoutDirWithVersion); + if (fileSystemDir.exists(relativePathWithVersion)) + return fileSystemDir.absoluteFilePath(relativePathWithVersion); + if (resourcesDir.exists(relativePathWithVersion)) + return resourcesDir.absoluteFilePath(relativePathWithVersion); + + const QString withoutDir = relativePath.split(QLatin1String("/")).last(); + if (importDir.exists(relativePath)) + return importDir.absoluteFilePath(relativePath); + if (importDir.exists(withoutDir)) //Since we are in a subfolder of the import we do not require the directory + return importDir.absoluteFilePath(withoutDir); + if (fileSystemDir.exists(relativePath)) + return fileSystemDir.absoluteFilePath(relativePath); + if (resourcesDir.exists(relativePath)) + return resourcesDir.absoluteFilePath(relativePath); + + return QString(); +} + + } //QmlDesigner |