From a02438a44f14e284aaab45faecfce5823553aa35 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 19 May 2015 10:54:16 +0200 Subject: [PATCH] QmlPuppet: Move fixResourcePaths to QmlPrivateGate Change-Id: I9bbd22c19df64d3cfda3bbf02d9c72da5c2a0542 Reviewed-by: Tim Jenssen --- .../instances/nodeinstanceserver.cpp | 2 +- .../instances/objectnodeinstance.cpp | 52 +----------------- .../qml2puppet/instances/objectnodeinstance.h | 2 - .../qmlprivategate/qmlprivategate.cpp | 53 ++++++++++++++++++- .../qmlpuppet/qmlprivategate/qmlprivategate.h | 2 +- 5 files changed, 55 insertions(+), 56 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp index ba31cd6a282..3158819a651 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp @@ -872,7 +872,7 @@ void NodeInstanceServer::setInstancePropertyVariant(const PropertyValueContainer } if (valueContainer.isDynamic() && valueContainer.instanceId() == 0 && engine()) - rootContext()->setContextProperty(name, Internal::ObjectNodeInstance::fixResourcePaths(value)); + rootContext()->setContextProperty(name, Internal::QmlPrivateGate::fixResourcePaths(value)); } } diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp index 43b4a20163d..6963755b274 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp @@ -377,56 +377,6 @@ QVariant ObjectNodeInstance::convertSpecialCharacter(const QVariant& value) cons return specialCharacterConvertedValue; } - -QVariant ObjectNodeInstance::fixResourcePaths(const QVariant &value) -{ - if (value.type() == QVariant::Url) - { - const QUrl url = value.toUrl(); - if (url.scheme() == QLatin1String("qrc")) { - const QString path = QLatin1String("qrc:") + url.path(); - QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS"); - if (!qrcSearchPath.isEmpty()) { - const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';')); - foreach (const QString &qrcPath, searchPaths) { - const QStringList qrcDefintion = qrcPath.split(QLatin1Char('=')); - if (qrcDefintion.count() == 2) { - QString fixedPath = path; - fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/')); - if (QFileInfo(fixedPath).exists()) { - fixedPath.replace(QLatin1String("//"), QLatin1String("/")); - fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/')); - return QUrl(fixedPath); - } - } - } - } - } - } - if (value.type() == QVariant::String) { - const QString str = value.toString(); - if (str.contains(QLatin1String("qrc:"))) { - QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS"); - if (!qrcSearchPath.isEmpty()) { - const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';')); - foreach (const QString &qrcPath, searchPaths) { - const QStringList qrcDefintion = qrcPath.split(QLatin1Char('=')); - if (qrcDefintion.count() == 2) { - QString fixedPath = str; - fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/')); - if (QFileInfo(fixedPath).exists()) { - fixedPath.replace(QLatin1String("//"), QLatin1String("/")); - fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/')); - return fixedPath; - } - } - } - } - } - } - return value; -} - void ObjectNodeInstance::updateAllDirtyNodesRecursive() { } @@ -469,7 +419,7 @@ void ObjectNodeInstance::setPropertyVariant(const PropertyName &name, const QVar if (value.canConvert()) adjustedValue = convertEnumToValue(value, name); else - adjustedValue = fixResourcePaths(value); + adjustedValue = QmlPrivateGate::fixResourcePaths(value); QVariant oldValue = property.read(); diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.h index 6d53c9cddf3..50d254e7708 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.h @@ -184,8 +184,6 @@ public: virtual void setNodeSource(const QString &source); - static QVariant fixResourcePaths(const QVariant &value); - virtual void updateAllDirtyNodesRecursive(); virtual PropertyNameList ignoredProperties() const; diff --git a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.cpp b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.cpp index 98552dd830d..e7972357faf 100644 --- a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.cpp +++ b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -233,7 +234,7 @@ static void fixResourcePathsForObject(QObject *object) QQmlProperty property(object, propertyName, QQmlEngine::contextForObject(object)); const QVariant value = property.read(); - const QVariant fixedValue = ObjectNodeInstance::fixResourcePaths(value); + const QVariant fixedValue = fixResourcePaths(value); if (value != fixedValue) { property.write(fixedValue); } @@ -370,6 +371,56 @@ QObject *createPrimitive(const QString &typeName, int majorNumber, int minorNumb return object; } +QVariant fixResourcePaths(const QVariant &value) +{ + if (value.type() == QVariant::Url) + { + const QUrl url = value.toUrl(); + if (url.scheme() == QLatin1String("qrc")) { + const QString path = QLatin1String("qrc:") + url.path(); + QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS"); + if (!qrcSearchPath.isEmpty()) { + const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';')); + foreach (const QString &qrcPath, searchPaths) { + const QStringList qrcDefintion = qrcPath.split(QLatin1Char('=')); + if (qrcDefintion.count() == 2) { + QString fixedPath = path; + fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/')); + if (QFileInfo(fixedPath).exists()) { + fixedPath.replace(QLatin1String("//"), QLatin1String("/")); + fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/')); + return QUrl(fixedPath); + } + } + } + } + } + } + if (value.type() == QVariant::String) { + const QString str = value.toString(); + if (str.contains(QLatin1String("qrc:"))) { + QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS"); + if (!qrcSearchPath.isEmpty()) { + const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';')); + foreach (const QString &qrcPath, searchPaths) { + const QStringList qrcDefintion = qrcPath.split(QLatin1Char('=')); + if (qrcDefintion.count() == 2) { + QString fixedPath = str; + fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/')); + if (QFileInfo(fixedPath).exists()) { + fixedPath.replace(QLatin1String("//"), QLatin1String("/")); + fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/')); + return fixedPath; + } + } + } + } + } + } + return value; +} + + QObject *createComponent(const QUrl &componentUrl, QQmlContext *context) { ComponentCompleteDisabler disableComponentComplete; diff --git a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.h b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.h index 5e5c6f9d079..4244e244e3e 100644 --- a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.h +++ b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate.h @@ -67,6 +67,7 @@ public: void readPropertyValue(QObject *object, const QByteArray &propertyName, QQmlContext *qmlContext, bool *ok); void createNewDynamicProperty(const ObjectNodeInstancePointer &nodeInstance, const QString &name); void registerNodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance); + QVariant fixResourcePaths(const QVariant &value); QObject *createPrimitive(const QString &typeName, int majorNumber, int minorNumber, QQmlContext *context); QObject *createComponent(const QUrl &componentUrl, QQmlContext *context); void tweakObjects(QObject *object); @@ -78,7 +79,6 @@ public: const PropertyName &baseName = PropertyName(), QObjectList *inspectedObjects = 0); - } // namespace QmlPrivateGate } // namespace Internal } // namespace QmlDesigner