Grantlee gets enum support

While at Akademy I have been doing some Grantlee work on adding support for enumerations in string templates.

This was some fun stuff digging into the possibilities in QMetaEnum and using some undocumented API for supporting enums in the Qt namespace.

The resulting possibilities are already in the Grantlee API documentation.

  {% ifequal document.alignment Qt.AlignRight %} 
    Right aligned 
  {% endifequal %}

  {% ifequal MyClass.Thing2 %} 
    Is Thing2
  {% endifequal %}

  Alignment is {{ document.alignment.key }}. // Outputs "Alignment is AlignRight", for example.

This is a feature it would be nice to see in QML. Hopefully I can convince the QML developers to add enum support.

One Response to “Grantlee gets enum support”

  1. Grantlee version 0.1.2 now available « Steveire’s Blog Says:

    […] Steveire’s Blog Just another weblog « Grantlee gets enum support […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: