views:

203

answers:

3

I've recently begun working on a project regarding GUI building using some form of declarative language. What i mean is that i need to describe an hierarchy of objects, without specifying the type of GUI widgets that will be used to "show" that hierarchy. For example, for some existing hierarchy H, using JSON notation (or something like that):

H = 
{
    "title" : "Label_1"
    "children" : 
    [
        {
            "title" : "Label_2"
            "children": 
            [
                {
                    "title": "Field_A"
                    "type": "Integer"
                    "value": 10
                },

                {
                    "title": "Field_B"
                    "type": "String"
                    "value": "YES"
                }
            ]
         }
    ]
}

Someone could build a simple window, that would be shown to the user by pressing a button labeled "Label_1". The window could be then titled "Label_2" and have two fields labeled "Field_A" and "Field_B" accepting integer and boolean values respectively.

Someone else, could put this hierarchy on a tree list, e.g

--------------------------------------------------------
>Label_1                |
    >Label_2            |
        >Field_A        |   10
        >Field_B        |   YES

My first question is, well, do i have to build some form of a language parser to achieve something like this ? Could i use JSON then ? Though i don't need to support complex hierarchies, there is need to support mutually exclusive hierarchies (something like radio buttons enabling/disabling options). I have the feeling that it looks like some form of language parsing with a couple of operators. Don't get me wrong, i am of a Mechanical Engineering background, and i am not an experienced programmer.

Thank you in advance for your comments and help.

+4  A: 

JSON would be one choice. XML would be another -- for example, Microsoft uses XAML (an XML dialect) for exactly this purpose and the W3C has a (fairly new) Widget packaging specification (using another dialect of XML). Any of these will let you use existing parsers instead of building yet another from the ground up.

Jerry Coffin
So, i guess i am moving at the right direction then. Thank you.
GiFou
Hey, if it's about declarative / c++ / ui why did not "http://labs.trolltech.com/blogs/2009/05/13/qt-declarative-ui/" come to anybody's mind?
mlvljr
@mlvljr: the link you gave says: "we're really, really sorry, but there's nothing here."
Jerry Coffin
*amn that closing `"`! what about http://qt.nokia.com/doc/qml-snapshot/declarativeui.html?
mlvljr
A: 

What you're looking for is called QML

It's Qt's GUI declarative language based on JSON.

I'm was wondering the same thing so I started a thread to collect information on Open Source, declarative GUI languages. If you're looking for alternatives, check it out.

Evan Plaice
A: 

I am just testing QML for a real user interface environment on a C++ project based on Qt. And I think it is very powerful as a declarative language so if you already know some Qt basics you can use it.

You can build modern, professional and good-looking user interfaces very very fast. And you can also effortless connect the declarative language with your C++ code and vice versa.

msantamaria