Commit 36ea24af authored by Wouter's avatar Wouter

Add union QVariant conversions

parent 3e00e466
......@@ -20,7 +20,12 @@ public:
// Direct members
// ===========================================================
private:
QVariant m_value;
int m_tag;
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
{{ variant.fullName }}* m_{{ variant.className }};
{% endifnotequal %}
{% endfor %}
public:
// Constructors per variant type
......@@ -37,6 +42,9 @@ public:
{% endifnotequal %}
{% endfor %}
// Destructor
virtual ~{{ class.className }}();
/**
* Construct a {{ class.className }} from QVariant data.
*
......@@ -44,4 +52,11 @@ public:
*/
static {{ class.className }} fromVariant(const QVariant &value);
virtual QVariant toVariant() const;
operator QVariant() const
{
return toVariant();
}
}; // Class {{ class.className }}
......@@ -7,25 +7,82 @@
{% endif %}
{% endfor %}
// Default constructor
{{ class.fullName }}::{{ class.className }}()
{% for base in class.inheritance %}
{% if forloop.first %}:{% else %},{% endif %} {{ base.name }}()
{% endfor %}
{
}
{% evalto initializerspretag %}
{% for base in class.inheritance %}
{% if forloop.first %}:{% else %},{% endif %} {{ base.name }}()
{% endfor %}
{% if class.inheritance %},{% else %}:{% endif %}
{% evaltosplit %}
{% evalto initializersposttag %}
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
, m_{{ variant.className }}(0)
{% endifnotequal %}
{% endfor %}
{% evaltosplit %}
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
{{ class.fullName }}::{{ class.className }}(const {{ variant.fullName }}& value)
: m_value(QVariant::fromValue(value))
// Default constructor
{{ class.fullName }}::{{ class.className }}()
{{ initializerspretag }} m_tag(-1) {{ initializersposttag }}
{
}
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
{{ class.fullName }}::{{ class.className }}(const {{ variant.fullName }}& value)
{{ initializerspretag }} m_tag({{ forloop.counter }}) {{ initializersposttag }}
{
m_{{ variant.className }} = new {{ variant.fullName }}(value);
}
{% endifnotequal %}
{% endfor %}
{% endevalto %}
{% endevalto %}
{{ class.fullName }}::~{{ class.className }}()
{
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
delete m_{{ variant.className }};
{% endifnotequal %}
{% endfor %}
}
{% endifnotequal %}
{% endfor %}
{{ class.fullName }} {{ class.fullName }}::fromVariant(const QVariant &value)
{
// TODO
return {{ class.fullName }}();
}
QVariant {{ class.fullName }}::toVariant() const
{
switch(m_tag) {
{% for variant in class.variants %}
case {{ forloop.counter }}:
// {{ variant.metaType }}
// {{ variant.fullName }}
{% switch variant.metaType %}
{% default %}
{% ifequal variant.fullName "void" %}
return QVariant();
{% else %}
return *m_{{ variant.className }};
{% endifequal %}
{% case "array" %}
{
QVariantList resultList;
Q_FOREACH(const {{ variant.itemType.type.fullName }}& m_{{ variant.className }}Item, *m_{{ variant.className }}) {
resultList << m_{{ variant.className }}Item;
}
return resultList;
}
{% endswitch %}
{% endfor %}
default:
return QVariant();
}
}
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