PDA

View Full Version : Model, View and Proxy



No-Nonsense
20th November 2006, 18:33
I am fairly new to Qt. I have read through the Qt 4.2.1 documentation, but some questions remain:

I have some data inside a tree like this:
A
- 1
- x y z
- 2
- x y z
- a b c
- d e f
B
- 1
-x y z
C
- 1
-x y z

I want to use the MVC concept to display and edit this data in two views: one tree view and one table view:

table view:
A
- 1
- 2
B
- 1
C
- 1

list view (depending on tree view selection; here A 2 was selected by the user):
x y z
a b c
d e f

Further the tree view can be hidden and the table view should show all data in a flat view:
A 1 x y z
A 2 x y z
A 2 a b c
A 2 d e f
B 1 x y z
C 1 x y z

How would I implement this correctly?

- Do I implement two models, one for the tree view and one for the table view or do I implement one model to access all data and two proxies filtering the data needed for each view?

- Would I add another filtering proxy to the table view that filters the rows based on if the tree view is shown and subclass the view to hide the first two colums if needed? Or would the proxy filter the colums also?

- How do I notify the model about changes inside the data that occured outside the MVC?

- Where would I add the editing delegates? To the model or the proxy? I only want editing to be done inside the table view. Changes to the tree view data is done internally (some buttons).

Thanks in advance, sorry for my bad english, greetings from Germany,
-Jens

e8johan
20th November 2006, 18:39
- You will need proxies to achieve all your views. Look at the proxy classes in the Qt docs and the FlaxProxy class here http://www.thorsen-consulting.dk/software.html .

- Delegates can be added to the view - so you do not have to worry about adding it to the proxy or the model.

- Changes from outside can be made by calling setData which takes care of notifying the views.

No-Nonsense
21st November 2006, 09:50
So I would implement one model and one proxy for each view and maybe a third proxy on top of the table view proxy to filter the rows (& colums)?

Regarding the filtering of columns: is this better done as proxy (I think I will need to remap the indices then?) or to subclass the view and hide (as explained in the book Practical Qt) the unneeded columns?
I imagine hiding is easyer (but not good practice) as I would not have to change which column wich delegate is used?

I do not want to to use the model when changing data from the outside of the MVC using setData. I expect there is a slot to notify the model of changes (e.g. rows, colums or whole data)?
This is because the datastructure might be used in another non Qt project and mainly because the operations on it might change the whole tree. When calling the operations from button's slots, I know if this changes one row/column, cell or if this can change the whole tree. So I could notify the model myself.

Thanks in advance,
-Jens