PDA

View Full Version : Model "knows" the asking view



lotek
10th November 2010, 21:58
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

tbscope
11th November 2010, 06:11
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

lotek
11th November 2010, 09:11
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 :)

tbscope
11th November 2010, 09:27
If you just want to hide a column
http://doc.qt.nokia.com/4.7/qtreeview.html#setColumnHidden

lotek
11th November 2010, 09:38
So I did. What about the performance (please see the original message)? I am going to display only few of the XXXXX columns.

ChrisW67
12th November 2010, 00:03
The view should not try to fetch the data for the columns/rows it does not need to display.