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
 
@@ -17,8 +17,8 @@
 
  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),
 
@@ -31,6 +31,9 @@ Plot::Plot(QWidget* parent) :
 
    zoomer.setZoomBase();
 
    grid.attach(this);
 

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

	
 
    darkBackground(false);
 
}
 

	
plot.h
Show inline comments
 
@@ -22,6 +22,7 @@
 

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

	
 
@@ -39,6 +40,7 @@ private:
 
    Zoomer zoomer;
 
    ScaleZoomer sZoomer;
 
    QwtPlotGrid grid;
 
    QwtPlotShapeItem rectItem;
 

	
 
    void resetAxes();
 

	
scalezoomer.cpp
Show inline comments
 
@@ -28,10 +28,35 @@ ScaleZoomer::ScaleZoomer(QwtPlot* plot, 
 
{
 
    _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;
 
@@ -49,6 +74,8 @@ void ScaleZoomer::bottomPicked(double fi
 
    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)
scalezoomer.h
Show inline comments
 
@@ -23,6 +23,7 @@
 
#include <QObject>
 
#include <qwt_plot.h>
 
#include <qwt_plot_zoomer.h>
 
#include <qwt_plot_shapeitem.h>
 

	
 
#include "scalepicker.h"
 

	
 
@@ -39,9 +40,12 @@ private:
 
    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);
 
};
 

	
0 comments (0 inline, 0 general)