10#include "qwt_plot_rescaler.h"
12#include "qwt_scale_div.h"
13#include "qwt_interval.h"
14#include "qwt_plot_canvas.h"
18class QwtPlotRescaler::AxisData
33class QwtPlotRescaler::PrivateData
44 QwtPlotRescaler::AxisData* axisData( QwtAxisId axisId )
49 return &m_axisData[ axisId];
52 QwtAxisId referenceAxis;
59 QwtPlotRescaler::AxisData m_axisData[QwtAxis::AxisPositions];
75 m_data =
new PrivateData;
77 m_data->rescalePolicy = policy;
99 if ( m_data->isEnabled != on )
101 m_data->isEnabled = on;
106 if ( m_data->isEnabled )
107 w->installEventFilter(
this );
109 w->removeEventFilter(
this );
120 return m_data->isEnabled;
131 m_data->rescalePolicy = policy;
140 return m_data->rescalePolicy;
151 m_data->referenceAxis = axisId;
160 return m_data->referenceAxis;
172 for (
int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
186 if ( AxisData* axisData = m_data->axisData( axisId ) )
187 axisData->expandingDirection = direction;
199 if (
const AxisData* axisData = m_data->axisData( axisId ) )
200 return axisData->expandingDirection;
214 for (
int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
228 if ( AxisData* axisData = m_data->axisData( axisId ) )
233 axisData->aspectRatio = ratio;
245 if ( AxisData* axisData = m_data->axisData( axisId ) )
246 return axisData->aspectRatio;
264 if ( AxisData* axisData = m_data->axisData( axisId ) )
275 if ( AxisData* axisData = m_data->axisData( axisId ) )
276 return axisData->intervalHint;
284 return qobject_cast< QWidget* >( parent() );
290 return qobject_cast< const QWidget* >( parent() );
298 w = w->parentWidget();
300 return qobject_cast< QwtPlot* >( w );
306 const QWidget* w =
canvas();
308 w = w->parentWidget();
310 return qobject_cast< const QwtPlot* >( w );
316 if (
object &&
object ==
canvas() )
318 switch ( event->type() )
325 case QEvent::PolishRequest:
345 const QMargins m =
canvas()->contentsMargins();
346 const QSize marginSize( m.left() + m.right(), m.top() + m.bottom() );
348 const QSize newSize =
event->size() - marginSize;
349 const QSize oldSize =
event->oldSize() - marginSize;
357 const QSize size =
canvas()->contentsRect().size();
368 const QSize& oldSize,
const QSize& newSize )
const
370 if ( newSize.isEmpty() )
374 for (
int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
376 const QwtAxisId axisId( axisPos );
377 intervals[axisPos] =
interval( axisId );
381 intervals[refAxis] =
expandScale( refAxis, oldSize, newSize );
383 for (
int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
385 const QwtAxisId axisId( axisPos );
386 if (
aspectRatio( axisId ) > 0.0 && axisId != refAxis )
389 axisId, intervals[refAxis], newSize );
406 const QSize& oldSize,
const QSize& newSize )
const
419 if ( !oldSize.isEmpty() )
421 double width = oldInterval.
width();
423 width *= double( newSize.width() ) / oldSize.width();
425 width *= double( newSize.height() ) / oldSize.height();
435 for (
int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
437 const QwtAxisId axisId( axisPos );
438 const double d = pixelDist( axisId, newSize );
446 width = newSize.width() * dist;
448 width = newSize.height() * dist;
470 const QwtInterval& reference,
const QSize& size )
const
474 dist = reference.
width() / size.width();
476 dist = reference.
width() / size.height();
479 dist *= size.width();
481 dist *= size.height();
511 if ( !
plot()->isAxisValid( axisId ) )
553double QwtPlotRescaler::pixelDist( QwtAxisId axisId,
const QSize& size )
const
568 dist = intv.
width() * r;
575 dist /= size.width();
577 dist /= size.height();
589 QwtInterval intervals[QwtAxis::AxisPositions] )
const
591 if ( m_data->inReplot >= 5 )
601 for (
int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
604 const QwtAxisId axisId( axisPos );
608 double v1 = intervals[axisPos].minValue();
609 double v2 = intervals[axisPos].maxValue();
614 if ( m_data->inReplot >= 1 )
615 m_data->axisData( axisId )->scaleDiv = plt->
axisScaleDiv( axisId );
617 if ( m_data->inReplot >= 2 )
621 ticks[t] = m_data->axisData( axisId )->scaleDiv.
ticks( t );
635 bool immediatePaint =
false;
648 if (
canvas && immediatePaint )
654#include "moc_qwt_plot_rescaler.cpp"
A class representing an interval.
QwtInterval normalized() const
Normalize the limits of the interval.
double width() const
Return the width of an interval.
void setAxisScale(QwtAxisId, double min, double max, double stepSize=0)
Disable autoscaling and specify a fixed scale for a selected axis.
virtual void replot()
Redraw the plot.
void setAutoReplot(bool=true)
Set or reset the autoReplot option.
const QwtScaleDiv & axisScaleDiv(QwtAxisId) const
Return the scale division of a specified axis.
void setAxisScaleDiv(QwtAxisId, const QwtScaleDiv &)
Disable autoscaling and specify a fixed scale for a selected axis.
QwtPlotRescaler takes care of fixed aspect ratios for plot scales.
QwtAxisId referenceAxis() const
void setIntervalHint(QwtAxisId, const QwtInterval &)
QwtInterval intervalHint(QwtAxisId) const
@ ExpandUp
The upper limit of the scale is adjusted.
@ ExpandBoth
Both limits of the scale are adjusted.
@ ExpandDown
The lower limit of the scale is adjusted.
ExpandingDirection expandingDirection(QwtAxisId) const
void setAspectRatio(double ratio)
QwtInterval expandInterval(const QwtInterval &, double width, ExpandingDirection) const
virtual QwtInterval expandScale(QwtAxisId, const QSize &oldSize, const QSize &newSize) const
virtual void canvasResizeEvent(QResizeEvent *)
virtual bool eventFilter(QObject *, QEvent *) override
Event filter for the plot canvas.
void setEnabled(bool)
En/disable the rescaler.
Qt::Orientation orientation(QwtAxisId) const
QwtInterval interval(QwtAxisId) const
virtual void updateScales(QwtInterval intervals[QwtAxis::AxisPositions]) const
virtual QwtInterval syncScale(QwtAxisId, const QwtInterval &reference, const QSize &size) const
double aspectRatio(QwtAxisId) const
QwtPlotRescaler(QWidget *canvas, QwtAxisId referenceAxis=QwtAxis::XBottom, RescalePolicy=Expanding)
void setExpandingDirection(ExpandingDirection)
RescalePolicy rescalePolicy() const
virtual ~QwtPlotRescaler()
Destructor.
void setRescalePolicy(RescalePolicy)
void setReferenceAxis(QwtAxisId)
void rescale() const
Adjust the plot axes scales.
A class representing a scale division.
QwtInterval interval() const
QList< double > ticks(int tickType) const
bool isIncreasing() const
Check if the scale division is increasing( lowerBound() <= upperBound() )
@ NTickTypes
Number of valid tick types.
bool isYAxis(int axisPos)
@ XBottom
X axis below the canvas.
bool isValid(int axisPos)