PDA

View Full Version : Proper Setup for Using the Graphics View Framework



Wazman
26th January 2010, 17:28
I would like to create a 2D Plotter that allows a user to plot various items (Position, lines, etc) on a map of the world. I'm concerned about the organization of where to put the attributes a features of this application.

I need to give the user the ability to control the zoom (in/out) of the scene, Capturing a image of the plot and saving it to either a file or printing it. The user must be also able to interact with the plot via the mouse.

Should I put the zoom functionality into the reimplemented QGraphicsView or instead the QGraphicsScene. The same for printing/saving the plot.

I have a feeling that I need to handle the mouse interaction in my object that reimplements the QGraphicScene but handling the mouse events do I need to use QGraphicsSceneMouseEvent instead of QMouseEvent?

I'm using the Qt 4.6.1 Version (Its great btw) but I've also noticed that the class QMatrix is now listed as being obsolete with the recommendation not to use it. But there are functions throughout the Graphics View Framework that seem to rely on it.

Thank you for your time

Wazman
26th January 2010, 18:17
I've done some more research and it appears that I should do the zoom (in/out) in the class reimplented from QGraphicsView and Printing is best implemented from QGraphicsView. But I'm still concerned about making new code that relys on using QMatrix class is there recommended replacement.

Wazman
26th January 2010, 20:28
Please any help would be appreciated.

ecanela
27th January 2010, 04:02
i have similar situation, i delegate the funtions as follow.

thing to do in the QGraphicsScene
- Save / load plot
- create the plot

things to do in the QGraphicsView
- zooming and affine tranformations
- management of items selection
- printing plot.

printing can be done in the scene or the view. only try to be consistent in the assigment.
try not print all plot in the scene and print current selection in views.

QMatrix is obsolete, QTransform is the recommended class to tranformation. QGraphicsView have function has QMatrix based function, but is prefered using the QTransform version. intead of matrix() use transform().

dchow
28th January 2010, 01:07
The way I'd think about how to organize your functions, is to think about what difference between the QGraphicsScene and the QGraphicsView. The QGraphicsScene contains the actual canvas that you are drawing. In your case it would be the map of the world and the other graphical items. The QGraphicsView is like the window into your scene, so with this thinking Zooming and Panning would be handled in the View.

As for printing/saving, as ecanela said, they can be handled in either the scene or the view. However, if you handle it in the view remember that unless you add special code, it will only print/save what is currently being viewed in the View. If you handle printing/saving in the scene, then the entire scene will be printed/saved.

For mouse interactions, you can override the mouseMoveEvent, mousePressEvent and mouseReleaseEvent in either the QGraphicsView or QGraphicsScene. Depending on what you're doing it might be easier and better organized if you can handle it in the widgets/items that you are drawing.

Lastly, if you are just doing simple zoom in/out, try using QGraphicsView::scale. This way, you won't need to worry about playing with the transformation matrix.

Good Luck!