Commit 2fa6d31a authored by Kai Koehne's avatar Kai Koehne
Browse files

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
parent 644f9848
......@@ -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;
......
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