Results 1 to 6 of 6

Thread: Model "knows" the asking view

  1. #1
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post Model "knows" the asking view

    Hello,

    1)
    Is it possible, that the model "knows" which view is calling its methods (e.g. columnCount), and according to it returns different values?

    My problem is, that I'd like to apply two different (table) views on one model, but one table view shall show different columns (also column count) than the other one.

    I could hide some view columns, but I am afraid this will have negative influence on the performance. I couldn't find any statement if a hidden view column queries for data. I've check it at the moment seems OK - hidden columns are not queried but is this behavior guaranteed?

    I've also noticed that data() method is called couple of times, for different display roles. Could I inhibit this, if I know, that only one role will be use?

    How to solve this?

    2)
    The QProxyModel class is deprecated - fine, but the Class Reference does not say what class shall be used instead. Any ideas.

    Thanks for your help

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Model "knows" the asking view

    Quote Originally Posted by lotek View Post
    Hello,

    1)
    Is it possible, that the model "knows" which view is calling its methods (e.g. columnCount), and according to it returns different values?

    My problem is, that I'd like to apply two different (table) views on one model, but one table view shall show different columns (also column count) than the other one.

    I could hide some view columns, but I am afraid this will have negative influence on the performance. I couldn't find any statement if a hidden view column queries for data. I've check it at the moment seems OK - hidden columns are not queried but is this behavior guaranteed?

    I've also noticed that data() method is called couple of times, for different display roles. Could I inhibit this, if I know, that only one role will be use?

    How to solve this?
    Use either a subclassed view or a delegate.
    The model shouldn't be aware of any view at all. That's the beauty of this pattern.

    2)
    The QProxyModel class is deprecated - fine, but the Class Reference does not say what class shall be used instead. Any ideas.
    http://doc.qt.nokia.com/4.7/qabstractproxymodel.html

  3. #3
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Model "knows" the asking view

    Thank you,

    Of course you are right with the pattern.

    Considering the sub-classing of a table view - how to chose the columns being displayed? Which virtual method shall be changed? I don't like to sub-class the QAbstractItemView to get the table view

    Best regards

    me

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Model "knows" the asking view

    If you just want to hide a column
    http://doc.qt.nokia.com/4.7/qtreevie...etColumnHidden

  5. #5
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Model "knows" the asking view

    So I did. What about the performance (please see the original message)? I am going to display only few of the XXXXX columns.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Model "knows" the asking view

    The view should not try to fetch the data for the columns/rows it does not need to display.

Similar Threads

  1. Replies: 2
    Last Post: 10th November 2010, 08:25
  2. Replies: 0
    Last Post: 1st June 2010, 07:31
  3. Replies: 1
    Last Post: 7th April 2010, 22:46
  4. Adapting the "Simple DOM Model Example" to be read/write
    By joshuajcarson in forum Qt Programming
    Replies: 7
    Last Post: 8th September 2008, 21:19
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05

Tags for this Thread

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.