Results 1 to 2 of 2

Thread: Aggregating a model's data

  1. #1
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Aggregating a model's data

    I have a model that supplies a list of items.
    Each of the items has some properties.
    (So the model is a tree of depth 2. Like the widgets in designer...)

    When I select an item, in a separate view this item's properties are displayed for editing. Works like a charm.

    What I want to do now is:
    * when multiple items are selected, show the properties common to all of the selected items
    * if the a property has the same value for each item, show that value,
    * otherwise show something like "<different values>"
    (I.e. a property value is not mapped to a single item, but to a list of items!)

    So far, I have implemented a second model (on the underlying data). Works, but I am not happy with it: it is not connected to the first model and does not update itself when the underlying data is changed via the first model.
    (I can work around that. But the solution does not get more elegant from it...)

    Question:
    Is it possible (sensible) to implement that with a proxy model? I.e. can proxy models aggregate their source model's data?
    Do methods like QAbstractProxyModel::mapToSource() need to implement a 1:1 mapping? (Obviously impossible here...)

    Thank you for thinking about that problem!
    Christoph

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Aggregating a model's data

    Yes, the proxy can aggregate data provided you can map items both ways. multiple->one mapping is easy, the other way it is harder as mapToSource can't be used in a regular way, so you'll have to reimplement all virtual methods that might be using it.

Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  2. Replies: 4
    Last Post: 19th October 2007, 19:47
  3. Custom Model Class
    By mattjgalloway in forum Qt Programming
    Replies: 12
    Last Post: 4th June 2007, 17:30
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.