// implementation
{
// plot object
setWindowTitle
( QString( "SigLibGraph - Plot2D" ));
setTitle( plotTitle );
setCanvasBackground( backgroundColor);
// window size and position
setMinimumSize
( QSize( 240,
170 ));
mWindowWidth = 550; mWindowHeight = 365;
mWindowXPosition = 200; mWindowYPosition = 200;
setGeometry( mWindowXPosition, mWindowYPosition, mWindowWidth, mWindowHeight );
// 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
...
// print functionality
...
// export functionality
...
show();
}
void Plot2D::attachCurve( SLData_t* xData,
SLData_t* yData,
int dataCount,
{
curve->setSamples( xData, yData, dataCount );
// following works well
//qDebug() << "xMin=" << curve->minXValue() << " | xMax=" << curve->maxXValue()
// << " | yMin=" << curve->minYValue() << " | yMax=" << curve->maxYValue()
// << " | data count=" << curve->dataSize();
curvePen.setColor( lineColor );
curve->setPen( curvePen );
curve
->setRenderHint
( QwtPlotItem::RenderAntialiased );
curve->setTitle( curveLabel );
if ( curveLabel.isEmpty() )
else
curve->attach( this );
}
void Plot2D::setMarkerOnMax( SLData_t* xData,
SLData_t* yData,
SLArrayIndex_t dataCount,
int precision, // positive value for '%.*g', negative value for '%.*f'
Qt::Alignment alignment )
{
SLArrayIndex_t index = SDA_MaxPos( xData, dataCount ); // get the index of max value
setMarker( xData[index], yData[index], precision, alignment ); // set marker position
}
void Plot2D::setMarker( double X,
double Y,
int precision,
Qt::Alignment alignment )
{
marker->setValue( X, Y );
if (precision < 0)
label.sprintf( "(%.*f | %.*f)", -precision, X, -precision, Y );
else
label.sprintf( "(%.*g | %.*g)", precision, X, precision, Y );
text.
setColor( QColor( Qt
::white ));
text.
setFont( QFont("Helvetica",
8,
QFont::Bold ));
marker->setLabel( text );
marker->setLabelAlignment( alignment );
marker->attach( this );
}