I'm working on a project that contains a QTreeWidget
. This widget will have Parent nodes with childs nodes and or other siblings nodes. Attached to each node will be a unique ID
in the form of an integer as well as a name.
Now..... what methods can or should I use to save all the nodes in the QTreeWidget
to disk and how to read them back in?????
What I would do is traverse the tree and save each node into a sqlite DB. I already can do that in exactly the same order as it is in the tree. BUT...... QTreeWidget
and its related QTreeWidgetItem
objects do NOT have a uniq index that you can USE to insert other nodes around.
When I rebuild the tree, childs have to be attached to their parents/ancestor (which by then exists in the tree). To do so I keep track of the Parents and their ID
s I already added to the tree, like (parent name, parentID
) inside an array. Note that the parentID
has nothing to do with location as a node inside the QTreeWidget
/WidgetItem
. It is created by myself and stored insite the sqlite db allong with the name of the node just as some sort of tag since QTreeWidget
/QTreeWidgetItem
does not supply any.
To determine the correct parent I
- take the
ParentID
from the sqlite DB, - search the array or the
QTreeWidget
for that sameID
, - select that parent in the
QTreeWidget
, - add the sqlite db item as a child node to the parent in the
treeview
.
But it feels clumsy this way, because of the search each time a node is added and because of a missing index inside the QTreeWidget
/WidgetItem
I can use for inserting nodes around.
I know this should be done much more elegant and less resource intensive.
I'm not looking for exact coding examples but more for ideas and hints of the methods and properties to use from QTreeWidget
and QTreeWidgetItem
.
Any ideas?