Commit 63be2e3c authored by Wouter's avatar Wouter

Add some support for virtual inheritance

parent 656dcba3
...@@ -768,18 +768,21 @@ Class *Introspector::introspectObject(const QString& id, const QVariantMap& data ...@@ -768,18 +768,21 @@ Class *Introspector::introspectObject(const QString& id, const QVariantMap& data
bases << makeIdentifier(data.value("extends").toString()); bases << makeIdentifier(data.value("extends").toString());
} }
// Add all base classes // Add all base classes - first QObject as "normal" inheritance, others as virtual
bool firstQObject = true;
Q_FOREACH(QString base, bases) { Q_FOREACH(QString base, bases) {
Type *baseType = m_typeRegistry->find(base, result->namespaces()); Type *baseType = m_typeRegistry->find(base, result->namespaces());
if (baseType) { if (baseType) {
Class *baseClass = dynamic_cast<Class*>(baseType); Class *baseClass = dynamic_cast<Class*>(baseType);
result->addInheritance(Type::Public, baseType->fullName());
if (result->isQObject()) { if (result->isQObject()) {
ctor->addInitializer(baseType, "parent"); ctor->addInitializer(baseType, "parent");
result->addInheritance(Type::Public, baseType->fullName(), !firstQObject);
firstQObject = false;
} }
else { else {
ctor->addInitializer(baseType, ""); ctor->addInitializer(baseType, "");
result->addInheritance(Type::Public, baseType->fullName());
} }
} }
else { else {
...@@ -1084,7 +1087,7 @@ UnionType* Introspector::introspectUnion(const QString& id, const QVariantMap& d ...@@ -1084,7 +1087,7 @@ UnionType* Introspector::introspectUnion(const QString& id, const QVariantMap& d
Q_FOREACH(QVariant v, typeList) { Q_FOREACH(QVariant v, typeList) {
QVariantMap typeMap = v.toMap(); QVariantMap typeMap = v.toMap();
QString id = typeMap.value("id", QString("Variant%1").arg(i)).toString(); QString id = typeMap.value("id", QString("Variant%1").arg(i)).toString();
Type *variant = internalType(id, typeMap, result); Type *variant = internalType(id, typeMap, result, true);
if (variant) { if (variant) {
variants << variant; variants << variant;
......
...@@ -189,11 +189,11 @@ QString Class::metaType() const ...@@ -189,11 +189,11 @@ QString Class::metaType() const
return "class"; return "class";
} }
void Class::addInheritance(Type::ProtectionLevel protectionLevel, const QString& baseClassName) void Class::addInheritance(Type::ProtectionLevel protectionLevel, const QString& baseClassName, bool virtualInheritance)
{ {
Type *t = typeRegistry()->find(baseClassName, namespaces()); Type *t = typeRegistry()->find(baseClassName, namespaces());
if (t && t->isValid()) { if (t && t->isValid()) {
Type::addInheritance(protectionLevel, t); Type::addInheritance(protectionLevel, t, virtualInheritance);
} }
} }
......
...@@ -87,7 +87,7 @@ public slots: ...@@ -87,7 +87,7 @@ public slots:
* This will find the type by name and add it as inherited item. It will * This will find the type by name and add it as inherited item. It will
* scan for the type within this class's namespaces. * scan for the type within this class's namespaces.
*/ */
void addInheritance(Type::ProtectionLevel protectionLevel, const QString &baseClassName); void addInheritance(Type::ProtectionLevel protectionLevel, const QString &baseClassName, bool virtualInheritance = false);
void setSourceId(const QString &id); void setSourceId(const QString &id);
......
...@@ -225,7 +225,7 @@ Type::InheritanceList Type::inheritance() const ...@@ -225,7 +225,7 @@ Type::InheritanceList Type::inheritance() const
return m_inheritance; return m_inheritance;
} }
void Type::addInheritance(Type::ProtectionLevel protectionLevel, Type* baseClass) void Type::addInheritance(Type::ProtectionLevel protectionLevel, Type* baseClass, bool virtualInheritance)
{ {
Q_ASSERT(baseClass); Q_ASSERT(baseClass);
Q_ASSERT(baseClass->isValid()); Q_ASSERT(baseClass->isValid());
...@@ -234,6 +234,7 @@ void Type::addInheritance(Type::ProtectionLevel protectionLevel, Type* baseClass ...@@ -234,6 +234,7 @@ void Type::addInheritance(Type::ProtectionLevel protectionLevel, Type* baseClass
item.protectionLevel = protectionLevel; item.protectionLevel = protectionLevel;
item.name = baseClass->fullName(); item.name = baseClass->fullName();
item.type = baseClass; item.type = baseClass;
item.isVirtual = virtualInheritance;
m_inheritance.append(item); m_inheritance.append(item);
} }
...@@ -261,7 +262,7 @@ void Type::loadDependencies() const ...@@ -261,7 +262,7 @@ void Type::loadDependencies() const
m_dependencies.clear(); m_dependencies.clear();
QQueue<TypeReference> references; QQueue<TypeReference> references;
references << typeReferences(); references << typeReferences();
QSet<QString> processed; // reference signatures, saves us implementing qHash() and == for now QSet<QString> processed; // reference signatures, saves us implementing qHash() and == for now
while (!references.isEmpty()) { while (!references.isEmpty()) {
TypeReference reference = references.dequeue(); TypeReference reference = references.dequeue();
......
...@@ -84,12 +84,14 @@ public: ...@@ -84,12 +84,14 @@ public:
Public = 4, Public = 4,
PublicSlot = 5, PublicSlot = 5,
Signal = 6, Signal = 6,
Virtual = 7, // Used for virtual inheritance
}; };
struct Inheritance { struct Inheritance {
Type::ProtectionLevel protectionLevel; Type::ProtectionLevel protectionLevel;
QString name; QString name;
Type *type; Type *type;
bool isVirtual;
}; };
typedef QList< Inheritance > InheritanceList; typedef QList< Inheritance > InheritanceList;
...@@ -196,7 +198,7 @@ public: ...@@ -196,7 +198,7 @@ public:
* This includes all manually added references. * This includes all manually added references.
*/ */
virtual QList<TypeReference> typeReferences() const; virtual QList<TypeReference> typeReferences() const;
/** /**
* Get a list of dependencies. * Get a list of dependencies.
*/ */
...@@ -232,7 +234,7 @@ public slots: ...@@ -232,7 +234,7 @@ public slots:
void setTypeInfo(TypeInfo option, bool value); void setTypeInfo(TypeInfo option, bool value);
void setTypeInfo(TypeInfoFlags options); void setTypeInfo(TypeInfoFlags options);
void addInheritance(Type::ProtectionLevel protectionLevel, Type *baseClass); void addInheritance(Type::ProtectionLevel protectionLevel, Type *baseClass, bool virtualInheritance = false);
void addManualReference(const TypeReference &reference); void addManualReference(const TypeReference &reference);
}; };
...@@ -290,6 +292,9 @@ GRANTLEE_BEGIN_LOOKUP(QJsonIntrospect::Type::Inheritance) ...@@ -290,6 +292,9 @@ GRANTLEE_BEGIN_LOOKUP(QJsonIntrospect::Type::Inheritance)
else if (property == "type") { else if (property == "type") {
return QVariant::fromValue(object.type); return QVariant::fromValue(object.type);
} }
else if (property == "virtual" || property == "isVirtual") {
return object.isVirtual;
}
GRANTLEE_END_LOOKUP GRANTLEE_END_LOOKUP
GRANTLEE_BEGIN_LOOKUP(QJsonIntrospect::Dependency) GRANTLEE_BEGIN_LOOKUP(QJsonIntrospect::Dependency)
......
...@@ -37,7 +37,9 @@ class AbstractWrapper { ...@@ -37,7 +37,9 @@ class AbstractWrapper {
/** /**
* Check if the current value is valid. * Check if the current value is valid.
*/ */
virtual bool isValid(); virtual bool isValid() {
return true;
};
/** /**
* Assign a new value. * Assign a new value.
......
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