1

My data is loaded from an XML file, and is certainly hierarchical. Adapting the data to work with Qt's Model/View framework seems to be straight forward. However, the XML nodes are not primitive objects, like numbers or strings. I like to display the data similar to the Simple Widget Mapper example. I have a form with some labels, a text field, buttons, maybe check boxes. Furthermore, items in the hierarchy view can be selected (e.g. checking check boxes), removed (close button), edited (edit button), dragged and dropped. Drag and Drop is used to manipulate (insert, move, copy) the hierarchy. What is the best practice?

So far, I see three Options:

  1. Use QDataWidgetMapper with nested widgets:

    The attributes of an XML node are listed in a single row. For each node a QDataWidgetMapper is associated with that row. The QDataWidgetMapper synchronizes the widget fields with the appropriate node values. All events, drag, and drop, selection, ... must be handled by the widgets. Widgets provide drop containers. The nested widgets represent the data hierarchy.

  2. Implement a custom QAbstractItemView, and use delegates:

    I am aiming for something like a Nassi-Shneiderman diagram. Therefore, the standard QTreeView cannot be applied. However, it should be possible to create a basic hierarchic layout inheriting QAbstractItemView. A custom delegate is used, to paint the XML data with the form widgets, and create the editors. The QAbstractItemView is responsible for drag, drop, managing the selection model, (somehow) listening to button events to remove items from the hierarchy, and to ask the delegate for an editor.

  3. Something else:

    I am far away from being a Qt guru. I welcome suggestions.

Which option is recommended? Which option do you consider less painful?

EDIT - February 21st: Does someone know, how Qt Designer is implemented? This is pretty much, what I am looking for. As in Qt Designer, I have elements (loops, conditions, actions, ...), and like to edit hierarchic processes. Some elements are containers, others are leafs. Some elements are structured horizontally, others vertically. Is Qt Designer a QGraphicsScene?

Thank you for your help, and suggestions, Marian

Marian
  • 351
  • 2
  • 12
  • 1
    None of 1 or 2 is notably better than the other, so you should choose the one that is easier to implement in your case. Also take a look at QGraphicsScene. May be it will be more convenient than option 1. – Pavel Strakhov Feb 19 '14 at 19:26
  • In that case, I would lean to option 1. I wonder, whether delegates are supposed to render complex widgets. In Qt's documentation, I've only found examples for spin boxes, combo boxes, and alike. That confuses me. I like to use Qt in the cleanest way, without hacks. However, using nested widgets does not sound so great either. – Marian Feb 20 '14 at 06:51
  • Option 2 would be preferred if any of existing view classes would suit your needs. Handling complex widget could be done at the view level (e.g. QTreeView with parent-child item relationship and simple delegates for each item). Hoewever implementing your own view requires much work. – Pavel Strakhov Feb 20 '14 at 12:09
  • I would recommend both during development. The `QAbstractItemView` gives you a 'raw' view on your model, WYSIWYG while you fix bugs in your other view or the model itself. – jtooker Nov 05 '15 at 17:33

0 Answers0