forked from qt-creator/qt-creator
QmlDesigner.metaInfo: resolve alias properties in the code model
Change-Id: I22b10e05163e3fa73e1fb2847552cda948e3ac4d Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
@@ -84,16 +84,53 @@ using namespace QmlJS;
|
|||||||
|
|
||||||
typedef QPair<QString, QString> PropertyInfo;
|
typedef QPair<QString, QString> PropertyInfo;
|
||||||
|
|
||||||
|
static QString resolveTypeName(const ASTPropertyReference *ref, const ContextPtr &context)
|
||||||
|
{
|
||||||
|
QString type = QLatin1String("unknown");
|
||||||
|
|
||||||
|
if (!ref->ast()->memberType.isEmpty()) {
|
||||||
|
type = ref->ast()->memberType.toString();
|
||||||
|
|
||||||
|
if (type == QLatin1String("alias")) {
|
||||||
|
const Value *value = context->lookupReference(ref);
|
||||||
|
|
||||||
|
if (!value)
|
||||||
|
return type;
|
||||||
|
|
||||||
|
if (const ASTObjectValue * astObjectValue = value->asAstObjectValue()) {
|
||||||
|
if (astObjectValue->typeName())
|
||||||
|
type = astObjectValue->typeName()->name.toString();
|
||||||
|
} else if (const ObjectValue * objectValue = value->asObjectValue()) {
|
||||||
|
type = objectValue->className();
|
||||||
|
} else if (value->asColorValue()) {
|
||||||
|
type = QLatin1String("color");
|
||||||
|
} else if (value->asUrlValue()) {
|
||||||
|
type = QLatin1String("url");
|
||||||
|
} else if (value->asStringValue()) {
|
||||||
|
type = QLatin1String("string");
|
||||||
|
} else if (value->asRealValue()) {
|
||||||
|
type = QLatin1String("real");
|
||||||
|
} else if (value->asIntValue()) {
|
||||||
|
type = QLatin1String("int");
|
||||||
|
} else if (value->asBooleanValue()) {
|
||||||
|
type = QLatin1String("boolean");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
class PropertyMemberProcessor : public MemberProcessor
|
class PropertyMemberProcessor : public MemberProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
PropertyMemberProcessor(const ContextPtr &context) : m_context(context)
|
||||||
|
{}
|
||||||
virtual bool processProperty(const QString &name, const Value *value)
|
virtual bool processProperty(const QString &name, const Value *value)
|
||||||
{
|
{
|
||||||
const ASTPropertyReference *ref = value_cast<ASTPropertyReference>(value);
|
const ASTPropertyReference *ref = value_cast<ASTPropertyReference>(value);
|
||||||
if (ref) {
|
if (ref) {
|
||||||
QString type = "unknown";
|
const QString type = resolveTypeName(ref, m_context);
|
||||||
if (!ref->ast()->memberType.isEmpty())
|
|
||||||
type = ref->ast()->memberType.toString();
|
|
||||||
m_properties.append(qMakePair(name, type));
|
m_properties.append(qMakePair(name, type));
|
||||||
} else {
|
} else {
|
||||||
if (const CppComponentValue * ov = value_cast<CppComponentValue>(value)) {
|
if (const CppComponentValue * ov = value_cast<CppComponentValue>(value)) {
|
||||||
@@ -119,6 +156,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QList<PropertyInfo> m_properties;
|
QList<PropertyInfo> m_properties;
|
||||||
|
const ContextPtr m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline bool isValueType(const QString &type)
|
static inline bool isValueType(const QString &type)
|
||||||
@@ -178,7 +216,7 @@ QList<PropertyInfo> getQmlTypes(const CppComponentValue *ov, const ContextPtr &c
|
|||||||
if (ov->className().isEmpty())
|
if (ov->className().isEmpty())
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
PropertyMemberProcessor processor;
|
PropertyMemberProcessor processor(context);
|
||||||
ov->processMembers(&processor);
|
ov->processMembers(&processor);
|
||||||
|
|
||||||
QList<PropertyInfo> newList = processor.properties();
|
QList<PropertyInfo> newList = processor.properties();
|
||||||
@@ -254,7 +292,7 @@ QList<PropertyInfo> getObjectTypes(const ObjectValue *ov, const ContextPtr &cont
|
|||||||
if (ov->className().isEmpty())
|
if (ov->className().isEmpty())
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
PropertyMemberProcessor processor;
|
PropertyMemberProcessor processor(context);
|
||||||
ov->processMembers(&processor);
|
ov->processMembers(&processor);
|
||||||
|
|
||||||
list << processor.properties();
|
list << processor.properties();
|
||||||
@@ -834,7 +872,7 @@ bool NodeMetaInfoPrivate::isValid() const
|
|||||||
QString NodeMetaInfoPrivate::propertyType(const QString &propertyName) const
|
QString NodeMetaInfoPrivate::propertyType(const QString &propertyName) const
|
||||||
{
|
{
|
||||||
if (!m_properties.contains(propertyName))
|
if (!m_properties.contains(propertyName))
|
||||||
return QString();
|
return QLatin1String("Property does not exist...");
|
||||||
return m_propertyTypes.at(m_properties.indexOf(propertyName));
|
return m_propertyTypes.at(m_properties.indexOf(propertyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user