myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ),
myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ),
myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ),
- myXMode( 0 ), myYMode( 0 ), mySecondY( false ), myIsRescaled( false )
+ myXMode( 0 ), myYMode( 0 ), mySecondY( false )
{
/* Plot 2d View */
QVBoxLayout* aLayout = new QVBoxLayout( this );
this, SLOT( plotMouseReleased( const QMouseEvent& ) ) );
connect( myPlot, SIGNAL( legendClicked( long ) ),
this, SIGNAL( legendClicked( long ) ) );
- connect( myPlot, SIGNAL( rescale() ),
- this, SLOT( rescale() ) );
/* Initial Setup - get from the preferences */
readPreferences();
myPlot->setAxisAutoScale( QwtPlot::yLeft );
myPlot->setAxisAutoScale( QwtPlot::xBottom );
- //myPlot->replot();
+ myPlot->replot();
// for existing grid
QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
myPlot->setAxisScale( QwtPlot::xBottom,
- QString::number(myPlot->invTransform( QwtPlot::xBottom, xMap.i1() )).toDouble(),
- QString::number(myPlot->invTransform( QwtPlot::xBottom, xMap.i2() )).toDouble() );
+ myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
+ myPlot->invTransform( QwtPlot::xBottom, xMap.i2() ) );
myPlot->setAxisScale( QwtPlot::yLeft,
- QString::number(myPlot->invTransform( QwtPlot::yLeft, yMap.i1() )).toDouble(),
- QString::number(myPlot->invTransform( QwtPlot::yLeft, yMap.i2() )).toDouble() );
+ myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
+ myPlot->invTransform( QwtPlot::yLeft, yMap.i2() ) );
if (mySecondY) {
myPlot->setAxisAutoScale( QwtPlot::yRight );
myPlot->replot();
QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
myPlot->setAxisScale( QwtPlot::yRight,
- QString::number(myPlot->invTransform( QwtPlot::yRight, yMap2.i1() )).toDouble(),
- QString::number(myPlot->invTransform( QwtPlot::yRight, yMap2.i2() )).toDouble() );
+ myPlot->invTransform( QwtPlot::yRight, yMap2.i1() ),
+ myPlot->invTransform( QwtPlot::yRight, yMap2.i2() ) );
}
myPlot->replot();
}
aParent->putInfo(tr("INF_READY"));
myOperation = NoOpId;
}
-
-/*!
- Slot, rescales axis on the first show of view frame in order to take into account the correct canvas map
-*/
-void Plot2d_ViewFrame::rescale()
-{
- if ( myPlot && !myIsRescaled ) {
- myIsRescaled = true;
-
- QwtDiMap map;
- int axis[3] = { QwtPlot::xBottom, QwtPlot::yLeft, QwtPlot::yRight };
- double dMin, dMax;
- for ( int i = 0; i < 3; i++ )
- if ( i < 2 || i == 2 && mySecondY ) {
- map = myPlot->canvasMap(axis[i]);
- dMin = myPlot->invTransform(axis[i], map.i1()); dMax = myPlot->invTransform(axis[i], map.i2());
- myPlot->setAxisScale( axis[i], QString::number(dMin).toDouble(), QString::number(dMax).toDouble() );
- }
- myPlot->replot();
- }
-}
-
/*!
Slot, called when user wheeling mouse
*/
}
/*!
- Emits rescale() signal on the first drawing of the QwtPlotCanvas.
+ In addition to draw canvas, checks the current labels format and change it if needed
*/
void Plot2d_Plot2d::drawCanvas(QPainter *painter)
{
- if ( Plot2d_ViewFrame* aVF = dynamic_cast<Plot2d_ViewFrame*>(parentWidget()) )
- if ( !aVF->isRescaled() )
- emit rescale();
+ if ( dynamic_cast<Plot2d_ViewFrame*>(parentWidget()) ) {
+ QwtDiMap map;
+ double aStep;
+ char f; int prec, fieldwidth;
+ int axis[3] = { QwtPlot::xBottom, QwtPlot::yLeft, QwtPlot::yRight };
+ for ( int i = 0; i < 3; i++ ) {
+ if ( axisEnabled( axis[i] ) ) {
+ map = canvasMap( axis[i] );
+ aStep = fabs( map.d2() - map.d1() ) / ( axisMaxMajor( axis[i] ) * axisMaxMinor( axis[i] ) );
+
+ QString aStepStr;
+ aStepStr.sprintf("%e",aStep);
+ int aPrecision = aStepStr.right(aStepStr.length()-aStepStr.find('e')-2).toInt();
+
+ axisLabelFormat( axis[i], f, prec, fieldwidth );
+
+ if ( aPrecision != prec )
+ setAxisLabelFormat( axis[i], 'f', aPrecision );
+ }
+ }
+ }
QwtPlot::drawCanvas(painter);
}