qwt_plot_zoomer.h 3.8 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

// vim: expandtab

#ifndef QWT_PLOT_ZOOMER_H
#define QWT_PLOT_ZOOMER_H

#include <qglobal.h>
#if QT_VERSION < 0x040000
#include <qvaluestack.h>
#else
#include <qstack.h>
#endif

#include "qwt_double_rect.h"
#include "qwt_plot_picker.h"

/*!
  \brief QwtPlotZoomer provides stacked zooming for a plot widget

28
  QwtPlotZoomer offers rubberband selections on the plot canvas,
pixhawk's avatar
pixhawk committed
29
  translating the selected rectangles into plot coordinates and
30 31 32
  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.
pixhawk's avatar
pixhawk committed
33 34 35

  Zoom rectangles can be selected depending on selectionFlags() using the
  mouse or keyboard (QwtEventPattern, QwtPickerMachine).
36 37
  QwtEventPattern::MouseSelect3/QwtEventPattern::KeyUndo,
  or QwtEventPattern::MouseSelect6/QwtEventPattern::KeyRedo
pixhawk's avatar
pixhawk committed
38 39
  walk up and down the zoom stack.
  QwtEventPattern::MouseSelect2 or QwtEventPattern::KeyHome unzoom to
40 41
  the initial size.

pixhawk's avatar
pixhawk committed
42 43 44
  QwtPlotZoomer is tailored for plots with one x and y axis, but it is
  allowed to attach a second QwtPlotZoomer for the other axes.

45
  \note The realtime example includes an derived zoomer class that adds
pixhawk's avatar
pixhawk committed
46 47 48 49 50 51 52 53
        scrollbars to the plot canvas.
*/

class QWT_EXPORT QwtPlotZoomer: public QwtPlotPicker
{
    Q_OBJECT
public:
    explicit QwtPlotZoomer(QwtPlotCanvas *, bool doReplot = true);
54 55
    explicit QwtPlotZoomer(int xAxis, int yAxis,
                           QwtPlotCanvas *, bool doReplot = true);
pixhawk's avatar
pixhawk committed
56
    explicit QwtPlotZoomer(int xAxis, int yAxis, int selectionFlags,
57 58
                           DisplayMode trackerMode, QwtPlotCanvas *,
                           bool doReplot = true);
pixhawk's avatar
pixhawk committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

    virtual ~QwtPlotZoomer();

    virtual void setZoomBase(bool doReplot = true);
    virtual void setZoomBase(const QwtDoubleRect &);

    QwtDoubleRect zoomBase() const;
    QwtDoubleRect zoomRect() const;

    virtual void setAxis(int xAxis, int yAxis);

    void setMaxStackDepth(int);
    int maxStackDepth() const;

#if QT_VERSION < 0x040000
    const QValueStack<QwtDoubleRect> &zoomStack() const;
    void setZoomStack(const QValueStack<QwtDoubleRect> &,
76
                      int zoomRectIndex = -1);
pixhawk's avatar
pixhawk committed
77 78 79
#else
    const QStack<QwtDoubleRect> &zoomStack() const;
    void setZoomStack(const QStack<QwtDoubleRect> &,
80
                      int zoomRectIndex = -1);
pixhawk's avatar
pixhawk committed
81 82 83 84 85 86 87
#endif
    uint zoomRectIndex() const;

    virtual void setSelectionFlags(int);

public slots:
    void moveBy(double x, double y);
Don Gagne's avatar
Don Gagne committed
88 89 90 91 92 93 94

// These pragmas are local modifications to this third party library to silence warnings
#ifndef Q_OS_WIN
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
#endif
    
pixhawk's avatar
pixhawk committed
95 96
    virtual void move(double x, double y);

Don Gagne's avatar
Don Gagne committed
97 98 99 100
#ifndef Q_OS_WIN
#pragma GCC diagnostic pop
#endif

pixhawk's avatar
pixhawk committed
101 102 103 104 105
    virtual void zoom(const QwtDoubleRect &);
    virtual void zoom(int up);

signals:
    /*!
106
      A signal emitting the zoomRect(), when the plot has been
pixhawk's avatar
pixhawk committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
      zoomed in or out.

      \param rect Current zoom rectangle.
    */

    void zoomed(const QwtDoubleRect &rect);

protected:
    virtual void rescale();

    virtual QwtDoubleSize minZoomSize() const;

    virtual void widgetMouseReleaseEvent(QMouseEvent *);
    virtual void widgetKeyPressEvent(QKeyEvent *);

    virtual void begin();
    virtual bool end(bool ok = true);
    virtual bool accept(QwtPolygon &) const;

private:
    void init(int selectionFlags, DisplayMode trackerMode, bool doReplot);

    class PrivateData;
    PrivateData *d_data;
};
132

pixhawk's avatar
pixhawk committed
133
#endif