QwtPlotZoomer provides stacked zooming for a plot widget. More...
#include <qwt_plot_zoomer.h>
Classes | |
class | PrivateData |
Public Slots | |
void | moveBy (double x, double y) |
virtual void | move (double x, double y) |
virtual void | zoom (const QwtDoubleRect &) |
Zoom in. | |
virtual void | zoom (int up) |
Zoom in or out. | |
Signals | |
void | zoomed (const QwtDoubleRect &rect) |
Public Member Functions | |
QwtPlotZoomer (QwtPlotCanvas *, bool doReplot=true) | |
Create a zoomer for a plot canvas. | |
QwtPlotZoomer (int xAxis, int yAxis, QwtPlotCanvas *, bool doReplot=true) | |
Create a zoomer for a plot canvas. | |
QwtPlotZoomer (int xAxis, int yAxis, int selectionFlags, DisplayMode trackerMode, QwtPlotCanvas *, bool doReplot=true) | |
virtual | ~QwtPlotZoomer () |
virtual void | setZoomBase (bool doReplot=true) |
virtual void | setZoomBase (const QwtDoubleRect &) |
Set the initial size of the zoomer. | |
QwtDoubleRect | zoomBase () const |
QwtDoubleRect | zoomRect () const |
virtual void | setAxis (int xAxis, int yAxis) |
void | setMaxStackDepth (int) |
Limit the number of recursive zoom operations to depth. | |
int | maxStackDepth () const |
const QValueStack < QwtDoubleRect > & | zoomStack () const |
void | setZoomStack (const QValueStack< QwtDoubleRect > &, int zoomRectIndex=-1) |
uint | zoomRectIndex () const |
virtual void | setSelectionFlags (int) |
Protected Member Functions | |
virtual void | rescale () |
virtual QwtDoubleSize | minZoomSize () const |
Limit zooming by a minimum rectangle. | |
virtual void | widgetMouseReleaseEvent (QMouseEvent *) |
virtual void | widgetKeyPressEvent (QKeyEvent *) |
virtual void | begin () |
virtual bool | end (bool ok=true) |
virtual bool | accept (QwtPolygon &) const |
Check and correct a selected rectangle. |
QwtPlotZoomer provides stacked zooming for a plot widget.
QwtPlotZoomer offers rubberband selections on the plot canvas, translating the selected rectangles into plot coordinates and adjusting the axes to them. Zooming can repeated as often as possible, limited only by maxStackDepth() or minZoomSize(). Each rectangle is pushed on a stack.
Zoom rectangles can be selected depending on selectionFlags() using the mouse or keyboard (QwtEventPattern, QwtPickerMachine). QwtEventPattern::MouseSelect3/QwtEventPatternKeyUndo, or QwtEventPattern::MouseSelect6/QwtEventPatternKeyRedo walk up and down the zoom stack. QwtEventPattern::MouseSelect2 or QwtEventPattern::KeyHome unzoom to the initial size.
QwtPlotZoomer is tailored for plots with one x and y axis, but it is allowed to attach a second QwtPlotZoomer for the other axes.
Definition at line 49 of file qwt_plot_zoomer.h.
QwtPlotZoomer::QwtPlotZoomer | ( | QwtPlotCanvas * | canvas, |
bool | doReplot = true |
||
) | [explicit] |
Create a zoomer for a plot canvas.
The zoomer is set to those x- and y-axis of the parent plot of the canvas that are enabled. If both or no x-axis are enabled, the picker is set to QwtPlot::xBottom. If both or no y-axis are enabled, it is set to QwtPlot::yLeft.
The selectionFlags() are set to QwtPicker::RectSelection & QwtPicker::ClickSelection, the tracker mode to QwtPicker::ActiveOnly.
canvas | Plot canvas to observe, also the parent object |
doReplot | Call replot for the attached plot before initializing the zoomer with its scales. This might be necessary, when the plot is in a state with pending scale changes. |
Definition at line 51 of file qwt_plot_zoomer.cpp.
References QwtPicker::ActiveOnly, QwtPicker::ClickSelection, and QwtPicker::RectSelection.
: QwtPlotPicker(canvas) { if ( canvas ) init(RectSelection & ClickSelection, ActiveOnly, doReplot); }
QwtPlotZoomer::QwtPlotZoomer | ( | int | xAxis, |
int | yAxis, | ||
QwtPlotCanvas * | canvas, | ||
bool | doReplot = true |
||
) | [explicit] |
Create a zoomer for a plot canvas.
The selectionFlags() are set to QwtPicker::RectSelection & QwtPicker::ClickSelection, the tracker mode to QwtPicker::ActiveOnly.
xAxis | X axis of the zoomer |
yAxis | Y axis of the zoomer |
canvas | Plot canvas to observe, also the parent object |
doReplot | Call replot for the attached plot before initializing the zoomer with its scales. This might be necessary, when the plot is in a state with pending scale changes. |
Definition at line 75 of file qwt_plot_zoomer.cpp.
References QwtPicker::ActiveOnly, QwtPicker::ClickSelection, and QwtPicker::RectSelection.
: QwtPlotPicker(xAxis, yAxis, canvas) { if ( canvas ) init(RectSelection & ClickSelection, ActiveOnly, doReplot); }
QwtPlotZoomer::QwtPlotZoomer | ( | int | xAxis, |
int | yAxis, | ||
int | selectionFlags, | ||
DisplayMode | trackerMode, | ||
QwtPlotCanvas * | canvas, | ||
bool | doReplot = true |
||
) | [explicit] |
Create a zoomer for a plot canvas.
xAxis | X axis of the zoomer |
yAxis | Y axis of the zoomer |
selectionFlags | Or'd value of QwtPicker::RectSelectionType and QwtPicker::SelectionMode. QwtPicker::RectSelection will be auto added. |
trackerMode | Tracker mode |
canvas | Plot canvas to observe, also the parent object |
doReplot | Call replot for the attached plot before initializing the zoomer with its scales. This might be necessary, when the plot is in a state with pending scale changes. |
Definition at line 103 of file qwt_plot_zoomer.cpp.
: QwtPlotPicker(xAxis, yAxis, canvas) { if ( canvas ) init(selectionFlags, trackerMode, doReplot); }
QwtPlotZoomer::~QwtPlotZoomer | ( | ) | [virtual] |
Definition at line 129 of file qwt_plot_zoomer.cpp.
{
delete d_data;
}
bool QwtPlotZoomer::accept | ( | QwtPolygon & | pa ) | const [protected, virtual] |
Check and correct a selected rectangle.
Reject rectangles with a hight or width < 2, otherwise expand the selected rectangle to a minimum size of 11x11 and accept it.
Reimplemented from QwtPicker.
Definition at line 539 of file qwt_plot_zoomer.cpp.
References minZoomSize().
{ if ( pa.count() < 2 ) return false; QRect rect = QRect(pa[0], pa[int(pa.count()) - 1]); #if QT_VERSION < 0x040000 rect = rect.normalize(); #else rect = rect.normalized(); #endif const int minSize = 2; if (rect.width() < minSize && rect.height() < minSize ) return false; const int minZoomSize = 11; const QPoint center = rect.center(); rect.setSize(rect.size().expandedTo(QSize(minZoomSize, minZoomSize))); rect.moveCenter(center); pa.resize(2); pa[0] = rect.topLeft(); pa[1] = rect.bottomRight(); return true; }
void QwtPlotZoomer::begin | ( | ) | [protected, virtual] |
Rejects selections, when the stack depth is too deep, or the zoomed rectangle is minZoomSize().
Reimplemented from QwtPicker.
Definition at line 587 of file qwt_plot_zoomer.cpp.
References QwtDoubleSize::height(), QwtDoubleSize::isValid(), QwtPlotZoomer::PrivateData::maxStackDepth, minZoomSize(), QwtDoubleSize::width(), QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
{ if ( d_data->maxStackDepth >= 0 ) { if ( d_data->zoomRectIndex >= uint(d_data->maxStackDepth) ) return; } const QwtDoubleSize minSize = minZoomSize(); if ( minSize.isValid() ) { const QwtDoubleSize sz = d_data->zoomStack[d_data->zoomRectIndex].size() * 0.9999; if ( minSize.width() >= sz.width() && minSize.height() >= sz.height() ) { return; } } QwtPlotPicker::begin(); }
bool QwtPlotZoomer::end | ( | bool | ok = true ) |
[protected, virtual] |
Expand the selected rectangle to minZoomSize() and zoom in if accepted.
Reimplemented from QwtPlotPicker.
Definition at line 617 of file qwt_plot_zoomer.cpp.
References QwtDoubleRect::center(), QwtDoubleSize::expandedTo(), QwtPlotPicker::invTransform(), minZoomSize(), QwtDoubleRect::moveCenter(), QwtDoubleRect::normalized(), QwtPlotPicker::plot(), QwtPicker::selection(), QwtDoubleRect::setSize(), QwtDoubleRect::size(), zoom(), and zoomRect().
{ ok = QwtPlotPicker::end(ok); if (!ok) return false; QwtPlot *plot = QwtPlotZoomer::plot(); if ( !plot ) return false; const QwtPolygon &pa = selection(); if ( pa.count() < 2 ) return false; QRect rect = QRect(pa[0], pa[int(pa.count() - 1)]); #if QT_VERSION < 0x040000 rect = rect.normalize(); #else rect = rect.normalized(); #endif QwtDoubleRect zoomRect = invTransform(rect).normalized(); const QwtDoublePoint center = zoomRect.center(); zoomRect.setSize(zoomRect.size().expandedTo(minZoomSize())); zoomRect.moveCenter(center); zoom(zoomRect); return true; }
int QwtPlotZoomer::maxStackDepth | ( | ) | const |
Definition at line 172 of file qwt_plot_zoomer.cpp.
References QwtPlotZoomer::PrivateData::maxStackDepth.
{ return d_data->maxStackDepth; }
QwtDoubleSize QwtPlotZoomer::minZoomSize | ( | ) | const [protected, virtual] |
Limit zooming by a minimum rectangle.
Definition at line 573 of file qwt_plot_zoomer.cpp.
References QwtPlotZoomer::PrivateData::zoomStack.
Referenced by accept(), begin(), and end().
{ return QwtDoubleSize( d_data->zoomStack[0].width() / 10e4, d_data->zoomStack[0].height() / 10e4 ); }
void QwtPlotZoomer::move | ( | double | x, |
double | y | ||
) | [virtual, slot] |
Move the the current zoom rectangle.
x | X value |
y | Y value |
Definition at line 509 of file qwt_plot_zoomer.cpp.
References QwtDoubleRect::bottom(), QwtDoubleRect::height(), QwtDoubleRect::left(), rescale(), QwtDoubleRect::right(), QwtDoubleRect::top(), QwtDoubleRect::width(), zoomBase(), zoomRect(), QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
Referenced by moveBy().
{ if ( x < zoomBase().left() ) x = zoomBase().left(); if ( x > zoomBase().right() - zoomRect().width() ) x = zoomBase().right() - zoomRect().width(); if ( y < zoomBase().top() ) y = zoomBase().top(); if ( y > zoomBase().bottom() - zoomRect().height() ) y = zoomBase().bottom() - zoomRect().height(); if ( x != zoomRect().left() || y != zoomRect().top() ) { d_data->zoomStack[d_data->zoomRectIndex].moveTo(x, y); rescale(); } }
void QwtPlotZoomer::moveBy | ( | double | dx, |
double | dy | ||
) | [slot] |
Move the current zoom rectangle.
dx | X offset |
dy | Y offset |
Definition at line 494 of file qwt_plot_zoomer.cpp.
References QwtDoubleRect::left(), move(), QwtDoubleRect::top(), QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
{ const QwtDoubleRect &rect = d_data->zoomStack[d_data->zoomRectIndex]; move(rect.left() + dx, rect.top() + dy); }
void QwtPlotZoomer::rescale | ( | ) | [protected, virtual] |
Adjust the observed plot to zoomRect()
Definition at line 385 of file qwt_plot_zoomer.cpp.
References QwtPlot::autoReplot(), QwtPlot::axisScaleDiv(), QwtDoubleRect::bottom(), QwtDoubleRect::left(), QwtScaleDiv::lowerBound(), QwtPlotPicker::plot(), QwtPlot::replot(), QwtDoubleRect::right(), QwtPlotPicker::scaleRect(), QwtPlot::setAutoReplot(), QwtPlot::setAxisScale(), QwtDoubleRect::top(), QwtScaleDiv::upperBound(), QwtPlotPicker::xAxis(), QwtPlotPicker::yAxis(), QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
Referenced by move(), setZoomBase(), and zoom().
{ QwtPlot *plt = plot(); if ( !plt ) return; const QwtDoubleRect &rect = d_data->zoomStack[d_data->zoomRectIndex]; if ( rect != scaleRect() ) { const bool doReplot = plt->autoReplot(); plt->setAutoReplot(false); double x1 = rect.left(); double x2 = rect.right(); if ( plt->axisScaleDiv(xAxis())->lowerBound() > plt->axisScaleDiv(xAxis())->upperBound() ) { qSwap(x1, x2); } plt->setAxisScale(xAxis(), x1, x2); double y1 = rect.top(); double y2 = rect.bottom(); if ( plt->axisScaleDiv(yAxis())->lowerBound() > plt->axisScaleDiv(yAxis())->upperBound() ) { qSwap(y1, y2); } plt->setAxisScale(yAxis(), y1, y2); plt->setAutoReplot(doReplot); plt->replot(); } }
void QwtPlotZoomer::setAxis | ( | int | xAxis, |
int | yAxis | ||
) | [virtual] |
Reinitialize the axes, and set the zoom base to their scales.
xAxis | X axis |
yAxis | Y axis |
Reimplemented from QwtPlotPicker.
Definition at line 429 of file qwt_plot_zoomer.cpp.
References QwtPlotPicker::scaleRect(), setZoomBase(), QwtPlotPicker::xAxis(), and QwtPlotPicker::yAxis().
{ if ( xAxis != QwtPlotPicker::xAxis() || yAxis != QwtPlotPicker::yAxis() ) { QwtPlotPicker::setAxis(xAxis, yAxis); setZoomBase(scaleRect()); } }
void QwtPlotZoomer::setMaxStackDepth | ( | int | depth ) |
Limit the number of recursive zoom operations to depth.
A value of -1 set the depth to unlimited, 0 disables zooming. If the current zoom rectangle is below depth, the plot is unzoomed.
depth | Maximum for the stack depth |
Definition at line 145 of file qwt_plot_zoomer.cpp.
References int(), QwtPlotZoomer::PrivateData::maxStackDepth, void(), zoom(), QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
{ d_data->maxStackDepth = depth; if ( depth >= 0 ) { // unzoom if the current depth is below d_data->maxStackDepth const int zoomOut = int(d_data->zoomStack.count()) - 1 - depth; // -1 for the zoom base if ( zoomOut > 0 ) { zoom(-zoomOut); for ( int i = int(d_data->zoomStack.count()) - 1; i > int(d_data->zoomRectIndex); i-- ) { (void)d_data->zoomStack.pop(); // remove trailing rects } } } }
void QwtPlotZoomer::setSelectionFlags | ( | int | flags ) | [virtual] |
Set the selection flags
flags | Or'd value of QwtPicker::RectSelectionType and QwtPicker::SelectionMode. The default value is QwtPicker::RectSelection & QwtPicker::ClickSelection. |
Reimplemented from QwtPicker.
Definition at line 661 of file qwt_plot_zoomer.cpp.
References QwtPicker::PointSelection, QwtPicker::PolygonSelection, and QwtPicker::RectSelection.
Referenced by QmitkHistogramWidget::InitializeZoomer().
{ // we accept only rects flags &= ~(PointSelection | PolygonSelection); flags |= RectSelection; QwtPlotPicker::setSelectionFlags(flags); }
void QwtPlotZoomer::setZoomBase | ( | bool | doReplot = true ) |
[virtual] |
Reinitialized the zoom stack with scaleRect() as base.
doReplot | Call replot for the attached plot before initializing the zoomer with its scales. This might be necessary, when the plot is in a state with pending scale changes. |
Definition at line 206 of file qwt_plot_zoomer.cpp.
References QwtPlotPicker::plot(), QwtPlot::replot(), rescale(), QwtPlotPicker::scaleRect(), QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
Referenced by setAxis().
void QwtPlotZoomer::setZoomBase | ( | const QwtDoubleRect & | base ) | [virtual] |
Set the initial size of the zoomer.
base is united with the current scaleRect() and the zoom stack is reinitalized with it as zoom base. plot is zoomed to scaleRect().
base | Zoom base |
Definition at line 232 of file qwt_plot_zoomer.cpp.
References QwtPlotPicker::plot(), rescale(), QwtPlotPicker::scaleRect(), QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
{ const QwtPlot *plt = plot(); if ( !plt ) return; const QwtDoubleRect sRect = scaleRect(); const QwtDoubleRect bRect = base | sRect; d_data->zoomStack.clear(); d_data->zoomStack.push(bRect); d_data->zoomRectIndex = 0; if ( base != sRect ) { d_data->zoomStack.push(sRect); d_data->zoomRectIndex++; } rescale(); }
void QwtPlotZoomer::setZoomStack | ( | const QValueStack< QwtDoubleRect > & | , |
int | zoomRectIndex = -1 |
||
) |
void QwtPlotZoomer::widgetKeyPressEvent | ( | QKeyEvent * | ke ) | [protected, virtual] |
Qt::Key_Plus zooms out, Qt::Key_Minus zooms in one position on the zoom stack, Qt::Key_Escape zooms out to the zoom base.
Changes the current position on the stack, but doesn't pop any rectangle.
Reimplemented from QwtPicker.
Definition at line 471 of file qwt_plot_zoomer.cpp.
References QwtPicker::isActive(), QwtEventPattern::KeyHome, QwtEventPattern::keyMatch(), QwtEventPattern::KeyRedo, QwtEventPattern::KeyUndo, and zoom().
void QwtPlotZoomer::widgetMouseReleaseEvent | ( | QMouseEvent * | me ) | [protected, virtual] |
Qt::MidButton zooms out one position on the zoom stack, Qt::RightButton to the zoom base.
Changes the current position on the stack, but doesn't pop any rectangle.
Reimplemented from QwtPicker.
Definition at line 448 of file qwt_plot_zoomer.cpp.
References QwtEventPattern::mouseMatch(), QwtEventPattern::MouseSelect2, QwtEventPattern::MouseSelect3, QwtEventPattern::MouseSelect6, and zoom().
{ if ( mouseMatch(MouseSelect2, me) ) zoom(0); else if ( mouseMatch(MouseSelect3, me) ) zoom(-1); else if ( mouseMatch(MouseSelect6, me) ) zoom(+1); else QwtPlotPicker::widgetMouseReleaseEvent(me); }
void QwtPlotZoomer::zoom | ( | int | offset ) | [virtual, slot] |
Zoom in or out.
Activate a rectangle on the zoom stack with an offset relative to the current position. Negative values of offest will zoom out, positive zoom in. A value of 0 zooms out to the zoom base.
offset | Offset relative to the current position of the zoom stack. |
Definition at line 320 of file qwt_plot_zoomer.cpp.
References qwtMax, qwtMin, rescale(), zoomed(), zoomRect(), QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
{ if ( offset == 0 ) d_data->zoomRectIndex = 0; else { int newIndex = d_data->zoomRectIndex + offset; newIndex = qwtMax(0, newIndex); newIndex = qwtMin(int(d_data->zoomStack.count()) - 1, newIndex); d_data->zoomRectIndex = uint(newIndex); } rescale(); emit zoomed(zoomRect()); }
void QwtPlotZoomer::zoom | ( | const QwtDoubleRect & | rect ) | [virtual, slot] |
Zoom in.
Clears all rectangles above the current position of the zoom stack and pushs the intersection of zoomRect() and the normalized rect on it.
Definition at line 283 of file qwt_plot_zoomer.cpp.
References QwtPlotZoomer::PrivateData::maxStackDepth, QwtDoubleRect::normalized(), rescale(), void(), zoomed(), zoomRect(), QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
Referenced by end(), setMaxStackDepth(), widgetKeyPressEvent(), and widgetMouseReleaseEvent().
{ if ( d_data->maxStackDepth >= 0 && int(d_data->zoomRectIndex) >= d_data->maxStackDepth ) { return; } const QwtDoubleRect zoomRect = d_data->zoomStack[0] & rect.normalized(); if ( zoomRect != d_data->zoomStack[d_data->zoomRectIndex] ) { for ( uint i = int(d_data->zoomStack.count()) - 1; i > d_data->zoomRectIndex; i-- ) { (void)d_data->zoomStack.pop(); } d_data->zoomStack.push(zoomRect); d_data->zoomRectIndex++; rescale(); emit zoomed(zoomRect); } }
QwtDoubleRect QwtPlotZoomer::zoomBase | ( | ) | const |
Definition at line 192 of file qwt_plot_zoomer.cpp.
References QwtPlotZoomer::PrivateData::zoomStack.
Referenced by move().
{ return d_data->zoomStack[0]; }
void QwtPlotZoomer::zoomed | ( | const QwtDoubleRect & | rect ) | [signal] |
A signal emitting the zoomRect(), when the plot has been zoomed in or out.
rect | Current zoom rectangle. |
Referenced by zoom().
QwtDoubleRect QwtPlotZoomer::zoomRect | ( | ) | const |
Rectangle at the current position on the zoom stack.
Definition at line 259 of file qwt_plot_zoomer.cpp.
References QwtPlotZoomer::PrivateData::zoomRectIndex, and QwtPlotZoomer::PrivateData::zoomStack.
Referenced by end(), move(), and zoom().
{ return d_data->zoomStack[d_data->zoomRectIndex]; }
uint QwtPlotZoomer::zoomRectIndex | ( | ) | const |
Definition at line 267 of file qwt_plot_zoomer.cpp.
References QwtPlotZoomer::PrivateData::zoomRectIndex.
{ return d_data->zoomRectIndex; }
const QwtZoomStack & QwtPlotZoomer::zoomStack | ( | ) | const |
Return the zoom stack. zoomStack()[0] is the zoom base, zoomStack()[1] the first zoomed rectangle.
Definition at line 183 of file qwt_plot_zoomer.cpp.
References QwtPlotZoomer::PrivateData::zoomStack.
{ return d_data->zoomStack; }