Loading...
Searching...
No Matches
qwt_plot_magnifier.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_plot.h"
#include "qwt_scale_map.h"
#include "qwt_plot_magnifier.h"
class QwtPlotMagnifier::PrivateData
{
public:
PrivateData()
{
for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
isAxisEnabled[axis] = true;
}
bool isAxisEnabled[QwtAxis::AxisPositions];
};
QwtPlotMagnifier::QwtPlotMagnifier( QWidget* canvas )
: QwtMagnifier( canvas )
{
m_data = new PrivateData();
}
QwtPlotMagnifier::~QwtPlotMagnifier()
{
delete m_data;
}
void QwtPlotMagnifier::setAxisEnabled( QwtAxisId axisId, bool on )
{
if ( QwtAxis::isValid( axisId ) )
m_data->isAxisEnabled[axisId] = on;
}
bool QwtPlotMagnifier::isAxisEnabled( QwtAxisId axisId ) const
{
if ( QwtAxis::isValid( axisId ) )
return m_data->isAxisEnabled[axisId];
return true;
}
QWidget* QwtPlotMagnifier::canvas()
{
return parentWidget();
}
const QWidget* QwtPlotMagnifier::canvas() const
{
return parentWidget();
}
QwtPlot* QwtPlotMagnifier::plot()
{
QWidget* w = canvas();
if ( w )
w = w->parentWidget();
return qobject_cast< QwtPlot* >( w );
}
const QwtPlot* QwtPlotMagnifier::plot() const
{
const QWidget* w = canvas();
if ( w )
w = w->parentWidget();
return qobject_cast< const QwtPlot* >( w );
}
void QwtPlotMagnifier::rescale( double factor )
{
QwtPlot* plt = plot();
if ( plt == NULL )
return;
factor = qAbs( factor );
if ( factor == 1.0 || factor == 0.0 )
return;
bool doReplot = false;
const bool autoReplot = plt->autoReplot();
plt->setAutoReplot( false );
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
{
{
const QwtAxisId axisId( axisPos );
if ( isAxisEnabled( axisId ) )
{
const QwtScaleMap scaleMap = plt->canvasMap( axisId );
double v1 = scaleMap.s1();
double v2 = scaleMap.s2();
if ( scaleMap.transformation() )
{
// the coordinate system of the paint device is always linear
v1 = scaleMap.transform( v1 ); // scaleMap.p1()
v2 = scaleMap.transform( v2 ); // scaleMap.p2()
}
const double center = 0.5 * ( v1 + v2 );
const double width_2 = 0.5 * ( v2 - v1 ) * factor;
v1 = center - width_2;
v2 = center + width_2;
if ( scaleMap.transformation() )
{
v1 = scaleMap.invTransform( v1 );
v2 = scaleMap.invTransform( v2 );
}
plt->setAxisScale( axisId, v1, v2 );
doReplot = true;
}
}
}
plt->setAutoReplot( autoReplot );
if ( doReplot )
plt->replot();
}
#include "moc_qwt_plot_magnifier.cpp"
QwtMagnifier
QwtMagnifier provides zooming, by magnifying in steps.
Definition qwt_magnifier.h:28
QwtMagnifier::parentWidget
QWidget * parentWidget()
Definition qwt_magnifier.cpp:499
QwtPlot
A 2-D plotting widget.
Definition qwt_plot.h:79
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
QwtPlot::autoReplot
bool autoReplot() const
Definition qwt_plot.cpp:319
QwtPlot::replot
virtual void replot()
Redraw the plot.
Definition qwt_plot.cpp:545
QwtPlot::setAutoReplot
void setAutoReplot(bool=true)
Set or reset the autoReplot option.
Definition qwt_plot.cpp:310
QwtPlot::canvasMap
virtual QwtScaleMap canvasMap(QwtAxisId) const
Definition qwt_plot.cpp:800
QwtPlotMagnifier::~QwtPlotMagnifier
virtual ~QwtPlotMagnifier()
Destructor.
Definition qwt_plot_magnifier.cpp:37
QwtPlotMagnifier::setAxisEnabled
void setAxisEnabled(QwtAxisId, bool on)
En/Disable an axis.
Definition qwt_plot_magnifier.cpp:53
QwtPlotMagnifier::rescale
virtual void rescale(double factor) override
Definition qwt_plot_magnifier.cpp:111
QwtPlotMagnifier::QwtPlotMagnifier
QwtPlotMagnifier(QWidget *)
Definition qwt_plot_magnifier.cpp:30
QwtPlotMagnifier::canvas
QWidget * canvas()
Return observed plot canvas.
Definition qwt_plot_magnifier.cpp:76
QwtPlotMagnifier::isAxisEnabled
bool isAxisEnabled(QwtAxisId) const
Definition qwt_plot_magnifier.cpp:67
QwtPlotMagnifier::plot
QwtPlot * plot()
Return plot widget, containing the observed plot canvas.
Definition qwt_plot_magnifier.cpp:88
QwtScaleMap
A scale map.
Definition qwt_scale_map.h:27
QwtScaleMap::transform
double transform(double s) const
Definition qwt_scale_map.h:137
QwtScaleMap::s1
double s1() const
Definition qwt_scale_map.h:83
QwtScaleMap::s2
double s2() const
Definition qwt_scale_map.h:91
QwtScaleMap::transformation
const QwtTransform * transformation() const
Get the transformation.
Definition qwt_scale_map.cpp:88
QwtScaleMap::invTransform
double invTransform(double p) const
Definition qwt_scale_map.h:154
QwtAxis::isValid
bool isValid(int axisPos)
Definition qwt_axis.h:45