From 39e21e8a146000f3c741d9d05b55222df4b64db8 Mon Sep 17 00:00:00 2001 From: mkr Date: Mon, 10 Nov 2008 13:56:54 +0000 Subject: [PATCH] Fix for IPAL17690 : Plot 2D grid/axial marks. --- src/Plot2d/Plot2d_ViewFrame.cxx | 67 +++++++++++++++++++++++++++++++++ src/Plot2d/Plot2d_ViewFrame.h | 19 ++++++++++ 2 files changed, 86 insertions(+) diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index b3fe3d4e6..e01b90895 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,7 @@ #include #include +#include #define DEFAULT_LINE_WIDTH 0 // (default) line width #define DEFAULT_MARKER_SIZE 9 // default marker size @@ -175,6 +177,15 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) connect( myPlot, SIGNAL( legendClicked( QwtPlotItem* ) ), this, SIGNAL( legendClicked( QwtPlotItem* ) ) ); + connect( myPlot->axisWidget( QwtPlot::xBottom ), SIGNAL( scaleDivChanged() ), + myPlot, SLOT( onScaleDivChanged() ) ); + connect( myPlot->axisWidget( QwtPlot::yLeft ), SIGNAL( scaleDivChanged() ), + myPlot, SLOT( onScaleDivChanged() ) ); + if (mySecondY) + connect( myPlot->axisWidget( QwtPlot::yRight ), SIGNAL( scaleDivChanged() ), + myPlot, SLOT( onScaleDivChanged() ) ); + + /* Initial Setup - get from the preferences */ readPreferences(); @@ -1820,6 +1831,41 @@ bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor return false; } +void Plot2d_Plot2d::onScaleDivChanged() +{ + QwtScaleWidget* aSW = 0; + if ( ( aSW = dynamic_cast(sender()) ) ) { + int axisId = -1; + switch ( aSW->alignment() ) { + case QwtScaleDraw::BottomScale: + axisId = QwtPlot::xBottom; + break; + case QwtScaleDraw::LeftScale: + axisId = QwtPlot::yLeft; + break; + case QwtScaleDraw::RightScale: + axisId = QwtPlot::yRight; + break; + default: + break; + } + + if ( axisId >= 0 ) { + QwtScaleMap map = canvasMap(axisId); + double aDist = fabs(map.s2()-map.s1()) / (axisMaxMajor(axisId)*axisMaxMinor(axisId)); + + QString diffPrecStr; + diffPrecStr.sprintf("%e",aDist); + int deltaEpsilon = diffPrecStr.right(diffPrecStr.length()-diffPrecStr.indexOf('e')-2).toInt(); + + QwtScaleDraw* aQwtSD = axisScaleDraw(axisId); + Plot2d_ScaleDraw* aPlot2dSD = dynamic_cast(aQwtSD); + if ( !aPlot2dSD && deltaEpsilon > 6 || aPlot2dSD && aPlot2dSD->precision() != deltaEpsilon ) + setAxisScaleDraw( axisId, new Plot2d_ScaleDraw(*aQwtSD, 'f', deltaEpsilon) ); + } + } +} + /*! Sets the flag saying that QwtPlot geometry has been fully defined. */ @@ -2119,3 +2165,24 @@ void Plot2d_ViewFrame::customEvent( QEvent* ce ) if ( ce->type() == FITALL_EVENT ) fitAll(); } + +Plot2d_ScaleDraw::Plot2d_ScaleDraw( char f, int prec ) + : QwtScaleDraw(), + myFormat(f), + myPrecision(prec) +{ + invalidateCache(); +} + +Plot2d_ScaleDraw::Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f, int prec ) + : QwtScaleDraw(scaleDraw), + myFormat(f), + myPrecision(prec) +{ + invalidateCache(); +} + +QwtText Plot2d_ScaleDraw::label( double value ) const +{ + return QLocale::system().toString(value,myFormat,myPrecision); +} diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index c08c827ae..f101ed18b 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -24,6 +24,7 @@ #include #include #include +#include class Plot2d_Plot2d; class Plot2d_Prs; @@ -225,6 +226,9 @@ public slots: protected: bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ); +protected slots: + void onScaleDivChanged(); + protected: CurveDict myCurves; QwtPlotGrid* myGrid; @@ -233,4 +237,19 @@ protected: QwtPlotZoomer* myPlotZoomer; }; +class Plot2d_ScaleDraw: public QwtScaleDraw +{ +public: + Plot2d_ScaleDraw( char f = 'g', int prec = 6 ); + Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f = 'g', int prec = 6 ); + + virtual QwtText label( double value ) const; + + int precision() const { return myPrecision; } + +private: + char myFormat; + int myPrecision; +}; + #endif -- 2.39.2