PDA

View Full Version : Model View Help Please



munna
20th July 2006, 19:05
Hi,

I am a complete newbie to this, so please bear with me if I ask some stupid questions.

1. I am having a application in which i need to read/write data from 10 tables from a database in order to show/edit data in the view. My doubt is, will I need to have 10 (one for each table) objects of QAbstractItemModel simultaneuosly in order to read/write from them ?

2. The view is not the usual table or tree but is combination of QLineEdit, QTextEdit, QLabel..ect. How can these widgets communicate with the model ?

3. How can I implement undo/redo using MVC ? Some tutorial or link would be great.

Thanks a lot.

aMan
20th July 2006, 19:26
@1
http://doc.trolltech.com/4.1/qsqlquerymodel.html

you have to subclass qsqlquerymodel. see the above page for details..

@2, 3
dunno, but i'm interested into it..

edit:
for 2 you probably have to use the delegate system.
http://doc.trolltech.com/4.1/model-view-delegate.html


regards..
aman..

wysota
22nd July 2006, 18:19
1. I am having a application in which i need to read/write data from 10 tables from a database in order to show/edit data in the view. My doubt is, will I need to have 10 (one for each table) objects of QAbstractItemModel simultaneuosly in order to read/write from them ?
It depends if they are related to each other. If you have a complex requirements, I'd suggest subclassing QAbstractTableModel instead of QSqlQueryModel as suggested above as this will give you more control and flexibility.



2. The view is not the usual table or tree but is combination of QLineEdit, QTextEdit, QLabel..ect. How can these widgets communicate with the model ?
With Qt4.2+ there is a specialised class called QDataWidgetMapper for that. For earlier versions you have to implement that functionality yourself using signals and slots.


3. How can I implement undo/redo using MVC ? Some tutorial or link would be great.
Once again, Qt 4.2 provides a framework for undo/redo. If you have access to Qt Solutions, there is a solution for for undo/redo too. If you wish to implement it yourself, I'd suggest connecting to dataChanged signal in the model or subclassing the model and implementing the functionality in reimplemented setData, insertRow and removeRow.