Results 1 to 3 of 3

Thread: From item based widgets to model/view

  1. #1
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default From item based widgets to model/view

    Hi,

    I could really use some help and general guidelines on how a complex hierarchical data model should be implemented using QAbstractItemModel interface (+ proxy models?) for several different views. The current solution that we have is implemented using item based classes (QTreeWidget, QListWidget mainly). The data model is separate from the widgets and implemented using standard c++ classes, containers etc. Qt widgets are used to visualize different parts of the model, for example a QTreeWidget is used to visualize the main hierarchy and when users selects an item there another tree widget visualizes the more detailed view from that item on and so on. There are tens different view on different levels of the data model. Synchronization between data model and item based widgets is made using identifiers and/or pointers that are stored to items (for example QTreeWidgetItem) as data (item->setData(0, id, Qt::UserRole)) and so one..

    However, the trend seems to be away from the item based widgets (or has been that for a while now) and the future Qt versions are relying more and more to model/view approach (QtQuick + item models).

    I'm a bit lost with Qt's model/view framework here... Would it be a good idea to describe the whole data model with one QAbstractItemModel interface and then use several proxy models to filter data for specific views or should we have several QAbstractItemModel based models in the first place... The Qt documentation is not very clear here - all the examples are for really small and simple data sets.

    Any recommendations and/or pointers would be more than welcome!

    Thanks,
    - Timo

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: From item based widgets to model/view

    One big tree describing all your objects sure presents a fanciful idea, especially the ease with which most of the views can be ready almost instantly thanks to proxy model. However it becomes increasingly difficult to make a tree model for different object types. See, making a model for a type QList<ObjectType1> is not that difficult. Now if your objecttype1 has objecttype2 which is to be a child of a particular objecttype1, you can go ahead use the facilities of QObject and make objecttype2 child of objecttype1 or implement something like that yourself or create another node wrapper class which essentially goes ahead and dissects type of object and helps you with the index() and parent() functions.
    With the growing objectypes classes, managing this node class becomes increasingly messy. And difficult. Moreover you cannot envisage the whole program beforehand. Later, it will become a head-ache when a new type comes in.
    Having said that, it is better to have that object tree as big as possible, according to my opinion. The various classes generally interact with each other. Even if your data is outside your classes, and you interact directly with them, models need to be told with anything you changed. I wish there was a straight and correct answer to your question. I wish I knew it too.

  3. The following user says thank you to pkj for this useful post:

    timom (22nd September 2011)

  4. #3
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: From item based widgets to model/view

    Thanks for your input! I know that there are no easy solutions for complex problems.. I guess what I'm looking for is some sort of "best practices" for Qt model/view for large/complex data models. Like said earlier, the Qt documentation and examples are very very limited.

    Any idea how the whole model/view framework is going to develop in the near future? There's been a lot of talk how it's over engineered and complex and should be re-designed and simplified...

Similar Threads

  1. QT Model View - parent Item different from child
    By mromanuk in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2011, 18:21
  2. Replies: 19
    Last Post: 25th November 2010, 08:52
  3. Qcombobox and model/item based question
    By yaguis in forum Newbie
    Replies: 5
    Last Post: 7th June 2010, 01:22
  4. Replies: 1
    Last Post: 1st February 2010, 18:42
  5. Default Item View classes and returning data from model
    By xerionn in forum Qt Programming
    Replies: 8
    Last Post: 23rd April 2009, 19:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.