PDA

View Full Version : Modify model data in QTreeView



YuriyRusinov
26th October 2006, 12:19
Hello !

I subclassed QItemDelegate, QAbstractItemModel in order to build tree model and see data in QTreeView. Now I need to modify model data, do I have to subclass QTreeView or I can achive it using QTreeView ?

patrik08
26th October 2006, 12:44
Hello !

I subclassed QItemDelegate, QAbstractItemModel in order to build tree model and see data in QTreeView. Now I need to modify model data, do I have to subclass QTreeView or I can achive it using QTreeView ?


I tested to subclass the item :-( is not easy!
I found a way to make a xml file tree unlimited .... and on a simple class i manage
the domelement & QTreeWidgetItem & the level of tree....

each new Item i add on aa QList<OneTree*> niagaratree; xxx.additem(**) an so i can interact on 2 class... on add item remove rename ecc... on QDomElement you can save all data image html page e other ..on.. QDomElement like a oracle DB :-)....

to delete on item i save the Nr of tree ... and fast save the file xml + reload the GUI whitout the delete nr..item ...

Is moore simple way... and fast....




QList<OneTree*> niagaratree;
typedef QMap<QString, QString> Treevar;

class QTreeWidget;
class QTreeWidgetItem;
class OneTree : public QObject, public Base_Function
{
Q_OBJECT

public:
OneTree( QDomElement d , QTreeWidgetItem * top , int lev );
...............
private:
.....
signals:
void SendtonewDom(int);
void SendtoParent(QString);
public slots:
void MoveToNewDest()
{
/////qDebug() << "### ONLISTER emit start " << ONLISTER;
emit SendtonewDom(ONLISTER);
}

};

YuriyRusinov
26th October 2006, 13:14
That I have to make view classes, which inherits QTreeView ?

patrik08
26th October 2006, 13:35
That I have to make view classes, which inherits QTreeView ?

??? QTreeWidget or QTreeView equal exept model ...
change the model is not evry time the better way ....
change the access mode can bring the same result.... only the way is long or briefly...

IMO: I found access is not long....

YuriyRusinov
26th October 2006, 14:00
OK, I'll process signal clicked() on QTreeView and make editor events. Thanks.

patrik08
26th October 2006, 14:57
OK, I'll process signal clicked() on QTreeView and make editor events. Thanks.


If You like grab the first structure from Tree Category

http://ppk.ciz.ch/win_build/tree_cat_memo/Tree_Cat.zip

& + the idea of class OneTree you can associate 100 of attribute each single node....

http://ppk.ciz.ch/win_build/tree_cat_memo/tree_category.png

to test right click and insert node sets...
this sample code replace on old Nested Sets mysql from an old cms Category manager... same as ....
http://www.klempert.de/nested_sets/demo/

wysota
26th October 2006, 17:28
I subclassed QItemDelegate, QAbstractItemModel in order to build tree model and see data in QTreeView. Now I need to modify model data, do I have to subclass QTreeView or I can achive it using QTreeView ?

You can achieve it with QTreeView. The view is just for displaying data and you want to change the data itself - the model. Editing model data is a responsibility of item delegate - it calls setData() on the model where appropriate, just make sure your model can handle setData() calls. If you take a look at QItemDelegate - there are createEditor, setEditorData and setModelData methods. They are responsible for edition. You can reimplement them if the default implementations don't suit your needs (but maybe they do, check that out). Just make sure data in your model is editable (return ItemIsEditable if flags() for each index you want editable) and set proper triggers in the view using QAbstractItemView::setEditTriggers().