// virtual from QwtPlotCurve
QwtGraphic SlotCurve::legendIcon (int index, // (ignore, only one)
const QSizeF& iconSize) const
{
// call base class method
//-- QwtGraphic graphic = QwtPlotCurve::legendIcon (index, iconSize);
// Note [Phil, 3-2017, RW 7.1, Qwt 6.1.3, Qt 5.5.1, Gnats 5864]:
// The following code is adapted from QwtPlotCurve::legendIcon().
// See the fix for Gnats 5864, below ("Legend and plot line look
// different if thickness is greater than one").
Q_UNUSED( index );
if ( iconSize.isEmpty() )
return QwtGraphic();
QwtGraphic graphic;
graphic.setDefaultSize( iconSize );
graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true );
painter.
setRenderHint( QPainter::Antialiasing,
bool doShowLine
= testLegendAttribute
(QwtPlotCurve::LegendShowLine);
bool doShowSymb
= testLegendAttribute
(QwtPlotCurve::LegendShowSymbol);
bool doShowBrush
= testLegendAttribute
(QwtPlotCurve::LegendShowBrush);
bool noAttribs = !(doShowLine || doShowSymb || doShowBrush);
const QPen curvePen
= pen
();
if ( noAttribs || doShowBrush)
{
if ( curveBrush.style() == Qt::NoBrush && noAttribs )
{
{
curveBrush
= QBrush( curvePen.
color() );
}
else if ( curveSymb
&& (curveSymb
->style
() != QwtSymbol::NoSymbol) ) {
curveBrush
= QBrush( curveSymb
->pen
().
color() );
}
}
if ( curveBrush.style() != Qt::NoBrush )
{
QRectF r
( 0,
0, iconSize.
width(), iconSize.
height() );
painter.fillRect( r, curveBrush );
}
}
if ( doShowLine )
{
if ( curvePen != Qt::NoPen )
{
// CADSWES FIX, Gnats 5864 ("Legend and plot line look different if
// thickness is greater than one"). DON'T set the pen Cap Style.
//
//-- QPen pn = curvePen;
//-- pn.setCapStyle( Qt::FlatCap );
//-- painter.setPen( pn );
painter.setPen( curvePen );
const double y = 0.5 * iconSize.height();
QwtPainter::drawLine( &painter,
0.0, y, iconSize.
width(), y
);
}
}
if ( doShowSymb )
{
if ( curveSymb )
{
QRectF r
( 0,
0, iconSize.
width(), iconSize.
height() );
curveSymb->drawSymbol( &painter, r );
}
}
return graphic;
}
// virtual from QwtPlotCurve
QwtGraphic SlotCurve::legendIcon (int index, // (ignore, only one)
const QSizeF& iconSize) const
{
// call base class method
//-- QwtGraphic graphic = QwtPlotCurve::legendIcon (index, iconSize);
// Note [Phil, 3-2017, RW 7.1, Qwt 6.1.3, Qt 5.5.1, Gnats 5864]:
// The following code is adapted from QwtPlotCurve::legendIcon().
// See the fix for Gnats 5864, below ("Legend and plot line look
// different if thickness is greater than one").
Q_UNUSED( index );
if ( iconSize.isEmpty() )
return QwtGraphic();
QwtGraphic graphic;
graphic.setDefaultSize( iconSize );
graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true );
QPainter painter( &graphic );
painter.setRenderHint( QPainter::Antialiasing,
testRenderHint( QwtPlotItem::RenderAntialiased ) );
bool doShowLine = testLegendAttribute (QwtPlotCurve::LegendShowLine);
bool doShowSymb = testLegendAttribute (QwtPlotCurve::LegendShowSymbol);
bool doShowBrush = testLegendAttribute (QwtPlotCurve::LegendShowBrush);
bool noAttribs = !(doShowLine || doShowSymb || doShowBrush);
const QPen curvePen = pen();
const QwtSymbol* curveSymb = symbol();
if ( noAttribs || doShowBrush)
{
QBrush curveBrush = brush();
if ( curveBrush.style() == Qt::NoBrush && noAttribs )
{
if ( style() != QwtPlotCurve::NoCurve )
{
curveBrush = QBrush( curvePen.color() );
}
else if ( curveSymb && (curveSymb->style() != QwtSymbol::NoSymbol) )
{
curveBrush = QBrush( curveSymb->pen().color() );
}
}
if ( curveBrush.style() != Qt::NoBrush )
{
QRectF r( 0, 0, iconSize.width(), iconSize.height() );
painter.fillRect( r, curveBrush );
}
}
if ( doShowLine )
{
if ( curvePen != Qt::NoPen )
{
// CADSWES FIX, Gnats 5864 ("Legend and plot line look different if
// thickness is greater than one"). DON'T set the pen Cap Style.
//
//-- QPen pn = curvePen;
//-- pn.setCapStyle( Qt::FlatCap );
//-- painter.setPen( pn );
painter.setPen( curvePen );
const double y = 0.5 * iconSize.height();
QwtPainter::drawLine( &painter, 0.0, y, iconSize.width(), y );
}
}
if ( doShowSymb )
{
if ( curveSymb )
{
QRectF r( 0, 0, iconSize.width(), iconSize.height() );
curveSymb->drawSymbol( &painter, r );
}
}
return graphic;
}
To copy to clipboard, switch view to plain text mode
Bookmarks