forked from qt-creator/qt-creator
Fixed default property discovery for custom QML components.
Reviewed-by: Christian Kamm
This commit is contained in:
@@ -1494,6 +1494,20 @@ void Context::setProperty(const ObjectValue *object, const QString &name, const
|
||||
_properties[object].insert(name, value);
|
||||
}
|
||||
|
||||
QString Context::defaultPropertyName(const ObjectValue *object)
|
||||
{
|
||||
for (const ObjectValue *o = object; o; o = o->prototype(this)) {
|
||||
if (const ASTObjectValue *astObjValue = dynamic_cast<const ASTObjectValue *>(o)) {
|
||||
QString defaultProperty = astObjValue->defaultPropertyName();
|
||||
if (!defaultProperty.isEmpty())
|
||||
return defaultProperty;
|
||||
} else if (const QmlObjectValue *qmlValue = dynamic_cast<const QmlObjectValue *>(o)) {
|
||||
return qmlValue->defaultPropertyName();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool Context::documentImportsPlugins(const QmlJS::Document *doc) const
|
||||
{
|
||||
return _documentsImportingPlugins.contains(doc->fileName());
|
||||
@@ -2800,7 +2814,7 @@ ASTObjectValue::ASTObjectValue(UiQualifiedId *typeName,
|
||||
UiObjectInitializer *initializer,
|
||||
const QmlJS::Document *doc,
|
||||
Engine *engine)
|
||||
: ObjectValue(engine), _typeName(typeName), _initializer(initializer), _doc(doc)
|
||||
: ObjectValue(engine), _typeName(typeName), _initializer(initializer), _doc(doc), _defaultPropertyRef(0)
|
||||
{
|
||||
if (_initializer) {
|
||||
for (UiObjectMemberList *it = _initializer->members; it; it = it->next) {
|
||||
@@ -2809,6 +2823,8 @@ ASTObjectValue::ASTObjectValue(UiQualifiedId *typeName,
|
||||
if (def->type == UiPublicMember::Property && def->name && def->memberType) {
|
||||
ASTPropertyReference *ref = new ASTPropertyReference(def, _doc, engine);
|
||||
_properties.append(ref);
|
||||
if (def->defaultToken.isValid())
|
||||
_defaultPropertyRef = ref;
|
||||
} else if (def->type == UiPublicMember::Signal && def->name) {
|
||||
ASTSignalReference *ref = new ASTSignalReference(def, _doc, engine);
|
||||
_signals.append(ref);
|
||||
@@ -2846,6 +2862,16 @@ void ASTObjectValue::processMembers(MemberProcessor *processor) const
|
||||
ObjectValue::processMembers(processor);
|
||||
}
|
||||
|
||||
QString ASTObjectValue::defaultPropertyName() const
|
||||
{
|
||||
if (_defaultPropertyRef) {
|
||||
UiPublicMember *prop = _defaultPropertyRef->ast();
|
||||
if (prop && prop->name)
|
||||
return prop->name->asString();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
ASTVariableReference::ASTVariableReference(VariableDeclaration *ast, Engine *engine)
|
||||
: Reference(engine), _ast(ast)
|
||||
{
|
||||
|
||||
@@ -297,6 +297,8 @@ public:
|
||||
const Value *property(const ObjectValue *object, const QString &name) const;
|
||||
void setProperty(const ObjectValue *object, const QString &name, const Value *value);
|
||||
|
||||
QString defaultPropertyName(const ObjectValue *object);
|
||||
|
||||
bool documentImportsPlugins(const Document *doc) const;
|
||||
void setDocumentImportsPlugins(const Document *doc);
|
||||
|
||||
@@ -817,6 +819,7 @@ class QMLJS_EXPORT ASTObjectValue: public ObjectValue
|
||||
const Document *_doc;
|
||||
QList<ASTPropertyReference *> _properties;
|
||||
QList<ASTSignalReference *> _signals;
|
||||
ASTPropertyReference *_defaultPropertyRef;
|
||||
|
||||
public:
|
||||
ASTObjectValue(AST::UiQualifiedId *typeName,
|
||||
@@ -827,6 +830,8 @@ public:
|
||||
|
||||
bool getSourceLocation(QString *fileName, int *line, int *column) const;
|
||||
virtual void processMembers(MemberProcessor *processor) const;
|
||||
|
||||
QString defaultPropertyName() const;
|
||||
};
|
||||
|
||||
} } // end of namespace QmlJS::Interpreter
|
||||
|
||||
Reference in New Issue
Block a user