[Xcircuit-dev] On graphic elements and user interaction
Kuba Ober
kuba at mareimbrium.org
Thu Dec 9 09:11:07 PST 2010
I've been thinking of how to design the code that allows to have independent
editing contexts. The QGraphicsItem does not directly support such operation
-- each item owns an editing context that includes selection, state of user
interaction, etc.
I came up with following idea of splitting things up into a model and
a view/controller.
The model would consist of existing element classes, only that they would derive
from QGraphicsItem so that we reuse Qt's transformation, hierarchy, spatial
index and repaint handling. Those model classes would not have any code that
directly deals with user interaction, and the selection mechanism would be unused.
Each item in the model would have a list of surrogate items (one per window) --
those items would be the views/controllers, and would implement all the user interaction
functionality. In case there is no user interaction happening (no selection
or editing), the surrogates simply forward all bounding box, repaint and similar
calls to the model. During user interaction, the surrogates add their own user
interaction elements, such as visible handles, and can modify the drawing (e.g. color)
done by the model element.
The model's page and library directories would use a custom scene derived from QGraphicsScene
as the parent object. The custom scene would have a reference to a factory that can
construct surrogates for all model element classes, and it would have a reference to
surrogate scenes.
The benefits of this approach are as follows:
1. We extend beyond the single-context functionality provided by QGraphicsItem system.
There will be multiple contexts.
2. The functionality of the model classes remains simple just like it is now all of the
user interaction code is not in the model classes but in surrogate classes.
3. The per-element-class user interaction code is collected in a surrogate class, vs. being
scattered around.
Thus I will begin by moving the current element classes over to QGraphicItem and making them
model classes, and I will add shim surrogates just to handle selection. Then the interaction
code will get moved over to the surrogates. Time to get back to work ;)
Cheers, Kuba
More information about the Xcircuit-dev
mailing list