bool LeveyJenningsGridAttributes::operator==( const LeveyJenningsGridAttributes& r ) const { return isGridVisible( Expected ) == r.isGridVisible( Expected ) && isGridVisible( Calculated ) == r.isGridVisible( Calculated ) && gridPen( Expected ) == r.gridPen( Expected ) && gridPen( Calculated ) == r.gridPen( Calculated ); }
void LeveyJenningsGrid::drawGrid( PaintContext* context ) { LeveyJenningsCoordinatePlane* plane = dynamic_cast<LeveyJenningsCoordinatePlane*>(context->coordinatePlane()); // This plane is used for tranlating the coordinates - not for the data boundaries PainterSaver p( context->painter() ); plane = dynamic_cast< LeveyJenningsCoordinatePlane* >( plane->sharedAxisMasterPlane( context->painter() ) ); Q_ASSERT_X ( plane, "LeveyJenningsGrid::drawGrid", "Bad function call: PaintContext::coodinatePlane() NOT a Levey Jennings plane." ); LeveyJenningsDiagram* diag = dynamic_cast<LeveyJenningsDiagram*>( plane->diagram() ); if( diag == 0 ) return; const LeveyJenningsGridAttributes gridAttrs( plane->gridAttributes() ); // important: Need to update the calculated mData, // before we may use it! updateData( context->coordinatePlane() ); // test for programming errors: critical Q_ASSERT_X ( mData.count() == 2, "CartesianGrid::drawGrid", "Error: updateData did not return exactly two dimensions." ); // test for invalid boundaries: non-critical if( !isBoundariesValid( mData ) ) return; //qDebug() << "B"; DataDimension dimX = mData.first(); // this happens if there's only one data point if( dimX.start == 0.0 && dimX.end == 0.0 ) dimX.end += plane->geometry().width(); // first we draw the expected lines // draw the "mean" line const float meanValue = diag->expectedMeanValue(); const float standardDeviation = diag->expectedStandardDeviation(); // then the calculated ones const float calcMeanValue = diag->calculatedMeanValue(); const float calcStandardDeviation = diag->calculatedStandardDeviation(); // draw the normal range QPointF topLeft = plane->translate( QPointF( dimX.start, meanValue - 2 * standardDeviation ) ); QPointF bottomRight = plane->translate( QPointF( dimX.end, meanValue + 2 * standardDeviation ) ); context->painter()->fillRect( QRectF( topLeft, QSizeF( bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y() ) ), gridAttrs.rangeBrush( LeveyJenningsGridAttributes::NormalRange ) ); // draw the critical range topLeft = plane->translate( QPointF( dimX.start, meanValue + 2 * standardDeviation ) ); bottomRight = plane->translate( QPointF( dimX.end, meanValue + 3 * standardDeviation ) ); context->painter()->fillRect( QRectF( topLeft, QSizeF( bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y() ) ), gridAttrs.rangeBrush( LeveyJenningsGridAttributes::CriticalRange ) ); topLeft = plane->translate( QPointF( dimX.start, meanValue - 2 * standardDeviation ) ); bottomRight = plane->translate( QPointF( dimX.end, meanValue - 3 * standardDeviation ) ); context->painter()->fillRect( QRectF( topLeft, QSizeF( bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y() ) ), gridAttrs.rangeBrush( LeveyJenningsGridAttributes::CriticalRange ) ); // draw the "out of range" range topLeft = plane->translate( QPointF( dimX.start, meanValue + 3 * standardDeviation ) ); bottomRight = plane->translate( QPointF( dimX.end, meanValue + 4 * standardDeviation ) ); context->painter()->fillRect( QRectF( topLeft, QSizeF( bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y() ) ), gridAttrs.rangeBrush( LeveyJenningsGridAttributes::OutOfRange ) ); topLeft = plane->translate( QPointF( dimX.start, meanValue - 3 * standardDeviation ) ); bottomRight = plane->translate( QPointF( dimX.end, meanValue - 4 * standardDeviation ) ); context->painter()->fillRect( QRectF( topLeft, QSizeF( bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y() ) ), gridAttrs.rangeBrush( LeveyJenningsGridAttributes::OutOfRange ) ); // the "expected" grid if( gridAttrs.isGridVisible( LeveyJenningsGridAttributes::Expected ) ) { context->painter()->setPen( gridAttrs.gridPen( LeveyJenningsGridAttributes::Expected ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, meanValue ) ), plane->translate( QPointF( dimX.end, meanValue ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, meanValue + 2 * standardDeviation ) ), plane->translate( QPointF( dimX.end, meanValue + 2 * standardDeviation ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, meanValue + 3 * standardDeviation ) ), plane->translate( QPointF( dimX.end, meanValue + 3 * standardDeviation ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, meanValue + 4 * standardDeviation ) ), plane->translate( QPointF( dimX.end, meanValue + 4 * standardDeviation ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, meanValue - 2 * standardDeviation ) ), plane->translate( QPointF( dimX.end, meanValue - 2 * standardDeviation ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, meanValue - 3 * standardDeviation ) ), plane->translate( QPointF( dimX.end, meanValue - 3 * standardDeviation ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, meanValue - 4 * standardDeviation ) ), plane->translate( QPointF( dimX.end, meanValue - 4 * standardDeviation ) ) ); } // the "calculated" grid if( gridAttrs.isGridVisible( LeveyJenningsGridAttributes::Calculated ) ) { context->painter()->setPen( gridAttrs.gridPen( LeveyJenningsGridAttributes::Calculated ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, calcMeanValue ) ), plane->translate( QPointF( dimX.end, calcMeanValue ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, calcMeanValue + 2 * calcStandardDeviation ) ), plane->translate( QPointF( dimX.end, calcMeanValue + 2 * calcStandardDeviation ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, calcMeanValue + 3 * calcStandardDeviation ) ), plane->translate( QPointF( dimX.end, calcMeanValue + 3 * calcStandardDeviation ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, calcMeanValue - 2 * calcStandardDeviation ) ), plane->translate( QPointF( dimX.end, calcMeanValue - 2 * calcStandardDeviation ) ) ); context->painter()->drawLine( plane->translate( QPointF( dimX.start, calcMeanValue - 3 * calcStandardDeviation ) ), plane->translate( QPointF( dimX.end, calcMeanValue - 3 * calcStandardDeviation ) ) ); } }