QUndoStack across 2 cpps? QTreeView and QGraphicsScene
-
@StudentScripter
It seems to me you have two possible general approaches:-
Use signals & slots to communicate between the tree view and the graphics scene. This can alleviate the need for each side to know too much about the other side. But be careful not to get into an "infinite loop", where each side "ping pongs" signals between themselves for some change.
-
As @SGaist says, create a common model and share the model between both sides. For example,
QStandardItem
is part of aQStandardItemModel
. You can already have multiple views (e.g.QTreeView
) attached to the same model, make it so (some wrapper around) theQGraphicsScene
shares that model with your oneQTreeView
. All your operations, like selecting or clicking a checkbox, should be implemented in the model, not the view or scene. Then that emits signals likedataChanged()
orselectionChanged()
in response to your actions and both views get notified about it and react in their own ways. The model code can be kept in its own/class/module/file, that is included into both the tree view & graphics scene classes, they should not need to see each other directly. This would be my inclination.
wrote on 12 Jan 2024, 22:03 last edited by@JonB said in QUndoStack across 2 cpps? QTreeView and QGraphicsScene:
The model code can be kept in its own/class/module/file, that is included into both the tree view & graphics scene classes, they should not need to see each other directly. This would be my inclination.
-
-
@JonB said in QUndoStack across 2 cpps? QTreeView and QGraphicsScene:
The model code can be kept in its own/class/module/file, that is included into both the tree view & graphics scene classes, they should not need to see each other directly. This would be my inclination.
wrote on 13 Jan 2024, 09:24 last edited by@JonB Ok and from their i add an setter in the qtreeview class and the viewlayerlist to retrieve the model.
-
@JonB Ok and from their i add an setter in the qtreeview class and the viewlayerlist to retrieve the model.
wrote on 13 Jan 2024, 13:33 last edited by@StudentScripter Yes, a suitable public getter & setter for the model called from each of the
QTreeView
andQGraphicsScene
modules. -
@JonB Ok and from their i add an setter in the qtreeview class and the viewlayerlist to retrieve the model.
@StudentScripter QTreeView already has a setter for the model. You just need to add one to your QGraphicsScene subclass.
-
@StudentScripter QTreeView already has a setter for the model. You just need to add one to your QGraphicsScene subclass.
wrote on 22 Jan 2024, 20:10 last edited by@SGaist Yep done everything and works fine. :D
-
@SGaist Yep done everything and works fine. :D
@StudentScripter great !
Then please mark the model as solved using the "Topic Tools" button or the dotted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)
-