QmlPuppet: Move fixResourcePaths to QmlPrivateGate

Change-Id: I9bbd22c19df64d3cfda3bbf02d9c72da5c2a0542
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Thomas Hartmann
2015-05-19 10:54:16 +02:00
committed by Thomas Hartmann
parent c4489a19b4
commit a02438a44f
5 changed files with 55 additions and 56 deletions

View File

@@ -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));
}
}

View File

@@ -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<Enumeration>())
adjustedValue = convertEnumToValue(value, name);
else
adjustedValue = fixResourcePaths(value);
adjustedValue = QmlPrivateGate::fixResourcePaths(value);
QVariant oldValue = property.read();

View File

@@ -184,8 +184,6 @@ public:
virtual void setNodeSource(const QString &source);
static QVariant fixResourcePaths(const QVariant &value);
virtual void updateAllDirtyNodesRecursive();
virtual PropertyNameList ignoredProperties() const;

View File

@@ -36,6 +36,7 @@
#include <QQuickItem>
#include <QQmlComponent>
#include <QFileInfo>
#include <private/qquicktransition_p.h>
#include <private/qquickanimation_p.h>
@@ -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;

View File

@@ -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