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:
17  PrivateData()
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 
98 const QwtPlot* QwtPlotMagnifier::plot() const
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
QwtPlotMagnifier::rescale
virtual void rescale(double factor) QWT_OVERRIDE
Definition: qwt_plot_magnifier.cpp:111
QwtPlotMagnifier::QwtPlotMagnifier
QwtPlotMagnifier(QWidget *)
Definition: qwt_plot_magnifier.cpp:30
QwtScaleMap::invTransform
double invTransform(double p) const
Definition: qwt_scale_map.h:154
QwtPlotMagnifier::canvas
QWidget * canvas()
Return observed plot canvas.
Definition: qwt_plot_magnifier.cpp:76
QwtPlotMagnifier::~QwtPlotMagnifier
virtual ~QwtPlotMagnifier()
Destructor.
Definition: qwt_plot_magnifier.cpp:37
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
QwtScaleMap::s2
double s2() const
Definition: qwt_scale_map.h:91
QwtScaleMap::s1
double s1() const
Definition: qwt_scale_map.h:83
QwtPlot::setAutoReplot
void setAutoReplot(bool=true)
Set or reset the autoReplot option.
Definition: qwt_plot.cpp:310
QwtPlotMagnifier::PrivateData::PrivateData
PrivateData()
Definition: qwt_plot_magnifier.cpp:24
QwtMagnifier
QwtMagnifier provides zooming, by magnifying in steps.
Definition: qwt_magnifier.h:27
QwtMagnifier::parentWidget
QWidget * parentWidget()
Definition: qwt_magnifier.cpp:499
qwt_scale_map.h
QwtPlotMagnifier::plot
QwtPlot * plot()
Return plot widget, containing the observed plot canvas.
Definition: qwt_plot_magnifier.cpp:88
QwtPlotMagnifier::setAxisEnabled
void setAxisEnabled(QwtAxisId, bool on)
En/Disable an axis.
Definition: qwt_plot_magnifier.cpp:53
qwt_plot_magnifier.h
QwtPlotMagnifier::PrivateData
Definition: qwt_plot_magnifier.cpp:14
QwtScaleMap::transform
double transform(double s) const
Definition: qwt_scale_map.h:137
QwtPlot::autoReplot
bool autoReplot
Definition: qwt_plot.h:85
QwtAxisId
int QwtAxisId
Axis identifier.
Definition: qwt_axis_id.h:26
QwtScaleMap
A scale map.
Definition: qwt_scale_map.h:26
QwtPlotMagnifier::isAxisEnabled
bool isAxisEnabled(QwtAxisId) const
Definition: qwt_plot_magnifier.cpp:67
QwtAxis::AxisPositions
@ AxisPositions
Definition: qwt_axis.h:44
QwtPlot::replot
virtual void replot()
Redraw the plot.
Definition: qwt_plot.cpp:545
QwtPlotMagnifier::m_data
PrivateData * m_data
Definition: qwt_plot_magnifier.h:51
QwtScaleMap::transformation
const QwtTransform * transformation() const
Get the transformation.
Definition: qwt_scale_map.cpp:88
QwtPlot::canvasMap
virtual QwtScaleMap canvasMap(QwtAxisId) const
Definition: qwt_plot.cpp:800
QwtAxis::isValid
bool isValid(int axisPos)
Definition: qwt_axis.h:45
qwt_plot.h
QwtPlotMagnifier::PrivateData::isAxisEnabled
bool isAxisEnabled[QwtAxis::AxisPositions]
Definition: qwt_plot_magnifier.cpp:30


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