qwt_plot_magnifier.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #include "qwt_plot.h"
11 #include "qwt_scale_map.h"
12 #include "qwt_plot_magnifier.h"
13 
15 {
16  public:
18  {
19  for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
20  isAxisEnabled[axis] = true;
21  }
22 
24 };
25 
31  : QwtMagnifier( canvas )
32 {
33  m_data = new PrivateData();
34 }
35 
38 {
39  delete m_data;
40 }
41 
54 {
55  if ( QwtAxis::isValid( axisId ) )
56  m_data->isAxisEnabled[axisId] = on;
57 }
58 
68 {
69  if ( QwtAxis::isValid( axisId ) )
70  return m_data->isAxisEnabled[axisId];
71 
72  return true;
73 }
74 
77 {
78  return parentWidget();
79 }
80 
82 const QWidget* QwtPlotMagnifier::canvas() const
83 {
84  return parentWidget();
85 }
86 
89 {
90  QWidget* w = canvas();
91  if ( w )
92  w = w->parentWidget();
93 
94  return qobject_cast< QwtPlot* >( w );
95 }
96 
99 {
100  const QWidget* w = canvas();
101  if ( w )
102  w = w->parentWidget();
103 
104  return qobject_cast< const QwtPlot* >( w );
105 }
106 
111 void QwtPlotMagnifier::rescale( double factor )
112 {
113  QwtPlot* plt = plot();
114  if ( plt == NULL )
115  return;
116 
117  factor = qAbs( factor );
118  if ( factor == 1.0 || factor == 0.0 )
119  return;
120 
121  bool doReplot = false;
122 
123  const bool autoReplot = plt->autoReplot();
124  plt->setAutoReplot( false );
125 
126  for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
127  {
128  {
129  const QwtAxisId axisId( axisPos );
130 
131  if ( isAxisEnabled( axisId ) )
132  {
133  const QwtScaleMap scaleMap = plt->canvasMap( axisId );
134 
135  double v1 = scaleMap.s1();
136  double v2 = scaleMap.s2();
137 
138  if ( scaleMap.transformation() )
139  {
140  // the coordinate system of the paint device is always linear
141 
142  v1 = scaleMap.transform( v1 ); // scaleMap.p1()
143  v2 = scaleMap.transform( v2 ); // scaleMap.p2()
144  }
145 
146  const double center = 0.5 * ( v1 + v2 );
147  const double width_2 = 0.5 * ( v2 - v1 ) * factor;
148 
149  v1 = center - width_2;
150  v2 = center + width_2;
151 
152  if ( scaleMap.transformation() )
153  {
154  v1 = scaleMap.invTransform( v1 );
155  v2 = scaleMap.invTransform( v2 );
156  }
157 
158  plt->setAxisScale( axisId, v1, v2 );
159  doReplot = true;
160  }
161  }
162  }
163 
164  plt->setAutoReplot( autoReplot );
165 
166  if ( doReplot )
167  plt->replot();
168 }
169 
170 #if QWT_MOC_INCLUDE
171 #include "moc_qwt_plot_magnifier.cpp"
172 #endif
double invTransform(double p) const
PrivateData * m_data
bool isValid(int axisPos)
Definition: qwt_axis.h:45
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
bool isAxisEnabled(QwtAxisId) const
A 2-D plotting widget.
Definition: qwt_plot.h:78
double transform(double s) const
virtual ~QwtPlotMagnifier()
Destructor.
QwtPlot * plot()
Return plot widget, containing the observed plot canvas.
QwtMagnifier provides zooming, by magnifying in steps.
Definition: qwt_magnifier.h:27
const QwtTransform * transformation() const
Get the transformation.
QWidget * parentWidget()
bool autoReplot
Definition: qwt_plot.h:85
void setAxisEnabled(QwtAxisId, bool on)
En/Disable an axis.
A scale map.
Definition: qwt_scale_map.h:26
int QwtAxisId
Axis identifier.
Definition: qwt_axis_id.h:26
QWidget * canvas()
Return observed plot canvas.
double s1() const
Definition: qwt_scale_map.h:83
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
virtual void rescale(double factor) QWT_OVERRIDE
bool isAxisEnabled[QwtAxis::AxisPositions]
double s2() const
Definition: qwt_scale_map.h:91


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