[Interest] QGView: placing and editing item using a tool class

Ch'Gans chgans at gna.org
Tue Jul 8 11:42:38 CEST 2014


Hi there,

I have been playing with Qt graphics view framework recently, my goal 
being to create an electronics schematics editor.
I come to you, Qt enthusiasts, with some design questions, hopefully 
someone could cast some light in here or simply share his/her experience 
on the matter.

I am after designing an extensible and flexible architecture, and right 
now I'm focused on graphically placing and editing items on a scene/view 
pair, and still allow other views to display (part of) the scene in a 
specialised way.

- Place an item:
For now I have a PlaceItemTool class that get activated via a QAction. 
Once selected, the PlaceItemTool class handles mouse events and allow 
the user to create the associated item in as many step as needed (eg. 
left-click to add points to form a polygon, right-click to finish)

- Edit an item:
For now, my item class draw itself with handles for control points when 
it is selected, and then handle mouse events to allow the user to edit 
the graphical object (by moving the control points), but i don't really 
like the solution since I end up with duplicated code in my 
PlaceItemTool class and in the item class itself.
I could easily move this code to an EditItemTool class (eg. using 
filterEvent()) and even merge this class with the PlaceItemTool, fine 
but ...

- Drawing of the items:
As my application makes use of different views for a given scene, I 
would like to let the view decide what to do with selected items: get 
them drawn the usual way or simply highlight them (eg. for a satellite 
view) or get the item drawn with the control points handles (eg. for the 
main interactive view)
I can see in the QGView class that there is a IndirectPainting flag that 
gives the view control over drawing the items (via a function member 
drawItems(painter, numItems, items, options)), this look very 
interesting to me, but this feature is marked as obsolete and the doc 
states "[It is] provided to keep old source code working. We strongly 
advise against using them in new code."

So my question is if it sounds like a good idea to go for a 
PlaceItemTool and an EditItemTool, but then what is the best way to 
control the drawing of the items if i cannot (or shouldn't) use the 
view's drawItems() function?

I would be interested to hear any advice or feedback from someone who is 
familiar with this kind of things.


Thx,
Chris

-- 
QtCreator/qmakeparser.cpp:42
////////// Parser ///////////
#define fL1S(s) QString::fromLatin1(s)
namespace { // MSVC2010 doesn't seem to know the semantics of "static"
...



More information about the Interest mailing list