PDA

View Full Version : How to map datitmes to qgraphicsscene



corrado1972
30th May 2011, 11:15
I'm facing for the first time this kind of problem: my input data are datetime events, and I have to draw they into a qgraphicsscene. In the diagramscene demo application I found all the basics to start drawing, but I didn't realize how to convert datetime events to x and y coordinates into scene.

If I have a qgraphicsscene that is 3000x3000 pixels wide, and a datetime interval that is three day long with some events inside, how could i translate this temporal coordinates to x and y ?

joyer83
30th May 2011, 12:33
Err, well, how about if you convert the the datetime to seconds and then use the seconds as a coordinate value?
Something like this:


QDateTime intervalStart = /* some start date time value */;
QDateTime intervalEnd = intervalStart.addDays( 3 );
int maxTimeLength = intervalStart.secsTo( intervalEnd );
int maxPixelLength = 3000;
double pixelPerSecond = (double)maxPixelLength / maxTimeLength;
// then convert each event's time to x-coordinate as pixels
someEventCoordinateX = intervalStart.secsTo( someEventDateTime ) * pixelPerSecond;