Commit 7a5cce92 authored by Thomas Hartmann's avatar Thomas Hartmann

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: default avatarMarco Bubke <marco.bubke@digia.com>
parent a01f70c0
......@@ -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
......@@ -63,8 +63,16 @@ public:
PropertyEditorValue *propertyValueForName(const QString &propertyName);
static QString propertyEditorResourcesPath();
static QString templateGeneration(NodeMetaInfo type, NodeMetaInfo superType,
const QmlObjectNode &objectNode);
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 QString fixTypeNameForPanes(const QString &typeName);
private:
void createPropertyEditorValue(const QmlObjectNode &qmlObjectNode,
......
......@@ -118,11 +118,7 @@ private slots:
void setupPanes();
private: //functions
QString qmlFileName(const NodeMetaInfo &nodeInfo) const;
QUrl fileToUrl(const QString &filePath) const;
QString fileFromUrl(const QUrl &url) const;
QUrl qmlForNode(const ModelNode &modelNode, TypeName &className) const;
QString locateQmlFile(const NodeMetaInfo &info, const QString &relativePath) const;
void select(const ModelNode& node);
void delayedResetView();
......@@ -134,8 +130,8 @@ private: //variables
int m_timerId;
PropertyEditorWidget* m_stackedWidget;
QString m_qmlDir;
QHash<QString, PropertyEditorQmlBackend *> m_typeHash;
PropertyEditorQmlBackend *m_currentType;
QHash<QString, PropertyEditorQmlBackend *> m_qmlBackendHash;
PropertyEditorQmlBackend *m_qmlBackEndForCurrentType;
bool m_locked;
bool m_setupCompleted;
QTimer *m_singleShotTimer;
......
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