Commit 8723da0f authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.rewriterView: adding convertTypeToImportAlias()

We need this function to handle alias imports.
parent 70ffe0c2
......@@ -187,6 +187,8 @@ public:
QmlJS::LookupContext *lookupContext() const;
QmlJS::Document *document() const;
QString convertTypeToImportAlias(const QString &type) const;
bool checkSemanticErrors() const
{ return m_checkErrors; }
......
......@@ -629,6 +629,53 @@ QmlJS::Document *RewriterView::document() const
return textToModelMerger()->document();
}
static inline QString getUrlFromType(const QString& typeName)
{
QStringList nameComponents = typeName.split('.');
QString result;
for (int i = 0; i < (nameComponents.count() - 1); i++) {
result += nameComponents.at(i);
}
return result;
}
QString RewriterView::convertTypeToImportAlias(const QString &type) const
{
QString url;
QString simplifiedType = type;
if (type.contains('.')) {
QStringList nameComponents = type.split('.');
url = getUrlFromType(type);
simplifiedType = nameComponents.last();
}
QString alias;
if (!url.isEmpty()) {
foreach (const Import &import, model()->imports()) {
if (import.url() == url) {
alias = import.alias();
break;
}
if (import.file() == url) {
alias = import.alias();
break;
}
}
}
QString result;
if (!alias.isEmpty())
result = alias + '.';
result += simplifiedType;
return result;
}
void RewriterView::qmlTextChanged()
{
if (inErrorState())
......
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