plotpanner.cpp
Go to the documentation of this file.
1 #include "qwt_plot.h"
2 #include "qwt_scale_map.h"
3 #include "qwt_scale_div.h"
4 
5 #include "plotpanner.h"
6 
7 void PlotPanner::moveCanvas( int dx, int dy )
8 {
9  if ( dx == 0 && dy == 0 )
10  return;
11 
12  QwtPlot* plot = this->plot();
13  if ( plot == NULL )
14  return;
15 
16  const bool doAutoReplot = plot->autoReplot();
17  plot->setAutoReplot( false );
18 
19  QRectF new_rect;
20 
21  for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
22  {
23  const QwtAxisId axisId( axisPos );
24 
25  if ( !isAxisEnabled(axisId) )
26  continue;
27 
28  const QwtScaleMap map = plot->canvasMap( axisId );
29 
30  const double p1 = map.transform( plot->axisScaleDiv( axisId ).lowerBound() );
31  const double p2 = map.transform( plot->axisScaleDiv( axisId ).upperBound() );
32 
33  double d1, d2;
34  if ( QwtAxis::isXAxis( axisPos ) )
35  {
36  d1 = map.invTransform( p1 - dx );
37  d2 = map.invTransform( p2 - dx );
38  }
39  else
40  {
41  d1 = map.invTransform( p1 - dy );
42  d2 = map.invTransform( p2 - dy );
43  }
44 
45  plot->setAxisScale( axisId, d1, d2 );
46 
47  if( axisId == QwtPlot::yLeft )
48  {
49  new_rect.setBottom( d1 );
50  new_rect.setTop( d2 );
51  }
52  if( axisId == QwtPlot::xBottom )
53  {
54  new_rect.setLeft( d1 );
55  new_rect.setRight( d2 );
56  }
57  }
58 
59  emit rescaled(new_rect);
60 
61  plot->setAutoReplot( doAutoReplot );
62  plot->replot();
63 }
double invTransform(double p) const
double lowerBound() const
void setAutoReplot(bool=true)
Set or reset the autoReplot option.
Definition: qwt_plot.cpp:310
virtual void replot()
Redraw the plot.
Definition: qwt_plot.cpp:545
const QwtScaleDiv & axisScaleDiv(QwtAxisId) const
Return the scale division of a specified axis.
void moveCanvas(int dx, int dy) override
Definition: plotpanner.cpp:7
A 2-D plotting widget.
Definition: qwt_plot.h:78
double transform(double s) const
bool autoReplot
Definition: qwt_plot.h:85
bool isXAxis(int axisPos)
Definition: qwt_axis.h:51
void rescaled(QRectF new_size)
QwtPlot * plot()
Return plot widget, containing the observed plot canvas.
A scale map.
Definition: qwt_scale_map.h:26
int QwtAxisId
Axis identifier.
Definition: qwt_axis_id.h:26
void setAxisScale(QwtAxisId, double min, double max, double stepSize=0)
Disable autoscaling and specify a fixed scale for a selected axis.
virtual QwtScaleMap canvasMap(QwtAxisId) const
Definition: qwt_plot.cpp:800
double upperBound() const
bool isAxisEnabled(QwtAxisId) const


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:38