/************************************************************
SigLibGraph.cpp
AW - 31.03.2012
************************************************************/
#include <QApplication>
#include <QtDebug>
#include <qpainter.h>
#include <qwt_plot.h>
#include <qwt_scale_engine.h>
#include <qwt_symbol.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_text.h>
#include <qwt_picker.h>
#include <qwt_picker_machine.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_renderer.h>
#include <qwt_event_pattern.h>
#include <qwt_text.h>
#include "SigLibGraph.h"
{
// plot object
setTitle( plotTitle );
setCanvasBackground
( QColor( Qt
::darkBlue ));
// axis
setAxisTitle
( QwtPlot::xBottom, xLabel
);
setAxisTitle
( QwtPlot::yLeft, yLabel
);
// grid
grid->enableXMin( true );
grid
->setMajPen
( QPen( Qt
::white,
0, Qt
::DotLine ));
grid
->setMinPen
( QPen( Qt
::gray,
0 , Qt
::DotLine ));
grid->attach( this );
// legend
insertLegend
( legend,
QwtPlot::RightLegend );
//zoomer
this->canvas() );
zoomer
->setRubberBand
( QwtPicker::RectRubberBand );
zoomer
->setRubberBandPen
( QColor( Qt
::green ));
zoomer
->setTrackerMode
( QwtPicker::ActiveOnly );
zoomer
->setTrackerPen
( QColor( Qt
::white ));
// RightButton: zoom out by one step
Qt::RightButton );
// Ctrl+RightButton: zoom out to full size
Qt::RightButton,
Qt::ControlModifier );
// handle zoom base
connect( zoomer,
SLOT( autoRescale
( QRectF )));
// resize Widget
resize( 600, 400 );
show();
}
void Plot2D
::autoRescale( QRectF ) {
qDebug("Plot2D::autoRescale called!");
if( zoomer->zoomRectIndex() == 0 ) // autorescale only if you are at base...
{
this
->setAxisAutoScale
( QwtPlot::xBottom );
this
->setAxisAutoScale
( QwtPlot::yLeft );
this->updateAxes();
zoomer->setZoomBase( false );
}
}
void Plot2D::attachCurve( double *xData,
double *yData,
uint dataCount,
{
// define the curve object
curve->setSamples( xData, yData, dataCount );
curve
->setPen
( QPen( curveColor
));
curve
->setRenderHint
( QwtPlotItem::RenderAntialiased );
curve->setTitle( curveLabel );
// qDebug() << "curveLabel.isEmpty = " << curveLabel.isEmpty();
if ( curveLabel.isEmpty() )
else
curve->attach( this );
}
void Plot2D::setXAxisScale( double firstValue, double lastValue )
{
setAxisScale( xBottom, firstValue, lastValue );
}
void Plot2D::setYAxisScale( double firstValue, double lastValue )
{
setAxisScale( yLeft, firstValue, lastValue );
}
void Plot2D::setXLogAxis()
{
}
void Plot2D::setYLogAxis()
{
}
void Plot2D
::setBackgroundColor( QColor backgroundColor
) {
setCanvasBackground( backgroundColor );
}
{
}