forked from qt-creator/qt-creator
QmlDesigner: Add lookup for alised types in NodeMetaInfo
Aliased types like T.Button require a special code path. Those lookups are only required for the rewriter and are not used by application code, since we strip the alias qualification. Change-Id: Ic74c352655e640b063bb01f03a699182af506de7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -82,6 +82,15 @@ using PropertyInfo = QPair<PropertyName, TypeName>;
|
||||
|
||||
QVector<PropertyInfo> getObjectTypes(const ObjectValue *ov, const ContextPtr &context, bool local = false, int rec = 0);
|
||||
|
||||
|
||||
static QByteArray getUnqualifiedName(const QByteArray &name)
|
||||
{
|
||||
const QList<QByteArray> nameComponents = name.split('.');
|
||||
if (nameComponents.size() < 2)
|
||||
return name;
|
||||
return nameComponents.constLast();
|
||||
}
|
||||
|
||||
static TypeName resolveTypeName(const ASTPropertyReference *ref, const ContextPtr &context, QVector<PropertyInfo> &dotProperties)
|
||||
{
|
||||
TypeName type = "unknown";
|
||||
@@ -789,22 +798,49 @@ NodeMetaInfoPrivate::NodeMetaInfoPrivate(Model *model, TypeName type, int maj, i
|
||||
} else {
|
||||
m_isFileComponent = true;
|
||||
const Imports *imports = context()->imports(document());
|
||||
const ImportInfo importInfo = imports->info(lookupNameComponent().constLast(), context().data());
|
||||
const ImportInfo importInfo = imports->info(lookupNameComponent().constLast(),
|
||||
context().data());
|
||||
|
||||
if (importInfo.isValid()) {
|
||||
if (importInfo.type() == ImportType::Library) {
|
||||
m_majorVersion = importInfo.version().majorVersion();
|
||||
m_minorVersion = importInfo.version().minorVersion();
|
||||
}
|
||||
bool prepandName = (importInfo.type() == ImportType::Library || importInfo.type() == ImportType::Directory)
|
||||
&& !m_qualfiedTypeName.contains('.');
|
||||
bool prepandName = (importInfo.type() == ImportType::Library
|
||||
|| importInfo.type() == ImportType::Directory)
|
||||
&& !m_qualfiedTypeName.contains('.');
|
||||
if (prepandName)
|
||||
m_qualfiedTypeName.prepend(importInfo.name().toUtf8() + '.');
|
||||
m_qualfiedTypeName.prepend(importInfo.name().toUtf8() + '.');
|
||||
}
|
||||
}
|
||||
m_objectValue = objectValue;
|
||||
m_defaultPropertyName = context()->defaultPropertyName(objectValue).toUtf8();
|
||||
m_isValid = true;
|
||||
setupPrototypes();
|
||||
} else {
|
||||
// Special case for aliased types for the rewriter
|
||||
|
||||
const Imports *imports = context()->imports(document());
|
||||
const ImportInfo importInfo = imports->info(QString::fromUtf8(m_qualfiedTypeName),
|
||||
context().data());
|
||||
if (importInfo.isValid()) {
|
||||
if (importInfo.type() == ImportType::Library) {
|
||||
m_majorVersion = importInfo.version().majorVersion();
|
||||
m_minorVersion = importInfo.version().minorVersion();
|
||||
}
|
||||
|
||||
m_qualfiedTypeName = getUnqualifiedName(m_qualfiedTypeName);
|
||||
|
||||
bool prepandName = (importInfo.type() == ImportType::Library
|
||||
|| importInfo.type() == ImportType::Directory);
|
||||
if (prepandName)
|
||||
m_qualfiedTypeName.prepend(importInfo.name().toUtf8() + '.');
|
||||
}
|
||||
|
||||
m_objectValue = getObjectValue();
|
||||
m_defaultPropertyName = context()->defaultPropertyName(objectValue).toUtf8();
|
||||
m_isValid = true;
|
||||
setupPrototypes();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1033,14 +1069,6 @@ bool NodeMetaInfoPrivate::isPropertyEnum(const PropertyName &propertyName) const
|
||||
return qmlObjectValue->getEnum(QString::fromUtf8(propertyType(propertyName))).isValid();
|
||||
}
|
||||
|
||||
static QByteArray getUnqualifiedName(const QByteArray &name)
|
||||
{
|
||||
const QList<QByteArray> nameComponents = name.split('.');
|
||||
if (nameComponents.size() < 2)
|
||||
return name;
|
||||
return nameComponents.constLast();
|
||||
}
|
||||
|
||||
static QByteArray getPackage(const QByteArray &name)
|
||||
{
|
||||
QList<QByteArray> nameComponents = name.split('.');
|
||||
|
Reference in New Issue
Block a user