I have a QGraphicsScene
which displays custom objects that inherit from QGraphicsItem
. As an example, I want to display triangles that are made up like this:
struct Triangle {
Point a;
Point b;
Point c;
};
The QGraphicsItem
would look something like this:
class TriangleItem : public QGraphicsItem {
public:
Triange(QGraphicsItem* parent = 0);
...
private:
IndexTo _triangle;
};
However, I don't want to store the triangles within the QGraphicsItem directly, but rather in a std::vector
or some other contigious data structure and keep them in a centralized place. There reason for this is, that I will have a bunch of algorithms performing transformations on these triangles. Since there are many of these triangles, my algorithms should be cache efficient and the datastructure should be easily iterateable.
The QGraphicsItems
or the QGraphicsScene
would then need hold a pointer/index to the triangles in this model. The Triangles
in the scene are dynamic and can be moved/added/deleted (with the standard qt flags ItemIsSelectable
, ItemIsMoveable
). The problem is that a pointer into a std::vector
is not guaranteed to stay valid.
I think it might be awkward to make the QGraphicsScene
into an QAbstractItemView
, so I am thinking about making my own model. However I am not quite sure on how to store the triangles internally and how to keep the model and the scene synchronized. How would you do this?