Changeset - b0ad4149e405
[Not reviewed]
scalezoomer
0 4 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-08-26 11:11:37
hy@ozderya.net
show rectange for bottom scale zoomer
4 files changed with 37 insertions and 1 deletions:
0 comments (0 inline, 0 general)
plot.cpp
Show inline comments
 
@@ -14,26 +14,29 @@
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include <QRectF>
 
#include "plot.h"
 

	
 
Plot::Plot(QWidget* parent) :
 
    QwtPlot(parent),
 
    zoomer(this->canvas(), false),
 
    sZoomer(this, &zoomer)
 
{
 
    isAutoScaled = false;
 

	
 
    QObject::connect(&zoomer, &Zoomer::unzoomed, this, &Plot::unzoomed);
 

	
 
    zoomer.setZoomBase();
 
    grid.attach(this);
 

	
 
    rectItem.setRect(QRectF(0,0,100,1));
 
    // rectItem.attach(this);
 

	
 
    darkBackground(false);
 
}
 

	
 
void Plot::setAxis(bool autoScaled, double yAxisMin, double yAxisMax)
 
{
 
    this->isAutoScaled = autoScaled;
plot.h
Show inline comments
 
@@ -19,12 +19,13 @@
 

	
 
#ifndef PLOT_H
 
#define PLOT_H
 

	
 
#include <qwt_plot.h>
 
#include <qwt_plot_grid.h>
 
#include <qwt_plot_shapeitem.h>
 
#include "zoomer.h"
 
#include "scalezoomer.h"
 

	
 
class Plot : public QwtPlot
 
{
 
    Q_OBJECT
 
@@ -36,12 +37,13 @@ public:
 
private:
 
    bool isAutoScaled;
 
    double yMin, yMax;
 
    Zoomer zoomer;
 
    ScaleZoomer sZoomer;
 
    QwtPlotGrid grid;
 
    QwtPlotShapeItem rectItem;
 

	
 
    void resetAxes();
 

	
 
public slots:
 
    void showGrid(bool show = true);
 
    void showMinorGrid(bool show = true);
scalezoomer.cpp
Show inline comments
 
@@ -25,16 +25,41 @@ ScaleZoomer::ScaleZoomer(QwtPlot* plot, 
 
    QObject(plot),
 
    bottomPicker(plot->axisWidget(QwtPlot::xBottom)),
 
    leftPicker(plot->axisWidget(QwtPlot::yLeft))
 
{
 
    _plot = plot;
 
    _zoomer = zoomer;
 
    connect(&bottomPicker, &ScalePicker::pickStarted, this, &ScaleZoomer::bottomPickStarted);
 
    connect(&bottomPicker, &ScalePicker::picking, this, &ScaleZoomer::bottomPicking);
 
    connect(&bottomPicker, &ScalePicker::picked, this, &ScaleZoomer::bottomPicked);
 
    connect(&leftPicker, &ScalePicker::picked, this, &ScaleZoomer::leftPicked);
 
}
 

	
 
void ScaleZoomer::bottomPickStarted(double firstPos)
 
{
 
    double yMin = _plot->axisScaleDiv(QwtPlot::yLeft).lowerBound();
 
    double yMax = _plot->axisScaleDiv(QwtPlot::yLeft).upperBound();
 
    rectShape.setRect(QRectF(firstPos, yMin, 2, yMax-yMin));
 
    rectShape.attach(_plot);
 
    _plot->replot();
 
}
 

	
 
void ScaleZoomer::bottomPicking(double firstPos, double lastPos)
 
{
 
    double yMin = _plot->axisScaleDiv(QwtPlot::yLeft).lowerBound();
 
    double yMax = _plot->axisScaleDiv(QwtPlot::yLeft).upperBound();
 
    if (lastPos > firstPos) {
 
        rectShape.setRect(QRectF(firstPos, yMin, lastPos-firstPos, yMax-yMin));
 
    }
 
    else
 
    {
 
        rectShape.setRect(QRectF(lastPos, yMin, firstPos-lastPos, yMax-yMin));
 
    }
 
    _plot->replot();
 
}
 

	
 
void ScaleZoomer::bottomPicked(double firstPos, double lastPos)
 
{
 
    QRectF zRect;
 
    if (lastPos > firstPos)
 
    {
 
        zRect.setLeft(firstPos);
 
@@ -46,12 +71,14 @@ void ScaleZoomer::bottomPicked(double fi
 
        zRect.setRight(firstPos);
 
    }
 

	
 
    zRect.setBottom(_plot->axisScaleDiv(QwtPlot::yLeft).lowerBound());
 
    zRect.setTop(_plot->axisScaleDiv(QwtPlot::yLeft).upperBound());
 
    _zoomer->zoom(zRect);
 
    rectShape.detach();
 
    _plot->replot();
 
}
 

	
 
void ScaleZoomer::leftPicked(double firstPos, double lastPos)
 
{
 
    QRectF zRect;
 
    if (lastPos > firstPos)
scalezoomer.h
Show inline comments
 
@@ -20,12 +20,13 @@
 
#ifndef SCALEZOOMER_H
 
#define SCALEZOOMER_H
 

	
 
#include <QObject>
 
#include <qwt_plot.h>
 
#include <qwt_plot_zoomer.h>
 
#include <qwt_plot_shapeitem.h>
 

	
 
#include "scalepicker.h"
 

	
 
class ScaleZoomer : public QObject
 
{
 
    Q_OBJECT
 
@@ -36,13 +37,16 @@ public:
 
private:
 
    QwtPlot* _plot;
 
    QwtPlotZoomer* _zoomer;
 
    ScalePicker bottomPicker;
 
    ScalePicker leftPicker;
 

	
 
    QwtPlotShapeItem rectShape;
 

	
 
private slots:
 
    void bottomPickStarted(double firstPos);
 
    void bottomPicked(double firstPos, double lastPos);
 
    void bottomPicking(double firstPos, double lastPos);
 
    void leftPicked(double firstPos, double lastPos);
 
};
 

	
 
#endif /* SCALEZOOMER_H */
0 comments (0 inline, 0 general)