Пример #1
0
std::string Grid::saveToString() {
  TSVSerialiser tsv;
  tsv.writeLine("grid");

  tsv << xEnabled() << xMinEnabled();
  tsv << yEnabled() << yMinEnabled();

  tsv << majPenX().color().name();
  tsv << majPenX().style() - 1;
  tsv << majPenX().widthF();

  tsv << minPenX().color().name();
  tsv << minPenX().style() - 1;
  tsv << minPenX().widthF();

  tsv << majPenY().color().name();
  tsv << majPenY().style() - 1;
  tsv << majPenY().widthF();

  tsv << minPenY().color().name();
  tsv << minPenY().style() - 1;
  tsv << minPenY().widthF();

  tsv << xZeroLineEnabled() << yZeroLineEnabled();
  tsv << xAxis() << yAxis();
  tsv << testRenderHint(QwtPlotItem::RenderAntialiased);
  return tsv.outputLines();
}
Пример #2
0
QString Grid::saveToString()
{
    QString s = "grid\t";
    s += QString::number(xEnabled())+"\t";
    s += QString::number(xMinEnabled())+"\t";
    s += QString::number(yEnabled())+"\t";
    s += QString::number(yMinEnabled())+"\t";

    s += majPenX().color().name()+"\t";
    s += QString::number(majPenX().style() - 1)+"\t";
    s += QString::number(majPenX().widthF())+"\t";

    s += minPenX().color().name()+"\t";
    s += QString::number(minPenX().style() - 1)+"\t";
    s += QString::number(minPenX().widthF())+"\t";

    s += majPenY().color().name()+"\t";
    s += QString::number(majPenY().style() - 1)+"\t";
    s += QString::number(majPenY().widthF())+"\t";

    s += minPenY().color().name()+"\t";
    s += QString::number(minPenY().style() - 1)+"\t";
    s += QString::number(minPenY().widthF())+"\t";

    s += QString::number(xZeroLineEnabled())+"\t";
    s += QString::number(yZeroLineEnabled())+"\t";
    s += QString::number(xAxis())+"\t";
    s += QString::number(yAxis())+"\t";
    s += QString::number(testRenderHint(QwtPlotItem::RenderAntialiased))+"\n";
    return s;
}
Пример #3
0
void PlotMarkerLegend::updateLegend(QwtLegend* legend) const
{
	if ( legend == NULL )
		return;

	if ( legend && testItemAttribute( QwtPlotItem::Legend ) && symbol() && symbol()->style() != QwtSymbol::NoSymbol )
	{
		QWidget *lgdItem = legend->find( this );
		if ( lgdItem == NULL )
		{
			lgdItem = legendItem();
			if ( lgdItem )
				legend->insert( this, lgdItem );
		}

		LegendItem *l = qobject_cast<LegendItem *>( lgdItem );
		if ( l )
			l->setIdentifierSize( symbol()->boundingSize() );
	}

	QWidget *lgdItem = legend->find( this );
	if ( testItemAttribute( QwtPlotItem::Legend ) )
	{
		LegendItem *label = qobject_cast<LegendItem *>( lgdItem );
		if ( label )
		{
			// paint the identifier
			const QSize sz = label->identifierSize();

			QPixmap identifier( sz.width(), sz.height() );
			identifier.fill( Qt::transparent );

			QPainter painter( &identifier );
			painter.setRenderHint( QPainter::Antialiasing, testRenderHint( QwtPlotItem::RenderAntialiased ) );
			drawLegendIdentifier( &painter, QRect( 0, 0, sz.width(), sz.height() ) );
			painter.end();

			const bool doUpdate = label->updatesEnabled();
			if ( doUpdate )
				label->setUpdatesEnabled( false );

			label->setText( title() );
			label->setIdentifier( identifier );
			label->setItemMode( legend->itemMode() );

			if ( doUpdate )
				label->setUpdatesEnabled( true );

			label->update();
		}
	}
	else
	{
		if ( lgdItem )
		{
			lgdItem->hide();
			lgdItem->deleteLater();
		}
	}
}
/*!
  \return Icon for the legend

  In case of Tube style() the icon is a plain rectangle filled with the brush().
  If a symbol is assigned it is scaled to size.

  \param index Index of the legend entry 
               ( ignored as there is only one )
  \param size Icon size
    
  \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
*/
QwtGraphic QwtPlotIntervalCurve::legendIcon( 
    int index, const QSizeF &size ) const
{
    Q_UNUSED( index );

    if ( size.isEmpty() )
        return QwtGraphic();

    QwtGraphic icon;
    icon.setDefaultSize( size );
    icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true );

    QPainter painter( &icon );
    painter.setRenderHint( QPainter::Antialiasing,
        testRenderHint( QwtPlotItem::RenderAntialiased ) );

    if ( d_data->style == Tube )
    {
        QRectF r( 0, 0, size.width(), size.height() );
        painter.fillRect( r, d_data->brush );
    }

    if ( d_data->symbol &&
        ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
    {
        QPen pen = d_data->symbol->pen();
        pen.setWidthF( pen.widthF() );
        pen.setCapStyle( Qt::FlatCap );

        painter.setPen( pen );
        painter.setBrush( d_data->symbol->brush() );

        if ( orientation() == Qt::Vertical )
        {
            const double x = 0.5 * size.width();

            d_data->symbol->draw( &painter, orientation(),
                QPointF( x, 0 ), QPointF( x, size.height() - 1.0 ) );
        }
        else
        {
            const double y = 0.5 * size.height();

            d_data->symbol->draw( &painter, orientation(),
                QPointF( 0.0, y ), QPointF( size.width() - 1.0, y ) );
        }
    }

    return icon;
}
Пример #5
0
/*!
   \return Icon representing the marker on the legend

   \param index Index of the legend entry 
                ( usually there is only one )
   \param size Icon size

   \sa setLegendIconSize(), legendData()
*/
QwtGraphic QwtPlotMarker::legendIcon( int index,
    const QSizeF &size ) const
{
    Q_UNUSED( index );

    if ( size.isEmpty() )
        return QwtGraphic();

    QwtGraphic icon;
    icon.setDefaultSize( size );
    icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true );

    QPainter painter( &icon );
    painter.setRenderHint( QPainter::Antialiasing,
        testRenderHint( QwtPlotItem::RenderAntialiased ) );

    if ( d_data->style != QwtPlotMarker::NoLine )
    {
        painter.setPen( d_data->pen );

        if ( d_data->style == QwtPlotMarker::HLine ||
            d_data->style == QwtPlotMarker::Cross )
        {
            const double y = 0.5 * size.height();

            QwtPainter::drawLine( &painter, 
                0.0, y, size.width(), y );
        }

        if ( d_data->style == QwtPlotMarker::VLine ||
            d_data->style == QwtPlotMarker::Cross )
        {
            const double x = 0.5 * size.width();

            QwtPainter::drawLine( &painter, 
                x, 0.0, x, size.height() );
        }
    }

    if ( d_data->symbol )
    {
        const QRect r( 0.0, 0.0, size.width(), size.height() );
        d_data->symbol->drawSymbol( &painter, r );
    }

    return icon;
}
/*!
  \return Icon for representing a bar on the legend

  \param index Index of the bar
  \param size Icon size
  
  \return An icon showing a bar
  \sa drawBar(), legendData()
 */
QwtGraphic QwtPlotMultiBarChart::legendIcon( int index,
    const QSizeF &size ) const
{
    QwtColumnRect column;
    column.hInterval = QwtInterval( 0.0, size.width() - 1.0 );
    column.vInterval = QwtInterval( 0.0, size.height() - 1.0 );

    QwtGraphic icon;
    icon.setDefaultSize( size );
    icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true );

    QPainter painter( &icon );
    painter.setRenderHint( QPainter::Antialiasing,
        testRenderHint( QwtPlotItem::RenderAntialiased ) );

    drawBar( &painter, -1, index, column );

    return icon;
}
Пример #7
0
/*!
  \return A rectangle filled with the color of the brush ( or the pen )

  \param index Index of the legend entry 
                ( usually there is only one )
  \param size Icon size

  \sa setLegendIconSize(), legendData()
*/
QwtGraphic QwtPlotShapeItem::legendIcon( int index,
    const QSizeF &size ) const
{
    Q_UNUSED( index );

    QwtGraphic icon;
    icon.setDefaultSize( size );

    if ( size.isEmpty() )
        return icon;

    if ( d_data->legendMode == QwtPlotShapeItem::LegendShape )
    {
        const QRectF &br = d_data->boundingRect;

        QPainter painter( &icon );
        painter.setRenderHint( QPainter::Antialiasing,
            testRenderHint( QwtPlotItem::RenderAntialiased ) );

        painter.translate( -br.topLeft() );

        painter.setPen( d_data->pen );
        painter.setBrush( d_data->brush );
        painter.drawPath( d_data->shape );
    }
    else
    {
        QColor iconColor;
        if ( d_data->brush.style() != Qt::NoBrush )
            iconColor = d_data->brush.color();
        else
            iconColor = d_data->pen.color();

        icon = defaultIcon( iconColor, size );
    }

    return icon;
}
Пример #8
0
/*!
   \return Icon representing a bar or the chart on the legend

   When the legendMode() is LegendBarTitles the icon shows
   the bar corresponding to index - otherwise the bar
   displays the default symbol.

   \param index Index of the legend entry 
   \param size Icon size

   \sa setLegendMode(), drawBar(), 
       QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
 */
QwtGraphic QwtPlotBarChart::legendIcon( 
    int index, const QSizeF &size ) const
{
    QwtColumnRect column;
    column.hInterval = QwtInterval( 0.0, size.width() - 1.0 );
    column.vInterval = QwtInterval( 0.0, size.height() - 1.0 );

    QwtGraphic icon;
    icon.setDefaultSize( size );
    icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true );

    QPainter painter( &icon );
    painter.setRenderHint( QPainter::Antialiasing,
        testRenderHint( QwtPlotItem::RenderAntialiased ) );

    int barIndex = -1;
    if ( d_data->legendMode == QwtPlotBarChart::LegendBarTitles )
        barIndex = index;
        
    drawBar( &painter, barIndex, QPointF(), column );

    return icon;
}
Пример #9
0
/*!
   \return Icon representing the curve on the legend

   \param index Index of the legend entry 
                ( ignored as there is only one )
   \param size Icon size

   \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
 */
QwtGraphic QwtPlotCurve::legendIcon( int index, 
    const QSizeF &size ) const
{
    Q_UNUSED( index );

    if ( size.isEmpty() )
        return QwtGraphic();

    QwtGraphic graphic;
    graphic.setDefaultSize( size );
    graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true );

    QPainter painter( &graphic );
    painter.setRenderHint( QPainter::Antialiasing,
        testRenderHint( QwtPlotItem::RenderAntialiased ) );

    if ( d_data->legendAttributes == 0 ||
        d_data->legendAttributes & QwtPlotCurve::LegendShowBrush )
    {
        QBrush brush = d_data->brush;

        if ( brush.style() == Qt::NoBrush &&
            d_data->legendAttributes == 0 )
        {
            if ( style() != QwtPlotCurve::NoCurve )
            {
                brush = QBrush( pen().color() );
            }
            else if ( d_data->symbol &&
                ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
            {
                brush = QBrush( d_data->symbol->pen().color() );
            }
        }

        if ( brush.style() != Qt::NoBrush )
        {
            QRectF r( 0, 0, size.width(), size.height() );
            painter.fillRect( r, brush );
        }
    }

    if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine )
    {
        if ( pen() != Qt::NoPen )
        {
            QPen pn = pen();
            pn.setCapStyle( Qt::FlatCap );

            painter.setPen( pn );

            const double y = 0.5 * size.height();
            QwtPainter::drawLine( &painter, 0.0, y, size.width(), y );
        }
    }

    if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
    {
        if ( d_data->symbol )
        {
            QRectF r( 0, 0, size.width(), size.height() );
            d_data->symbol->drawSymbol( &painter, r );
        }
    }

    return graphic;
}