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
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) {
Type *baseType = m_typeRegistry->find(base, result->namespaces());
if (baseType) {
Class *baseClass = dynamic_cast<Class*>(baseType);
result->addInheritance(Type::Public, baseType->fullName());
if (result->isQObject()) {
ctor->addInitializer(baseType, "parent");
result->addInheritance(Type::Public, baseType->fullName(), !firstQObject);
firstQObject = false;
}
else {
ctor->addInitializer(baseType, "");
result->addInheritance(Type::Public, baseType->fullName());
}
}
else {
......@@ -1084,7 +1087,7 @@ UnionType* Introspector::introspectUnion(const QString& id, const QVariantMap& d
Q_FOREACH(QVariant v, typeList) {
QVariantMap typeMap = v.toMap();
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) {
variants << variant;
......
......@@ -189,11 +189,11 @@ QString Class::metaType() const
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());
if (t && t->isValid()) {
Type::addInheritance(protectionLevel, t);
Type::addInheritance(protectionLevel, t, virtualInheritance);
}
}
......
......@@ -87,7 +87,7 @@ public slots:
* This will find the type by name and add it as inherited item. It will
* 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);
......
......@@ -225,7 +225,7 @@ Type::InheritanceList Type::inheritance() const
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->isValid());
......@@ -234,6 +234,7 @@ void Type::addInheritance(Type::ProtectionLevel protectionLevel, Type* baseClass
item.protectionLevel = protectionLevel;
item.name = baseClass->fullName();
item.type = baseClass;
item.isVirtual = virtualInheritance;
m_inheritance.append(item);
}
......
......@@ -84,12 +84,14 @@ public:
Public = 4,
PublicSlot = 5,
Signal = 6,
Virtual = 7, // Used for virtual inheritance
};
struct Inheritance {
Type::ProtectionLevel protectionLevel;
QString name;
Type *type;
bool isVirtual;
};
typedef QList< Inheritance > InheritanceList;
......@@ -232,7 +234,7 @@ public slots:
void setTypeInfo(TypeInfo option, bool value);
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);
};
......@@ -290,6 +292,9 @@ GRANTLEE_BEGIN_LOOKUP(QJsonIntrospect::Type::Inheritance)
else if (property == "type") {
return QVariant::fromValue(object.type);
}
else if (property == "virtual" || property == "isVirtual") {
return object.isVirtual;
}
GRANTLEE_END_LOOKUP
GRANTLEE_BEGIN_LOOKUP(QJsonIntrospect::Dependency)
......
......@@ -37,7 +37,9 @@ class AbstractWrapper {
/**
* Check if the current value is valid.
*/
virtual bool isValid();
virtual bool isValid() {
return true;
};
/**
* 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