Commit 63be2e3c authored by Wouter Haffmans's avatar Wouter Haffmans
Browse files

Add some support for virtual inheritance

parent 656dcba3
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -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
    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;
+2 −2
Original line number Original line Diff line number Diff line
@@ -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);
    }
    }
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -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);


+3 −2
Original line number Original line Diff line number Diff line
@@ -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
    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);
}
}


+7 −2
Original line number Original line Diff line number Diff line
@@ -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;


@@ -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)
    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)
Loading