Planner - Brief Code Explanation ( if anybody wanna help hacking it )

Tomaz Canabrava tcanabrava at
Mon Sep 16 19:30:24 UTC 2013

So, dirk asked me to do a bit of code explanation about the planner since
it's one of the things that I really changed from the old code. All the
code for the diveplanner is in 'diveplanner.h' - as the olds asked me not
to separate the functionality one per file.

There are Three Main Classes:

 DivePlannerPointsModel,  DivePlannerGraphics and DivePlannerWidget. The
other are little helpers.

The DivePlannerPointsModel is *the* main class, the other 2 just show fancy
graphics and asks things from this class ( or set things on this class ).
When everything changes on the Widget  ( that holds the table with the dive
point information ) the model is notified, and it will signal ( something
like call a function pointer ) the widget and the graphics so they refresh

If anyone wants to change this class please study a bit about the Qt model
system before doing a change.

so, to recap: wanna change something on the profile graph? change the model.
wanna change something on the table? change the model.

The Qt Model View documentation is explained in a very detailed way at the
Qt documentation ( 'assistant' )

The DivePlannerGraphics:

it has three helpers
a Button class, that paints a pixmap onto the canvas and reacts to clicks
a Ruler class, that paints a ruller horizontaly or vertically
a Hander class, that paintss a dive depth/time coordinate.

This class reacts to keypresses and mouse movement.
Cairo devels will see that there's not a single paint call done on this
class - this is not necessary due to how QGraphicsView works, the classes
knows how to paint themselves, you just need to put them on the scene() and
set their size and position, so if you wanna change the, dunno, Handler
appearing to make it 'fade in' while added, and 'fade out' when removed,
you don't need to delete the whole scene, and repaint everything again. you
just need to make the 'DiveHandler' item fade-in and out using a QTimer /
QAnimation thingy.

The X, Y coordinates of the system are get using the Ruler size and
so, this is  how the 'Depth' ruler is created:

    depthLine = new Ruler();
        fromPercent(10, Qt::Horizontal),
        fromPercent(10, Qt::Vertical),
        fromPercent(10, Qt::Horizontal),
        fromPercent(90, Qt::Vertical)
    depthLine->setTickSize(fromPercent(1, Qt::Horizontal));

the fromPercent method will return the coordinate in the Qt::Horizontal or
Qt::Vertical horientations, at x percent, so basically I'm creating a
vertical line with 10%x to 90%x, at 10%y.

Somebody asked how to add more info on the table:
Change the model columnCount and the appropriate data() for the column.

How to modify the Table when moving a diveHandler on the Profile:
on the mouseMoveEvent, call plannerModel->setData( ) with the new data.

I'm sleepy - it's almost midnight, I hope this gives a somewhat good idea.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the subsurface mailing list