Commit 743999b8 authored by Wouter's avatar Wouter

Add embeddedTypes property, to allow metatype registration

This goes a long way to functional unions with Qt/QVariants... several
types can now store/retrieve data successfully.
parent 03675aa2
......@@ -48,6 +48,18 @@ QList< TypeReference > Array::typeReferences() const
return result;
}
QList< Type* > Array::embeddedTypes() const
{
QList<Type*> result;
if (m_itemType.type()->isIntrospected() && m_itemType.type()->isAnonymous()) {
result << m_itemType.type();
result << m_itemType.type()->embeddedTypes();
}
return result;
}
QString Array::metaType() const
{
return "array";
......
......@@ -37,6 +37,7 @@ public:
QJsonIntrospect::TypeReference itemType() const;
virtual QString metaType() const;
virtual QList< TypeReference > typeReferences() const;
virtual QList< Type* > embeddedTypes() const;
public slots:
void setItemType(const QJsonIntrospect::TypeReference& itemType);
......
......@@ -122,6 +122,21 @@ QList< InnerType* > Class::innerTypes() const
return membersSet<InnerType>();
}
QList<Type*> Class::embeddedTypes() const
{
QList<Type*> result;
Q_FOREACH(InnerType* innerType, innerTypes()) {
Type* embeddedType = innerType->innerType();
if (embeddedType->isIntrospected() && embeddedType->isAnonymous()) {
result << embeddedType;
result << embeddedType->embeddedTypes();
}
}
return result;
}
QList< Property* > Class::properties() const
{
return membersSet<Property>();
......
......@@ -104,6 +104,7 @@ public:
QList< QJsonIntrospect::Constructor* > constructors() const;
QList< QJsonIntrospect::Property* > properties() const;
QList< QJsonIntrospect::InnerType* > innerTypes() const;
virtual QList<QJsonIntrospect::Type*> embeddedTypes() const;
bool isQObject() const;
......
......@@ -258,6 +258,11 @@ QList< TypeReference > Type::typeReferences() const
return result;
}
QList<Type*> Type::embeddedTypes() const
{
return QList<Type*>();
}
void Type::loadDependencies() const
{
m_dependencies.clear();
......
......@@ -50,6 +50,7 @@ class Type: public QObject
Q_PROPERTY(QList<QJsonIntrospect::Dependency> dependencies READ dependencies)
Q_PROPERTY(QList<QJsonIntrospect::Dependency> headerDependencies READ headerDependencies STORED false)
Q_PROPERTY(QList<QJsonIntrospect::Dependency> implementationDependencies READ implementationDependencies STORED false)
Q_PROPERTY(QList<QJsonIntrospect::Type*> embeddedTypes READ embeddedTypes STORED false)
Q_PROPERTY(QStringList namespaces READ namespaces)
Q_PROPERTY(QString className READ className)
......@@ -199,6 +200,14 @@ public:
*/
virtual QList<TypeReference> typeReferences() const;
/**
* Get a list of embedded types (recursive) inside this type.
*
* This lists introspected types which are a subtype of this type. The default implementation
* returns an empty list.
*/
virtual QList<Type*> embeddedTypes() const;
/**
* Get a list of dependencies.
*/
......
......@@ -56,6 +56,20 @@ QList< QJsonIntrospect::TypeReference > UnionType::typeReferences() const
return result;
}
QList<Type*> UnionType::embeddedTypes() const
{
QList<Type*> result;
Q_FOREACH(Type* embeddedType, variants()) {
if (embeddedType->isIntrospected() && embeddedType->isAnonymous()) {
result << embeddedType;
result << embeddedType->embeddedTypes();
}
}
return result;
}
QString UnionType::metaType() const
{
return "union";
......
......@@ -29,6 +29,7 @@ class UnionType : public Type
Q_OBJECT
Q_PROPERTY(QList<QJsonIntrospect::Type*> variants READ variants);
Q_PROPERTY(QList<QJsonIntrospect::Type*> embeddedTypes READ embeddedTypes STORED false);
private:
QList<Type*> m_variants;
......@@ -42,6 +43,7 @@ public:
virtual QString metaType() const;
QList<Type*> variants() const;
virtual QList<Type*> embeddedTypes() const;
virtual ~UnionType();
......
......@@ -49,3 +49,7 @@ class AbstractWrapper {
}
{% endblock %}
{% block metasystem %}
{# Keep empty #}
{% endblock %}
......@@ -24,6 +24,7 @@
{% endblock %}
{% block includes %}
#include <QtCore/QMetaType>
{% with class.headerDependencies as dependencies %}{% include "includes.inc" %}{% endwith %}
{% endblock %}
......@@ -37,5 +38,19 @@ namespace {{ class.namespaces|join:"::" }} {
} // Namespace {{ class.namespaces|join:"::" }}
{% endblock %}
{% block metasystem %}
{% if not class.isQObject %}
Q_DECLARE_METATYPE({{ class.fullName }});
{% endif %}
{% for embeddedType in class.embeddedTypes %}
{% if embeddedType.isIntrospected %}
{% ifnotequal embeddedType.metaType "array" %}{# Arrays are typedef-ed QLists; they should not be registered. #}
Q_DECLARE_METATYPE({{ embeddedType.fullName }});
{% endifnotequal %}
{% endif %}
{% endfor %}
{% endblock %}
{% block guardclose %}#endif{% endblock %}
{% endfilter %}
......@@ -15,7 +15,17 @@
{
}
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
{{ class.fullName }}::{{ class.className }}(const {{ variant.fullName }}& value)
: m_value(QVariant::fromValue(value))
{
}
{% endifnotequal %}
{% endfor %}
{{ class.fullName }} {{ class.fullName }}::fromVariant(const QVariant &value)
{
// TODO
return {{ class.fullName }}();
}
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