Commit 491bf79d authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Changed QML reading in QML designer to use the interpreter for property types.

parent 80cf9989
......@@ -302,6 +302,9 @@ bool Check::visit(UiArrayBinding *ast)
return true;
}
/// When something is changed here, also change ReadingContext::lookupProperty in
/// texttomodelmerger.cpp
/// ### Maybe put this into the context as a helper method.
const Value *Check::checkScopeObjectMember(const UiQualifiedId *id)
{
QList<const ObjectValue *> scopeObjects = _context.scopeChain().qmlScopeObjects;
......@@ -311,6 +314,9 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id)
if (! id)
return 0; // ### error?
if (! id->name) // possible after error recovery
return 0;
QString propertyName = id->name->asString();
if (propertyName == QLatin1String("id") && ! id->next)
......
......@@ -111,6 +111,9 @@ public:
: m_name(name)
{}
QString name() const
{ return m_name; }
void addKey(const QString &key, int value)
{ m_keys.append(key); m_values.append(value); }
......@@ -197,7 +200,9 @@ class FakeMetaObject {
const FakeMetaObject *m_super;
QString m_superName;
QList<FakeMetaEnum> m_enums;
QHash<QString, int> m_enumNameToIndex;
QList<FakeMetaProperty> m_props;
QHash<QString, int> m_propNameToIdx;
QList<FakeMetaMethod> m_methods;
QString m_defaultPropertyName;
......@@ -221,22 +226,26 @@ public:
{ return m_package; }
void addEnum(const FakeMetaEnum &fakeEnum)
{ m_enums.append(fakeEnum); }
{ m_enumNameToIndex.insert(fakeEnum.name(), m_enums.size()); m_enums.append(fakeEnum); }
int enumeratorCount() const
{ return m_enums.size(); }
int enumeratorOffset() const
{ return 0; }
FakeMetaEnum enumerator(int index) const
{ return m_enums.at(index); }
int enumeratorIndex(const QString &name) const
{ return m_enumNameToIndex.value(name, -1); }
void addProperty(const FakeMetaProperty &property)
{ m_props.append(property); }
{ m_propNameToIdx.insert(property.name(), m_props.size()); m_props.append(property); }
int propertyCount() const
{ return m_props.size(); }
int propertyOffset() const
{ return 0; }
FakeMetaProperty property(int index) const
{ return m_props.at(index); }
int propertyIndex(const QString &name) const
{ return m_propNameToIdx.value(name, -1); }
void addMethod(const FakeMetaMethod &method)
{ m_methods.append(method); }
......@@ -686,11 +695,6 @@ QmlObjectValue::QmlObjectValue(const FakeMetaObject *metaObject, Engine *engine)
QmlObjectValue::~QmlObjectValue()
{}
const Value *QmlObjectValue::lookupMember(const QString &name, Context *context) const
{
return ObjectValue::lookupMember(name, context);
}
const Value *QmlObjectValue::findOrCreateSignature(int index, const FakeMetaMethod &method, QString *methodName) const
{
*methodName = method.methodName();
......@@ -844,6 +848,22 @@ int QmlObjectValue::minorVersion() const
QString QmlObjectValue::defaultPropertyName() const
{ return _metaObject->defaultPropertyName(); }
QString QmlObjectValue::propertyType(const QString &propertyName) const
{
for (const FakeMetaObject *iter = _metaObject; iter; iter = iter->superClass()) {
int propIdx = _metaObject->propertyIndex(propertyName);
if (propIdx != -1) {
return _metaObject->property(propIdx).typeName();
}
}
return QString();
}
bool QmlObjectValue::isEnum(const QString &typeName) const
{
return _metaObject->enumeratorIndex(typeName) != -1;
}
bool QmlObjectValue::isDerivedFrom(const FakeMetaObject *base) const
{
for (const FakeMetaObject *iter = _metaObject; iter; iter = iter->superClass()) {
......@@ -1646,7 +1666,7 @@ void ObjectValue::processMembers(MemberProcessor *processor) const
}
}
const Value *ObjectValue::lookupMember(const QString &name, Context *context) const
const Value *ObjectValue::lookupMember(const QString &name, Context *context, bool examinePrototypes) const
{
if (const Value *m = _members.value(name))
return m;
......@@ -1657,10 +1677,12 @@ const Value *ObjectValue::lookupMember(const QString &name, Context *context) co
return slowLookup.value();
}
const ObjectValue *prototypeObject = prototype(context);
if (prototypeObject) {
if (const Value *m = prototypeObject->lookupMember(name, context))
return m;
if (examinePrototypes) {
const ObjectValue *prototypeObject = prototype(context);
if (prototypeObject) {
if (const Value *m = prototypeObject->lookupMember(name, context))
return m;
}
}
return 0;
......
......@@ -385,7 +385,7 @@ public:
virtual void setProperty(const QString &name, const Value *value);
virtual void removeProperty(const QString &name);
virtual const Value *lookupMember(const QString &name, Context *context) const;
virtual const Value *lookupMember(const QString &name, Context *context, bool examinePrototypes = true) const;
// Value interface
virtual const ObjectValue *asObjectValue() const;
......@@ -410,7 +410,6 @@ public:
QmlObjectValue(const FakeMetaObject *metaObject, Engine *engine);
virtual ~QmlObjectValue();
virtual const Value *lookupMember(const QString &name, Context *context) const;
virtual void processMembers(MemberProcessor *processor) const;
const Value *propertyValue(const FakeMetaProperty &prop) const;
......@@ -418,6 +417,8 @@ public:
int majorVersion() const;
int minorVersion() const;
QString defaultPropertyName() const;
QString propertyType(const QString &propertyName) const;
bool isEnum(const QString &typeName) const;
protected:
const Value *findOrCreateSignature(int index, const FakeMetaMethod &method, QString *methodName) const;
......
......@@ -42,8 +42,8 @@ class CORESHARED_EXPORT RewriterView;
namespace Internal {
struct ReadingContext;
class DifferenceHandler;
class ReadingContext;
class TextToModelMerger
{
......@@ -82,8 +82,7 @@ public:
ReadingContext *context,
DifferenceHandler &differenceHandler);
void syncVariantProperty(AbstractProperty &modelProperty,
const QString &astName,
const QString &astValue,
const QVariant &astValue,
const QString &astType,
DifferenceHandler &differenceHandler);
void syncNodeListProperty(NodeListProperty &modelListProperty,
......@@ -96,10 +95,6 @@ public:
QmlJS::AST::UiObjectMember *astNode,
ReadingContext *context,
DifferenceHandler &differenceHandler);
static QVariant convertToVariant(const ModelNode &node,
const QString &astName,
const QString &astValue,
const QString &astType);
private:
void setupComponent(const ModelNode &node);
......
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