qwt_plot_magnifier.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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_div.h"
12 #include "qwt_plot_magnifier.h"
13 
15 {
16 public:
18  {
19  for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
20  isAxisEnabled[axis] = true;
21  }
22 
24 };
25 
31  QwtMagnifier( canvas )
32 {
33  d_data = new PrivateData();
34 }
35 
38 {
39  delete d_data;
40 }
41 
53 void QwtPlotMagnifier::setAxisEnabled( int axis, bool on )
54 {
55  if ( axis >= 0 && axis < QwtPlot::axisCnt )
56  d_data->isAxisEnabled[axis] = on;
57 }
58 
67 bool QwtPlotMagnifier::isAxisEnabled( int axis ) const
68 {
69  if ( axis >= 0 && axis < QwtPlot::axisCnt )
70  return d_data->isAxisEnabled[axis];
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 axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
127  {
128  if ( isAxisEnabled( axisId ) )
129  {
130  const QwtScaleMap scaleMap = plt->canvasMap( axisId );
131 
132  double v1 = scaleMap.s1();
133  double v2 = scaleMap.s2();
134 
135  if ( scaleMap.transformation() )
136  {
137  // the coordinate system of the paint device is always linear
138 
139  v1 = scaleMap.transform( v1 ); // scaleMap.p1()
140  v2 = scaleMap.transform( v2 ); // scaleMap.p2()
141  }
142 
143  const double center = 0.5 * ( v1 + v2 );
144  const double width_2 = 0.5 * ( v2 - v1 ) * factor;
145 
146  v1 = center - width_2;
147  v2 = center + width_2;
148 
149  if ( scaleMap.transformation() )
150  {
151  v1 = scaleMap.invTransform( v1 );
152  v2 = scaleMap.invTransform( v2 );
153  }
154 
155  plt->setAxisScale( axisId, v1, v2 );
156  doReplot = true;
157  }
158  }
159 
160  plt->setAutoReplot( autoReplot );
161 
162  if ( doReplot )
163  plt->replot();
164 }
double s1() const
Definition: qwt_scale_map.h:85
void setAxisEnabled(int axis, bool on)
En/Disable an axis.
Number of axes.
Definition: qwt_plot.h:108
PrivateData * d_data
void setAutoReplot(bool=true)
Set or reset the autoReplot option.
Definition: qwt_plot.cpp:314
virtual void replot()
Redraw the plot.
Definition: qwt_plot.cpp:546
A 2-D plotting widget.
Definition: qwt_plot.h:74
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
double s2() const
Definition: qwt_scale_map.h:93
QWidget * parentWidget()
bool autoReplot
Definition: qwt_plot.h:80
bool isAxisEnabled(int axis) const
virtual QwtScaleMap canvasMap(int axisId) const
Definition: qwt_plot.cpp:790
const QwtTransform * transformation() const
Get the transformation.
A scale map.
Definition: qwt_scale_map.h:30
double invTransform(double p) const
TFSIMD_FORCE_INLINE const tfScalar & w() const
QWidget * canvas()
Return observed plot canvas.
double transform(double s) const
bool isAxisEnabled[QwtPlot::axisCnt]
void setAxisScale(int axisId, double min, double max, double step=0)
Disable autoscaling and specify a fixed scale for a selected axis.
virtual void rescale(double factor)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17