PDA

View Full Version : childred of a tree item held with QSharedPointer ?



jajdoo
21st August 2011, 12:49
i have a tree model, and all sorts of tree items. i want to be able to recover deleted items (say using undo command) from the tree by holding them outside of the model after they have been removed from it.

generally and Qt specifically speaking, will using a shared pointers for child items be a bad call?

on a different note, which is a better container for QSharedPointer - a QList or a QVector?

high_flyer
23rd August 2011, 10:39
A pointer to the item is not enough IMHO.
You also need its location in the hierarchy.
And you will have to supply some logic for example in a case you want to restore a certain item, which one or more parents items are also removed, or if its original location in the model has changed to to removing/adding items above it.
That is just from the top of my head, there are probably other problems as well.
I would tend to use another model, as a "mirror", in which I would hold the removed items, and probably also mirror operations on it so that the general structure of both models will stay consistant this way you have all the information of the items still.
However, this approach too, needs a very well thought through algorithm.