From 2fa6d31ab4dcbbba52797a8b31a483393ce1a7be Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 10 Jun 2010 13:36:45 +0200 Subject: [PATCH] QuickDesigner: Automatically use alias of namespace in Rewriter E.g. if the type of the node is 'Qt/Image', version 4, 6, search through the list of imports to find 'Qt'. If an alias for the namespace has been defined, prepend this to the element name. Reviewed-by: Erik Verbruggen --- .../designercore/model/qmltextgenerator.cpp | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/model/qmltextgenerator.cpp b/src/plugins/qmldesigner/designercore/model/qmltextgenerator.cpp index 8ad16ab0b5..f912214db8 100644 --- a/src/plugins/qmldesigner/designercore/model/qmltextgenerator.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmltextgenerator.cpp @@ -35,6 +35,7 @@ #include "nodelistproperty.h" #include "qmltextgenerator.h" #include "variantproperty.h" +#include "model.h" using namespace QmlDesigner; using namespace QmlDesigner::Internal; @@ -122,11 +123,31 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept QString QmlTextGenerator::toQml(const ModelNode &node, int indentDepth) const { QString type = node.type(); - int lastSlashIndex = type.lastIndexOf('/'); - if (lastSlashIndex != -1) - type = type.mid(lastSlashIndex + 1); + QString url; + if (type.contains('/')) { + QStringList nameComponents = type.split("/"); + url = nameComponents.first(); + type = nameComponents.last(); + } + + QString alias; + if (!url.isEmpty()) { + const QString &versionUrl = QString("%1.%2").arg(QString::number(node.majorVersion()), QString::number(node.minorVersion())); + foreach (const Import &import, node.model()->imports()) { + if (import.url() == url + && import.version() == versionUrl) { + alias = import.alias(); + break; + } + } + } + + QString result; + + if (!alias.isEmpty()) + result = alias + "."; - QString result = type; + result += type; result += QLatin1String(" {\n"); const int propertyIndentDepth = indentDepth + 4; -- 2.11.0