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 }
qwt_scale_div.h
QwtPlot
A 2-D plotting widget.
Definition: qwt_plot.h:78
QwtPlot::setAxisScale
void setAxisScale(QwtAxisId, double min, double max, double stepSize=0)
Disable autoscaling and specify a fixed scale for a selected axis.
Definition: qwt_plot_axis.cpp:477
QwtScaleDiv::lowerBound
double lowerBound() const
Definition: qwt_scale_div.cpp:131
QwtPlot::setAutoReplot
void setAutoReplot(bool=true)
Set or reset the autoReplot option.
Definition: qwt_plot.cpp:310
QwtPlotPanner::plot
QwtPlot * plot()
Return plot widget, containing the observed plot canvas.
Definition: qwt_plot_panner.cpp:189
qwt_scale_map.h
range_format::map
@ map
QwtPlotPanner::isAxisEnabled
bool isAxisEnabled(QwtAxisId) const
Definition: qwt_plot_panner.cpp:168
QwtScaleDiv::upperBound
double upperBound() const
Definition: qwt_scale_div.cpp:151
PlotPanner::moveCanvas
void moveCanvas(int dx, int dy) override
Definition: plotpanner.cpp:7
QwtAxis::isXAxis
bool isXAxis(int axisPos)
Definition: qwt_axis.h:51
QwtPlot::autoReplot
bool autoReplot
Definition: qwt_plot.h:85
QwtPlot::axisScaleDiv
const QwtScaleDiv & axisScaleDiv(QwtAxisId) const
Return the scale division of a specified axis.
Definition: qwt_plot_axis.cpp:283
QwtAxisId
int QwtAxisId
Axis identifier.
Definition: qwt_axis_id.h:26
QwtScaleMap
A scale map.
Definition: qwt_scale_map.h:26
QwtPlot::yLeft
@ yLeft
Definition: qwt_plot.h:240
QwtAxis::AxisPositions
@ AxisPositions
Definition: qwt_axis.h:44
QwtPlot::replot
virtual void replot()
Redraw the plot.
Definition: qwt_plot.cpp:545
QwtPlot::xBottom
@ xBottom
Definition: qwt_plot.h:242
plotpanner.h
QwtPlot::canvasMap
virtual QwtScaleMap canvasMap(QwtAxisId) const
Definition: qwt_plot.cpp:800
qwt_plot.h
PlotPanner::rescaled
void rescaled(QRectF new_size)


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45