void LineDiagram::LineDiagramType::paintValueTracker( PaintContext* ctx, const ValueTrackerAttributes& vt, const QPointF& at ) { CartesianCoordinatePlane* plane = qobject_cast<CartesianCoordinatePlane*>( ctx->coordinatePlane() ); if( !plane ) return; DataDimensionsList gridDimensions = ctx->coordinatePlane()->gridDimensionsList(); const QPointF bottomLeft( ctx->coordinatePlane()->translate( QPointF( plane->isHorizontalRangeReversed() ? gridDimensions.at( 0 ).end : gridDimensions.at( 0 ).start, plane->isVerticalRangeReversed() ? gridDimensions.at( 1 ).end : gridDimensions.at( 1 ).start ) ) ); const QPointF markerPoint = at; const QPointF ordinatePoint( bottomLeft.x(), at.y() ); const QPointF abscissaPoint( at.x(), bottomLeft.y() ); const QSizeF markerSize = vt.markerSize(); const QRectF ellipseMarker = QRectF( at.x() - markerSize.width() / 2, at.y() - markerSize.height() / 2, markerSize.width(), markerSize.height() ); const QPointF ordinateMarker[3] = { QPointF( ordinatePoint.x(), at.y() + markerSize.height() / 2 ), QPointF( ordinatePoint.x() + markerSize.width() / 2, at.y() ), QPointF( ordinatePoint.x(), at.y() - markerSize.height() / 2 ) }; const QPointF abscissaMarker[3] = { QPointF( at.x() + markerSize.width() / 2, abscissaPoint.y() ), QPointF( at.x(), abscissaPoint.y() - markerSize.height() / 2 ), QPointF( at.x() - markerSize.width() / 2, abscissaPoint.y() ) }; QPointF topLeft = ordinatePoint; QPointF bottomRightOffset = abscissaPoint - topLeft; QSizeF size( bottomRightOffset.x(), bottomRightOffset.y() ); QRectF area( topLeft, size ); PainterSaver painterSaver( ctx->painter() ); ctx->painter()->setPen( PrintingParameters::scalePen( vt.pen() ) ); ctx->painter()->setBrush( QBrush() ); ctx->painter()->drawLine( markerPoint, ordinatePoint ); ctx->painter()->drawLine( markerPoint, abscissaPoint ); ctx->painter()->fillRect( area, vt.areaBrush() ); ctx->painter()->drawEllipse( ellipseMarker ); ctx->painter()->setBrush( vt.pen().color() ); ctx->painter()->drawPolygon( ordinateMarker, 3 ); ctx->painter()->drawPolygon( abscissaMarker, 3 ); }
DataDimensionsList CartesianGrid::calculateGrid( const DataDimensionsList& rawDataDimensions ) const { Q_ASSERT_X ( rawDataDimensions.count() == 2, "CartesianGrid::calculateGrid", "Error: calculateGrid() expects a list with exactly two entries." ); CartesianCoordinatePlane* plane = dynamic_cast<CartesianCoordinatePlane*>( mPlane ); Q_ASSERT_X ( plane, "CartesianGrid::calculateGrid", "Error: PaintContext::calculatePlane() called, but no cartesian plane set." ); DataDimensionsList l( rawDataDimensions ); // rule: Returned list is either empty, or it is providing two // valid dimensions, complete with two non-Zero step widths. if( isBoundariesValid( l ) ) { const QPointF translatedBottomLeft( plane->translateBack( plane->geometry().bottomLeft() ) ); const QPointF translatedTopRight( plane->translateBack( plane->geometry().topRight() ) ); //qDebug() << "CartesianGrid::calculateGrid() first:" << l.first().start << l.first().end << " last:" << l.last().start << l.last().end; //qDebug() << "CartesianGrid::calculateGrid() translated x:" << translatedBottomLeft.x() << translatedTopRight.x() << " y:" << translatedBottomLeft.y() << translatedTopRight.y(); //qDebug() << "CartesianGrid::calculateGrid() raw data y-range :" << l.last().end - l.last().start; //qDebug() << "CartesianGrid::calculateGrid() translated y-range:" << translatedTopRight.y() - translatedBottomLeft.y(); /* Code is obsolete. The dataset dimension of the diagram should *never* be > 1. if( l.first().isCalculated && plane->autoAdjustGridToZoom() && plane->axesCalcModeX() == CartesianCoordinatePlane::Linear && plane->zoomFactorX() > 1.0 ) { l.first().start = translatedBottomLeft.x(); l.first().end = translatedTopRight.x(); } */ const GridAttributes gridAttrsX( plane->gridAttributes( Qt::Horizontal ) ); const GridAttributes gridAttrsY( plane->gridAttributes( Qt::Vertical ) ); const DataDimension dimX = calculateGridXY( l.first(), Qt::Horizontal, gridAttrsX.adjustLowerBoundToGrid(), gridAttrsX.adjustUpperBoundToGrid() ); if( dimX.stepWidth ){ //qDebug("CartesianGrid::calculateGrid() l.last().start: %f l.last().end: %f", l.last().start, l.last().end); //qDebug(" l.first().start: %f l.first().end: %f", l.first().start, l.first().end); // one time for the min/max value const DataDimension minMaxY = calculateGridXY( l.last(), Qt::Vertical, gridAttrsY.adjustLowerBoundToGrid(), gridAttrsY.adjustUpperBoundToGrid() ); if( plane->autoAdjustGridToZoom() && plane->axesCalcModeY() == CartesianCoordinatePlane::Linear && plane->zoomFactorY() > 1.0 ) { l.last().start = translatedBottomLeft.y(); l.last().end = translatedTopRight.y(); } // and one other time for the step width const DataDimension dimY = calculateGridXY( l.last(), Qt::Vertical, gridAttrsY.adjustLowerBoundToGrid(), gridAttrsY.adjustUpperBoundToGrid() ); if( dimY.stepWidth ){ l.first().start = dimX.start; l.first().end = dimX.end; l.first().stepWidth = dimX.stepWidth; l.first().subStepWidth = dimX.subStepWidth; l.last().start = minMaxY.start; l.last().end = minMaxY.end; l.last().stepWidth = dimY.stepWidth; l.last().subStepWidth = dimY.subStepWidth; //qDebug() << "CartesianGrid::calculateGrid() final grid y-range:" << l.last().end - l.last().start << " step width:" << l.last().stepWidth << endl; // calculate some reasonable subSteps if the // user did not set the sub grid but did set // the stepWidth. // FIXME (Johannes) // the last (y) dimension is not always the dimension for the ordinate! // since there's no way to check for the orientation of this dimension here, // we cannot automatically assume substep values //if ( dimY.subStepWidth == 0 ) // l.last().subStepWidth = dimY.stepWidth/2; //else // l.last().subStepWidth = dimY.subStepWidth; } } } //qDebug() << "CartesianGrid::calculateGrid() final grid Y-range:" << l.last().end - l.last().start << " substep width:" << l.last().subStepWidth; //qDebug() << "CartesianGrid::calculateGrid() final grid X-range:" << l.first().end - l.first().start << " substep width:" << l.first().subStepWidth; return l; }
DataDimensionsList LeveyJenningsGrid::calculateGrid( const DataDimensionsList& rawDataDimensions ) const { Q_ASSERT_X ( rawDataDimensions.count() == 2, "CartesianGrid::calculateGrid", "Error: calculateGrid() expects a list with exactly two entries." ); LeveyJenningsCoordinatePlane* plane = dynamic_cast< LeveyJenningsCoordinatePlane*>( mPlane ); Q_ASSERT_X ( plane, "LeveyJenningsGrid::calculateGrid", "Error: PaintContext::calculatePlane() called, but no cartesian plane set." ); DataDimensionsList l( rawDataDimensions ); // rule: Returned list is either empty, or it is providing two // valid dimensions, complete with two non-Zero step widths. if( isBoundariesValid( l ) ) { const QPointF translatedBottomLeft( plane->translateBack( plane->geometry().bottomLeft() ) ); const QPointF translatedTopRight( plane->translateBack( plane->geometry().topRight() ) ); if( l.first().isCalculated && plane->autoAdjustGridToZoom() && plane->axesCalcModeX() == CartesianCoordinatePlane::Linear && plane->zoomFactorX() > 1.0 ) { l.first().start = translatedBottomLeft.x(); l.first().end = translatedTopRight.x(); } const DataDimension dimX = calculateGridXY( l.first(), Qt::Horizontal, false, false ); if( dimX.stepWidth ){ // one time for the min/max value const DataDimension minMaxY = calculateGridXY( l.last(), Qt::Vertical, false, false ); if( plane->autoAdjustGridToZoom() && plane->axesCalcModeY() == CartesianCoordinatePlane::Linear && plane->zoomFactorY() > 1.0 ) { l.last().start = translatedBottomLeft.y(); l.last().end = translatedTopRight.y(); } // and one other time for the step width const DataDimension dimY = calculateGridXY( l.last(), Qt::Vertical, false, false ); if( dimY.stepWidth ){ l.first().start = dimX.start; l.first().end = dimX.end; l.first().stepWidth = dimX.stepWidth; l.first().subStepWidth = dimX.subStepWidth; l.last().start = minMaxY.start; l.last().end = minMaxY.end; l.last().stepWidth = dimY.stepWidth; //qDebug() << "CartesianGrid::calculateGrid() final grid y-range:" << l.last().end - l.last().start << " step width:" << l.last().stepWidth << endl; // calculate some reasonable subSteps if the // user did not set the sub grid but did set // the stepWidth. if ( dimY.subStepWidth == 0 ) l.last().subStepWidth = dimY.stepWidth/2; else l.last().subStepWidth = dimY.subStepWidth; } } } //qDebug() << "CartesianGrid::calculateGrid() final grid Y-range:" << l.last().end - l.last().start << " step width:" << l.last().stepWidth; //qDebug() << "CartesianGrid::calculateGrid() final grid X-range:" << l.first().end - l.first().start << " step width:" << l.first().stepWidth; return l; }
void paintValueTracker( PaintContext* ctx, const ValueTrackerAttributes& vt, const QPointF& at ) { CartesianCoordinatePlane* plane = qobject_cast<CartesianCoordinatePlane*>( ctx->coordinatePlane() ); if ( !plane ) return; DataDimensionsList gridDimensions = ctx->coordinatePlane()->gridDimensionsList(); const QPointF bottomLeft( ctx->coordinatePlane()->translate( QPointF( plane->isHorizontalRangeReversed() ? gridDimensions.at( 0 ).end : gridDimensions.at( 0 ).start, plane->isVerticalRangeReversed() ? gridDimensions.at( 1 ).end : gridDimensions.at( 1 ).start ) ) ); const QPointF topRight( ctx->coordinatePlane()->translate( QPointF( plane->isHorizontalRangeReversed() ? gridDimensions.at( 0 ).start : gridDimensions.at( 0 ).end, plane->isVerticalRangeReversed() ? gridDimensions.at( 1 ).start : gridDimensions.at( 1 ).end ) ) ); const QPointF markerPoint = at; QPointF startPoint; if ( vt.orientations() & Qt::Horizontal ) { startPoint = QPointF( bottomLeft.x(), at.y() ); } else { startPoint = QPointF( at.x(), topRight.y() ); } QPointF endPoint; if ( vt.orientations() & Qt::Vertical ) { endPoint = QPointF( at.x(), bottomLeft.y() ); } else { endPoint = QPointF( topRight.x(), at.y() ); } const QSizeF markerSize = vt.markerSize(); const QRectF ellipseMarker = QRectF( at.x() - markerSize.width() / 2, at.y() - markerSize.height() / 2, markerSize.width(), markerSize.height() ); QPointF startMarker[3]; if ( vt.orientations() & Qt::Horizontal ) { startMarker[0] = startPoint + QPointF( 0, markerSize.height() / 2 ); startMarker[1] = startPoint + QPointF( markerSize.width() / 2, 0 ); startMarker[2] = startPoint - QPointF( 0, markerSize.height() / 2 ); } else { startMarker[0] = startPoint + QPointF( 0, markerSize.height() / 2 ); startMarker[1] = startPoint + QPointF( markerSize.width() / 2, 0 ); startMarker[2] = startPoint - QPointF( markerSize.width() / 2, 0 ); } QPointF endMarker[3]; if ( vt.orientations() & Qt::Vertical ) { endMarker[0] = endPoint + QPointF( markerSize.width() / 2, 0 ); endMarker[1] = endPoint - QPointF( 0, markerSize.height() / 2 ); endMarker[2] = endPoint - QPointF( markerSize.width() / 2, 0 ); } else { endMarker[0] = endPoint + QPointF( 0, markerSize.width() / 2 ); endMarker[1] = endPoint - QPointF( 0, markerSize.height() / 2 ); endMarker[2] = endPoint - QPointF( markerSize.width() / 2, 0 ); } QPointF topLeft = startPoint; QPointF bottomRightOffset = endPoint - topLeft; QSizeF size( bottomRightOffset.x(), bottomRightOffset.y() ); QRectF area( topLeft, size ); PainterSaver painterSaver( ctx->painter() ); ctx->painter()->setPen( PrintingParameters::scalePen( vt.linePen() ) ); ctx->painter()->setBrush( QBrush() ); ctx->painter()->drawLine( markerPoint, startPoint ); ctx->painter()->drawLine( markerPoint, endPoint ); ctx->painter()->fillRect( area, vt.areaBrush() ); ctx->painter()->setPen( PrintingParameters::scalePen( vt.markerPen() ) ); ctx->painter()->setBrush( vt.markerBrush() ); ctx->painter()->drawEllipse( ellipseMarker ); ctx->painter()->setPen( PrintingParameters::scalePen( vt.arrowBrush().color() ) ); ctx->painter()->setBrush( vt.arrowBrush() ); ctx->painter()->drawPolygon( startMarker, 3 ); ctx->painter()->drawPolygon( endMarker, 3 ); }