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
Re: Model "knows" the asking view
Quote:
Originally Posted by
lotek
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.
Quote:
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
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 :)
Re: Model "knows" the asking view
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.
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.