Exemple #1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    config(),
    configUI(&config),
    experiment(&config, this),
    qwtPlotCurveHallU("Hall U"),
    qwtPlotCurveResistivity("Resistivity"),
    ui(new Ui::MainWindow)
{
    experiment.setObjectName("experiment");
    ui->setupUi(this);
    QObject::connect(&configUI, SIGNAL(accepted()), this, SLOT(show()));
    QObject::connect(&experiment, SIGNAL(coilBMeasured(double)),
                     ui->coilBDoubleSpinBox, SLOT(setValue(double)));
    QObject::connect(&experiment, SIGNAL(coilIMeasured(double)),
                     ui->coilCurrMeasDoubleSpinBox, SLOT(setValue(double)));
    QObject::connect(&experiment, SIGNAL(coilUMeasured(double)),
                     ui->coilVoltMeasDoubleSpinBox, SLOT(setValue(double)));

    ui->qwtPlot->enableAxis(QwtPlot::yRight, true);
    QString titleTpl("<html><body><span style=\"font-family:'Sans Serif'; font-size:14pt; font-weight:600; font-style:bold;\"><span style=\"%1\">%2</span> %3</span></body></html>");

    QwtText titleHall(titleTpl.arg("color: red;").arg("×").arg("hall U [V]"));
    QwtText titleR(titleTpl.arg("color: lime;").arg("*").arg("Resistivity [Ω]"));

    ui->qwtPlot->setAxisTitle(QwtPlot::yLeft, titleHall);
    ui->qwtPlot->setAxisTitle(QwtPlot::yRight, titleR);
    ui->qwtPlot->setAxisTitle(QwtPlot::xBottom, "B [T]");

    qwtPlotCurveHallU.attach(ui->qwtPlot);
    qwtPlotCurveResistivity.attach(ui->qwtPlot);

    qwtPlotCurveHallU.setStyle(QwtPlotCurve::NoCurve);
    qwtPlotCurveResistivity.setStyle(QwtPlotCurve::NoCurve);

    QwtSymbol *qwtPlotHallUSymbol = new QwtSymbol(QwtSymbol::XCross);
    QwtSymbol *qwtPlotResistivitySymbol = new QwtSymbol(QwtSymbol::Star1);

    qwtPlotHallUSymbol->setColor(QColor(255, 0, 0));
    qwtPlotResistivitySymbol->setColor(QColor(0, 255, 0));

    qwtPlotHallUSymbol->setSize(QSize(12, 12));
    qwtPlotResistivitySymbol->setSize(QSize(12, 12));

    QPen hallSymbolPen(qwtPlotHallUSymbol->pen());
    QPen resistivitySymbolPen(qwtPlotResistivitySymbol->pen());

    hallSymbolPen.setWidth(2);
    resistivitySymbolPen.setWidth(2);

    qwtPlotHallUSymbol->setPen(hallSymbolPen);
    qwtPlotResistivitySymbol->setPen(resistivitySymbolPen);

    qwtPlotCurveResistivity.setYAxis(QwtPlot::yRight);

    qwtPlotCurveHallU.setSymbol(qwtPlotHallUSymbol);
    qwtPlotCurveResistivity.setSymbol(qwtPlotResistivitySymbol);

    ui->dataTableWidget->resizeColumnsToContents();
}
Exemple #2
0
QString PlotCurve::saveCurveLayout()
{
  Plot *plot = static_cast<Plot *>(this->plot());
  Graph *g = static_cast<Graph *>(plot->parent());

  int index = g->curveIndex(static_cast<QwtPlotCurve *>(this));
  int style = g->curveType(index);
  QString s = "<Style>" + QString::number(style) + "</Style>\n";

  if (style == Graph::Spline)
    s += "<LineStyle>5</LineStyle>\n";
  else if (style == Graph::VerticalSteps)
    s += "<LineStyle>6</LineStyle>\n";
  else
    s += "<LineStyle>" + QString::number(this->style()) + "</LineStyle>\n";

  QPen pen = this->pen();
  if (pen.style() != Qt::NoPen){
    s += "<Pen>\n";
    s += "\t<Color>" + pen.color().name() + "</Color>\n";
    s += "\t<Style>" + QString::number(pen.style()-1) + "</Style>\n";
    s += "\t<Width>" + QString::number(pen.widthF()) + "</Width>\n";
    s += "</Pen>\n";
  }

  QBrush brush = this->brush();
  if (brush.style() != Qt::NoBrush){
    s += "<Brush>\n";
    s += "\t<Color>" + brush.color().name() + "</Color>\n";
    s += "\t<Style>" + QString::number(PatternBox::patternIndex(brush.style())) + "</Style>\n";
    s += "</Brush>\n";
  }

  const QwtSymbol symbol = this->symbol();
  if (symbol.style() != QwtSymbol::NoSymbol){
    s += "<Symbol>\n";
    s += "\t<Style>" + QString::number(SymbolBox::symbolIndex(symbol.style())) + "</Style>\n";
    s += "\t<Size>" + QString::number(symbol.size().width()) + "</Size>\n";

    s += "\t<SymbolPen>\n";
    s += "\t\t<Color>" + symbol.pen().color().name() + "</Color>\n";
    s += "\t\t<Width>" + QString::number(symbol.pen().widthF()) + "</Width>\n";
    s += "\t</SymbolPen>\n";

    brush = this->brush();
    if (brush.style() != Qt::NoBrush){
      s += "\t<SymbolBrush>\n";
      s += "\t\t<Color>" + symbol.brush().color().name() + "</Color>\n";
      s += "\t\t<Style>" + QString::number(PatternBox::patternIndex(symbol.brush().style())) + "</Style>\n";
      s += "\t</SymbolBrush>\n";
    }
    s += "</Symbol>\n";
  }
  s += "<xAxis>" + QString::number(xAxis()) + "</xAxis>\n";
  s += "<yAxis>" + QString::number(yAxis()) + "</yAxis>\n";
  s += "<Visible>" + QString::number(isVisible()) + "</Visible>\n";
  return s;
}
Exemple #3
0
/*!
 \brief Draw symbols
 \param painter Painter
 \param symbol Curve symbol
 \param xMap x map
 \param yMap y map
 \param from index of the first point to be painted
 \param to index of the last point to be painted

 \sa setSymbol(), draw(), drawCurve()
 */
void PlotCurve::drawSymbols(QPainter *painter, const QwtSymbol &symbol, const QwtScaleMap &xMap,
    const QwtScaleMap &yMap, int from, int to) const
{
  painter->translate(d_x_offset,-d_y_offset);  // For waterfall plots (will be zero otherwise)
                                               // Don't really know why you'd want symbols on a waterfall plot, but just in case...

  if (d_skip_symbols < 2)
  {
    QwtPlotCurve::drawSymbols(painter, symbol, xMap, yMap, from, to);
    return;
  }

  painter->setBrush(symbol.brush());
  //QtiPlot has added method to QwtPainter: painter->setPen(QwtPainter::scaledPen(symbol.pen()));
  painter->setPen(symbol.pen());

  const QwtMetricsMap &metricsMap = QwtPainter::metricsMap();

  QRect rect;
  rect.setSize(metricsMap.screenToLayout(symbol.size()));

  for (int i = from; i <= to; i += d_skip_symbols)
  {
    const int xi = xMap.transform(x(i));
    const int yi = yMap.transform(y(i));

    rect.moveCenter(QPoint(xi, yi));
    symbol.draw(painter, rect);
  }
}
Exemple #4
0
/*!
  Draw symbols

  \param painter Painter
  \param symbol Curve symbol
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.

  \sa setSymbol(), draw(), drawCurve()
*/
void QwtPolarCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
    const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    const QPointF &pole, int from, int to ) const
{
    painter->setBrush( symbol.brush() );
    painter->setPen( symbol.pen() );

    const int chunkSize = 500;

    for ( int i = from; i <= to; i += chunkSize )
    {
        const int n = qMin( chunkSize, to - i + 1 );

        QPolygonF points;
        for ( int j = 0; j < n; j++ )
        {
            const QwtPointPolar point = sample( i + j );

            if ( !qwtInsidePole( radialMap, point.radius() ) )
            {
                const double r = radialMap.transform( point.radius() );
                const double a = azimuthMap.transform( point.azimuth() );

                points += qwtPolar2Pos( pole, r, a );
            }
            else
            {
                points += pole;
            }
        }

        if ( points.size() > 0 )
            symbol.drawSymbols( painter, points );
    }
}
Exemple #5
0
/*!
 \brief Draw symbols
 \param painter Painter
 \param symbol Curve symbol
 \param xMap x map
 \param yMap y map
 \param from index of the first point to be painted
 \param to index of the last point to be painted

 \sa setSymbol(), draw(), drawCurve()
 */
void PlotCurve::drawSymbols(QPainter *painter, const QwtSymbol &symbol,
                            const QwtScaleMap &xMap, const QwtScaleMap &yMap,
                            int from, int to) const {
  if (d_skip_symbols < 2) {
    QwtPlotCurve::drawSymbols(painter, symbol, xMap, yMap, from, to);
    return;
  }

  painter->setBrush(symbol.brush());
  // QtiPlot has added method to QwtPainter:
  // painter->setPen(QwtPainter::scaledPen(symbol.pen()));
  painter->setPen(symbol.pen());

  const QwtMetricsMap &metricsMap = QwtPainter::metricsMap();

  QRect rect;
  rect.setSize(metricsMap.screenToLayout(symbol.size()));

  for (int i = from; i <= to; i += d_skip_symbols) {
    const int xi = xMap.transform(x(i));
    const int yi = yMap.transform(y(i));

    rect.moveCenter(QPoint(xi, yi));
    symbol.draw(painter, rect);
  }
}
static inline void qwtDrawXCrossSymbols( QPainter *painter,
    const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
    const QSize size = symbol.size();
    int off = 0;

    QPen pen = symbol.pen();
    if ( pen.width() > 1 )
    {
        pen.setCapStyle( Qt::FlatCap );
        off = 1;
    }
    painter->setPen( pen );


    if ( QwtPainter::roundingAlignment( painter ) )
    {
        const int sw = size.width();
        const int sh = size.height();
        const int sw2 = size.width() / 2;
        const int sh2 = size.height() / 2;

        for ( int i = 0; i < numPoints; i++ )
        {
            const QPointF &pos = points[i];

            const int x = qRound( pos.x() );
            const int y = qRound( pos.y() );

            const int x1 = x - sw2;
            const int x2 = x1 + sw + off;
            const int y1 = y - sh2;
            const int y2 = y1 + sh + off;

            QwtPainter::drawLine( painter, x1, y1, x2, y2 );
            QwtPainter::drawLine( painter, x2, y1, x1, y2 );
        }
    }
    else
    {
        const double sw = size.width();
        const double sh = size.height();
        const double sw2 = 0.5 * size.width();
        const double sh2 = 0.5 * size.height();

        for ( int i = 0; i < numPoints; i++ )
        {
            const QPointF &pos = points[i];

            const double x1 = pos.x() - sw2;
            const double x2 = x1 + sw;
            const double y1 = pos.y() - sh2;
            const double y2 = y1 + sh;

            QwtPainter::drawLine( painter, x1, y1, x2, y2 );
            QwtPainter::drawLine( painter, x1, y2, x2, y1 );
        }
    }
}
static inline void qwtDrawDiamondSymbols( QPainter *painter,
    const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
    const QSize size = symbol.size();

    QPen pen = symbol.pen();
    pen.setJoinStyle( Qt::MiterJoin );
    painter->setPen( pen );
    painter->setBrush( symbol.brush() );

    if ( QwtPainter::roundingAlignment( painter ) )
    {
        for ( int i = 0; i < numPoints; i++ )
        {
            const int x = qRound( points[i].x() );
            const int y = qRound( points[i].y() );

            const int x1 = x - size.width() / 2;
            const int y1 = y - size.height() / 2;
            const int x2 = x1 + size.width();
            const int y2 = y1 + size.height();

            QPolygonF polygon;
            polygon += QPointF( x, y1 );
            polygon += QPointF( x1, y );
            polygon += QPointF( x, y2 );
            polygon += QPointF( x2, y );

            QwtPainter::drawPolygon( painter, polygon );
        }
    }
    else
    {
        for ( int i = 0; i < numPoints; i++ )
        {
            const QPointF &pos = points[i];

            const double x1 = pos.x() - 0.5 * size.width();
            const double y1 = pos.y() - 0.5 * size.height();
            const double x2 = x1 + size.width();
            const double y2 = y1 + size.height();

            QPolygonF polygon;
            polygon += QPointF( pos.x(), y1 );
            polygon += QPointF( x2, pos.y() );
            polygon += QPointF( pos.x(), y2 );
            polygon += QPointF( x1, pos.y() );

            QwtPainter::drawPolygon( painter, polygon );
        }
    }
}
void specCanvasItem::setSymbolPenColor(const QColor& newColor)
{
	if(oldSymbol)
	{
		QPen newPen(oldSymbol->pen()) ;
		newPen.setColor(newColor) ;
		oldSymbol->setPen(newPen) ;
	}
	else
	{
		QwtSymbol* newSymbol = symbol() ? cloneSymbol(symbol()) : (new QwtSymbol) ;
		QPen newPen = newSymbol->pen() ;
		newPen.setColor(newColor) ;
		newSymbol->setPen(newPen) ;
		setSymbol(newSymbol) ;
	}
}
/*!
  \brief Draw symbols
  \param painter Painter
  \param symbol Curve symbol
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
*/
void QwtCurve::drawSymbols(QPainter *painter, QwtSymbol &symbol,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    painter->setBrush(symbol.brush());
    painter->setPen(symbol.pen());

    QRect rect;
    rect.setSize(QwtPainter::metricsMap().screenToLayout(symbol.size()));

    for (int i = from; i <= to; i++)
    {
        const int xi = xMap.transform(x(i));
        const int yi = yMap.transform(y(i));

        rect.moveCenter(QPoint(xi, yi));
        symbol.draw(painter, rect);
    }
}
/*!
  \brief Draw symbols
  \param painter Painter
  \param symbol Curve symbol
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa setSymbol(), draw(), drawCurve()
*/
void QwtPlotCurve::drawSymbols(QPainter *painter, const QwtSymbol &symbol,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap, 
    int from, int to) const
{
    painter->setBrush(symbol.brush());
    painter->setPen(QwtPainter::scaledPen(symbol.pen()));

    const QwtMetricsMap &metricsMap = QwtPainter::metricsMap();

    QRect rect;
    rect.setSize(metricsMap.screenToLayout(symbol.size()));

    if ( to > from && d_data->paintAttributes & PaintFiltered )
    {
        const QRect window = painter->window();
        if ( window.isEmpty() )
            return;

        PrivateData::PixelMatrix pixelMatrix(window);

        for (int i = from; i <= to; i++)
        {
            const QPoint pi( xMap.transform(x(i)),
                yMap.transform(y(i)) );

            if ( pixelMatrix.testPixel(pi) )
            {
                rect.moveCenter(pi);
                symbol.draw(painter, rect);
            }
        }
    }
    else
    {
        for (int i = from; i <= to; i++)
        {
            const int xi = xMap.transform(x(i));
            const int yi = yMap.transform(y(i));

            rect.moveCenter(QPoint(xi, yi));
            symbol.draw(painter, rect);
        }
    }
}
Exemple #11
0
static inline void qwtDrawRectSymbols( QPainter *painter,
    const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
    const QSize size = symbol.size();

    QPen pen = symbol.pen();
    pen.setJoinStyle( Qt::MiterJoin );
    painter->setPen( pen );
    painter->setBrush( symbol.brush() );
    painter->setRenderHint( QPainter::Antialiasing, false );

    if ( QwtPainter::roundingAlignment( painter ) )
    {
        const int sw = size.width();
        const int sh = size.height();
        const int sw2 = size.width() / 2;
        const int sh2 = size.height() / 2;

        for ( int i = 0; i < numPoints; i++ )
        {
            const int x = qRound( points[i].x() );
            const int y = qRound( points[i].y() );

            const QRect r( x - sw2, y - sh2, sw, sh );
            QwtPainter::drawRect( painter, r );
        }
    }
    else
    {
        const double sw = size.width();
        const double sh = size.height();
        const double sw2 = 0.5 * size.width();
        const double sh2 = 0.5 * size.height();

        for ( int i = 0; i < numPoints; i++ )
        {
            const double x = points[i].x();
            const double y = points[i].y();

            const QRectF r( x - sw2, y - sh2, sw, sh );
            QwtPainter::drawRect( painter, r );
        }
    }
}
Exemple #12
0
static inline void qwtDrawEllipseSymbols( QPainter *painter,
    const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
    painter->setBrush( symbol.brush() );
    painter->setPen( symbol.pen() );

    const QSize size = symbol.size();

    if ( QwtPainter::roundingAlignment( painter ) )
    {
        const int sw = size.width();
        const int sh = size.height();
        const int sw2 = size.width() / 2;
        const int sh2 = size.height() / 2;

        for ( int i = 0; i < numPoints; i++ )
        {
            const int x = qRound( points[i].x() );
            const int y = qRound( points[i].y() );

            const QRectF r( x - sw2, y - sh2, sw, sh );
            QwtPainter::drawEllipse( painter, r );
        }
    }
    else
    {
        const double sw = size.width();
        const double sh = size.height();
        const double sw2 = 0.5 * size.width();
        const double sh2 = 0.5 * size.height();

        for ( int i = 0; i < numPoints; i++ )
        {
            const double x = points[i].x();
            const double y = points[i].y();

            const QRectF r( x - sw2, y - sh2, sw, sh );
            QwtPainter::drawEllipse( painter, r );
        }
    }
}
Exemple #13
0
/*!
  Draw symbols

  \param painter Painter
  \param symbol Curve symbol
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.
  \sa setSymbol(), draw(), drawCurve()
*/
void QwtPolarCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
                                 const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
                                 const QwtDoublePoint &pole, int from, int to ) const
{
  painter->setBrush( symbol.brush() );
  painter->setPen( symbol.pen() );

  QRect rect;
  rect.setSize( QwtPainter::metricsMap().screenToLayout( symbol.size() ) );

  for ( int i = from; i <= to; i++ )
  {
    const QwtPolarPoint point = sample( i );
    const double r = radialMap.xTransform( point.radius() );
    const double a = azimuthMap.xTransform( point.azimuth() );

    const QPoint pos = qwtPolar2Pos( pole, r, a ).toPoint();

    rect.moveCenter( pos );
    symbol.draw( painter, rect );
  }
}
//! == operator
bool QwtSymbol::operator==(const QwtSymbol &other) const
{
    return brush() == other.brush() && pen() == other.pen()
            && style() == other.style() && size() == other.size();
}
void QwtPlotPrintFilter::reset(QwtPlotItem *item) const
{
    if ( d_data->cache == 0 )
        return;

    const PrivateData::Cache &cache = *d_data->cache;

    switch(item->rtti())
    {
        case QwtPlotItem::Rtti_PlotGrid:
        {
            QwtPlotGrid *grid = (QwtPlotGrid *)item;

            QPen pen = grid->majPen();
            pen.setColor(cache.gridColors[0]);
            grid->setMajPen(pen);

            pen = grid->minPen();
            pen.setColor(cache.gridColors[1]);
            grid->setMinPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotCurve:
        {
            QwtPlotCurve *c = (QwtPlotCurve *)item;

            QwtSymbol symbol = c->symbol();

            if ( cache.curveSymbolPenColors.contains(c) )
            {
                symbol.setPen(cache.curveSymbolPenColors[c]);
            }

            if ( cache.curveSymbolBrushColors.contains(c) )
            {
                QBrush brush = symbol.brush();
                brush.setColor(cache.curveSymbolBrushColors[c]);
                symbol.setBrush(brush);
            }
            c->setSymbol(symbol);

            if ( cache.curveColors.contains(c) )
            {
                QPen pen = c->pen();
                pen.setColor(cache.curveColors[c]);
                c->setPen(pen);
            }

            break;
        }
        case QwtPlotItem::Rtti_PlotMarker:
        {
            QwtPlotMarker *m = (QwtPlotMarker *)item;

            if ( cache.markerFonts.contains(m) )
            {
                QwtText label = m->label();
                label.setFont(cache.markerFonts[m]);
                m->setLabel(label);
            }

            if ( cache.markerLabelColors.contains(m) )
            {
                QwtText label = m->label();
                label.setColor(cache.markerLabelColors[m]);
                m->setLabel(label);
            }

            if ( cache.markerLineColors.contains(m) )
            {
                QPen pen = m->linePen();
                pen.setColor(cache.markerLineColors[m]);
                m->setLinePen(pen);
            }
            
            QwtSymbol symbol = m->symbol();

            if ( cache.markerSymbolPenColors.contains(m) )
            {
                QPen pen = symbol.pen();
                pen.setColor(cache.markerSymbolPenColors[m]);
                symbol.setPen(pen);
            }

            if ( cache.markerSymbolBrushColors.contains(m) )
            {
                QBrush brush = symbol.brush();
                brush.setColor(cache.markerSymbolBrushColors[m]);
                symbol.setBrush(brush);
            }

            m->setSymbol(symbol);

            break;
        }
        default:
            break;
    }
}
/*! 
   Reset color and fonts of a plot
   \sa apply()
*/
void QwtPlotPrintFilter::reset(QwtPlot *plot) const
{
    if ( d_data->cache == 0 )
        return;

    const bool doAutoReplot = plot->autoReplot();
    plot->setAutoReplot(false);

    const PrivateData::Cache &cache = *d_data->cache;

    if ( plot->titleLabel() )
    {
        QwtTextLabel* title = plot->titleLabel();
        if ( title->text().testPaintAttribute(QwtText::PaintUsingTextFont) )
        {
            QwtText text = title->text();
            text.setColor(cache.titleColor);
            title->setText(text);
        }
        else
        {
            QPalette palette = title->palette();
            palette.setColor(
                QPalette::Active, Palette::Text, cache.titleColor);
            title->setPalette(palette);
        }

        if ( title->text().testPaintAttribute(QwtText::PaintUsingTextFont) )
        {
            QwtText text = title->text();
            text.setFont(cache.titleFont);
            title->setText(text);
        }
        else
        {
            title->setFont(cache.titleFont);
        }
    }

    if ( plot->legend() )
    {
#if QT_VERSION < 0x040000
        QValueList<QWidget *> list = plot->legend()->legendItems();
        for ( QValueListIterator<QWidget *> it = list.begin();
            it != list.end(); ++it )
#else
        QList<QWidget *> list = plot->legend()->legendItems();
        for ( QList<QWidget*>::iterator it = list.begin();
            it != list.end(); ++it )
#endif
        {
            QWidget *w = *it;

            if ( cache.legendFonts.contains(w) )
                w->setFont(cache.legendFonts[w]);

            if ( w->inherits("QwtLegendItem") )
            {
                QwtLegendItem *label = (QwtLegendItem *)w;
                const QwtPlotItem *plotItem = 
                    (const QwtPlotItem*)plot->legend()->find(label);

                QwtSymbol symbol = label->symbol();
                if ( cache.curveSymbolPenColors.contains(plotItem) )
                {
                    QPen pen = symbol.pen();
                    pen.setColor(cache.curveSymbolPenColors[plotItem]);
                    symbol.setPen(pen);
                }

                if ( cache.curveSymbolBrushColors.contains(plotItem) )
                {
                    QBrush brush = symbol.brush();
                    brush.setColor(cache.curveSymbolBrushColors[plotItem]);
                    symbol.setBrush(brush);
                }
                label->setSymbol(symbol);

                if ( cache.curveColors.contains(plotItem) )
                {
                    QPen pen = label->curvePen();
                    pen.setColor(cache.curveColors[plotItem]);
                    label->setCurvePen(pen);
                }
            }
        }
    }
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        QwtScaleWidget *scaleWidget = plot->axisWidget(axis);
        if ( scaleWidget )
        {
            QPalette palette = scaleWidget->palette();
            palette.setColor(QPalette::Active, Palette::Foreground,
                             cache.scaleColor[axis]);
            scaleWidget->setPalette(palette);

            scaleWidget->setFont(cache.scaleFont[axis]);
            scaleWidget->setTitle(cache.scaleTitle[axis]);

            int startDist, endDist;
            scaleWidget->getBorderDistHint(startDist, endDist);
            scaleWidget->setBorderDist(startDist, endDist);
        }
    }

    if ( hasBackgroundColor(plot) )
    {
        QPalette p = plot->palette();
        p.setColor(QPalette::Active, Palette::Background, cache.widgetBackground);
        plot->setPalette(p);
    }

    if ( hasBackgroundColor(plot->canvas()) )
    {
        plot->setCanvasBackground(cache.canvasBackground);
    }
   
    const QwtPlotItemList& itmList = plot->itemList();
    for ( QwtPlotItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
    {
        reset(*it);
    }

    delete d_data->cache;
    d_data->cache = 0;

    plot->setAutoReplot(doAutoReplot);
}
Exemple #17
0
static inline void qwtDrawTriangleSymbols(
    QPainter *painter, QwtTriangle::Type type,
    const QPointF *points, int numPoints,
    const QwtSymbol &symbol )
{
    const QSize size = symbol.size();

    QPen pen = symbol.pen();
    pen.setJoinStyle( Qt::MiterJoin );
    painter->setPen( pen );

    painter->setBrush( symbol.brush() );

    const bool doAlign = QwtPainter::roundingAlignment( painter );

    double sw2 = 0.5 * size.width();
    double sh2 = 0.5 * size.height();

    if ( doAlign )
    {
        sw2 = qFloor( sw2 );
        sh2 = qFloor( sh2 );
    }

    QPolygonF triangle( 3 );
    QPointF *trianglePoints = triangle.data();

    for ( int i = 0; i < numPoints; i++ )
    {
        const QPointF &pos = points[i];

        double x = pos.x();
        double y = pos.y();

        if ( doAlign )
        {
            x = qRound( x );
            y = qRound( y );
        }

        const double x1 = x - sw2;
        const double x2 = x1 + size.width();
        const double y1 = y - sh2;
        const double y2 = y1 + size.height();

        switch ( type )
        {
            case QwtTriangle::Left:
            {
                trianglePoints[0].rx() = x2;
                trianglePoints[0].ry() = y1;

                trianglePoints[1].rx() = x1;
                trianglePoints[1].ry() = y;

                trianglePoints[2].rx() = x2;
                trianglePoints[2].ry() = y2;

                break;
            }
            case QwtTriangle::Right:
            {
                trianglePoints[0].rx() = x1;
                trianglePoints[0].ry() = y1;

                trianglePoints[1].rx() = x2;
                trianglePoints[1].ry() = y;

                trianglePoints[2].rx() = x1;
                trianglePoints[2].ry() = y2;

                break;
            }
            case QwtTriangle::Up:
            {
                trianglePoints[0].rx() = x1;
                trianglePoints[0].ry() = y2;

                trianglePoints[1].rx() = x;
                trianglePoints[1].ry() = y1;

                trianglePoints[2].rx() = x2;
                trianglePoints[2].ry() = y2;

                break;
            }
            case QwtTriangle::Down:
            {
                trianglePoints[0].rx() = x1;
                trianglePoints[0].ry() = y1;

                trianglePoints[1].rx() = x;
                trianglePoints[1].ry() = y2;

                trianglePoints[2].rx() = x2;
                trianglePoints[2].ry() = y1;

                break;
            }
        }
        QwtPainter::drawPolygon( painter, triangle );
    }
}
Exemple #18
0
QString PlotCurve::saveCurveLayout()
{
    QString s = "<Style>" + QString::number(d_plot_style) + "</Style>\n";
    if (d_plot_style == Graph::Spline)
        s += "<LineStyle>5</LineStyle>\n";
    else if (d_plot_style == Graph::VerticalSteps)
        s += "<LineStyle>6</LineStyle>\n";
    else
        s += "<LineStyle>" + QString::number(this->style()) + "</LineStyle>\n";

    QPen pen = this->pen();
    if (pen.style() != Qt::NoPen) {
        s += "<Pen>\n";
        s += "\t<Color>" + pen.color().name() + "</Color>\n";
        if (pen.color().alpha() != 255)
            s += "\t<Alpha>" + QString::number(pen.color().alpha()) + "</Alpha>\n";
        s += "\t<Style>" + QString::number(pen.style()-1) + "</Style>\n";
        s += "\t<Width>" + QString::number(pen.widthF()) + "</Width>\n";
        s += "</Pen>\n";
    }

    QBrush brush = this->brush();
    if (brush.style() != Qt::NoBrush) {
        s += "<Brush>\n";
        s += "\t<Color>" + brush.color().name() + "</Color>\n";
        if (brush.color().alpha() != 255)
            s += "\t<Alpha>" + QString::number(brush.color().alpha()) + "</Alpha>\n";
        s += "\t<Style>" + QString::number(PatternBox::patternIndex(brush.style())) + "</Style>\n";
        s += "</Brush>\n";
    }

    const QwtSymbol symbol = this->symbol();
    if (symbol.style() != QwtSymbol::NoSymbol) {
        s += "<Symbol>\n";
        s += "\t<Style>" + QString::number(SymbolBox::symbolIndex(symbol.style())) + "</Style>\n";
        s += "\t<Size>" + QString::number(symbol.size().width()) + "</Size>\n";

        s += "\t<SymbolPen>\n";
        s += "\t\t<Color>" + symbol.pen().color().name() + "</Color>\n";
        if (symbol.pen().color().alpha() != 255)
            s += "\t<Alpha>" + QString::number(symbol.pen().color().alpha()) + "</Alpha>\n";
        s += "\t\t<Width>" + QString::number(symbol.pen().widthF()) + "</Width>\n";
        s += "\t</SymbolPen>\n";

        brush = this->brush();
        if (brush.style() != Qt::NoBrush) {
            s += "\t<SymbolBrush>\n";
            s += "\t\t<Color>" + symbol.brush().color().name() + "</Color>\n";
            if (symbol.brush().color().alpha() != 255)
                s += "\t<Alpha>" + QString::number(symbol.brush().color().alpha()) + "</Alpha>\n";
            s += "\t\t<Style>" + QString::number(PatternBox::patternIndex(symbol.brush().style())) + "</Style>\n";
            s += "\t</SymbolBrush>\n";
        }
        s += "</Symbol>\n";
    }
    s += "<xAxis>" + QString::number(xAxis()) + "</xAxis>\n";
    s += "<yAxis>" + QString::number(yAxis()) + "</yAxis>\n";
    s += "<CurveType>" + QString::number(curveType()) + "</CurveType>\n";
    s += "<Visible>" + QString::number(isVisible()) + "</Visible>\n";
    return s;
}
Exemple #19
0
static inline void qwtDrawHexagonSymbols( QPainter *painter,
    const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
    painter->setBrush( symbol.brush() );
    painter->setPen( symbol.pen() );

    const double cos30 = 0.866025; // cos(30°)
    const double dx = 0.5 * ( symbol.size().width() - cos30 );

    const double dy = 0.25 * symbol.size().height();

    QPolygonF hexaPolygon( 6 );
    QPointF *hexaPoints = hexaPolygon.data();

    const bool doAlign = QwtPainter::roundingAlignment( painter );

    for ( int i = 0; i < numPoints; i++ )
    {
        double x = points[i].x();
        double y = points[i].y();
        if ( doAlign )
        {
            x = qRound( x );
            y = qRound( y );
        }

        double x1 = x - dx;
        double y1 = y - 2 * dy;
        if ( doAlign )
        {
            x1 = qCeil( x1 );
            y1 = qCeil( y1 );
        }

        const double x2 = x1 + 1 * dx;
        const double x3 = x1 + 2 * dx;

        const double y2 = y1 + 1 * dy;
        const double y3 = y1 + 3 * dy;
        const double y4 = y1 + 4 * dy;

        hexaPoints[0].rx() = x2;
        hexaPoints[0].ry() = y1;

        hexaPoints[1].rx() = x3;
        hexaPoints[1].ry() = y2;

        hexaPoints[2].rx() = x3;
        hexaPoints[2].ry() = y3;

        hexaPoints[3].rx() = x2;
        hexaPoints[3].ry() = y4;

        hexaPoints[4].rx() = x1;
        hexaPoints[4].ry() = y3;

        hexaPoints[5].rx() = x1;
        hexaPoints[5].ry() = y2;

        QwtPainter::drawPolygon( painter, hexaPolygon );
    }
}
/*!
  \brief Copy constructor

  \param other Symbol
*/
QwtSymbol::QwtSymbol( const QwtSymbol &other )
{
    d_data = new PrivateData( other.style(), other.brush(),
                              other.pen(), other.size() );
};
Exemple #21
0
static inline void qwtDrawStar1Symbols( QPainter *painter,
    const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
    const QSize size = symbol.size();
    painter->setPen( symbol.pen() );

    if ( QwtPainter::roundingAlignment( painter ) )
    {
        QRect r( 0, 0, size.width(), size.height() );

        for ( int i = 0; i < numPoints; i++ )
        {
            r.moveCenter( points[i].toPoint() );

            const double sqrt1_2 = 0.70710678118654752440; /* 1/sqrt(2) */

            const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );

            QwtPainter::drawLine( painter,
                qRound( r.left() + d1 ), qRound( r.top() + d1 ),
                qRound( r.right() - d1 ), qRound( r.bottom() - d1 ) );
            QwtPainter::drawLine( painter,
                qRound( r.left() + d1 ), qRound( r.bottom() - d1 ),
                qRound( r .right() - d1), qRound( r.top() + d1 ) );

            const QPoint c = r.center();

            QwtPainter::drawLine( painter,
                c.x(), r.top(), c.x(), r.bottom() );
            QwtPainter::drawLine( painter,
                r.left(), c.y(), r.right(), c.y() );
        }
    }
    else
    {
        QRectF r( 0, 0, size.width(), size.height() );

        for ( int i = 0; i < numPoints; i++ )
        {
            r.moveCenter( points[i] );

            const double sqrt1_2 = 0.70710678118654752440; /* 1/sqrt(2) */

            const QPointF c = r.center();
            const double d1  = r.width() / 2.0 * ( 1.0 - sqrt1_2 );

            QwtPainter::drawLine( painter,
                r.left() + d1, r.top() + d1,
                r.right() - d1, r.bottom() - d1 );
            QwtPainter::drawLine( painter,
                r.left() + d1, r.bottom() - d1,
                r.right() - d1, r.top() + d1 );
            QwtPainter::drawLine( painter,
                c.x(), r.top(),
                c.x(), r.bottom() );
            QwtPainter::drawLine( painter,
                r.left(), c.y(),
                r.right(), c.y() );
        }
    }
}
Exemple #22
0
static inline void qwtDrawLineSymbols(
    QPainter *painter, int orientations,
    const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
    const QSize size = symbol.size();

    int off = 0;

    QPen pen = symbol.pen();
    if ( pen.width() > 1 )
    {
        pen.setCapStyle( Qt::FlatCap );
        off = 1;
    }

    painter->setPen( pen );
    painter->setRenderHint( QPainter::Antialiasing, false );

    if ( QwtPainter::roundingAlignment( painter ) )
    {
        const int sw = qFloor( size.width() );
        const int sh = qFloor( size.height() );
        const int sw2 = size.width() / 2;
        const int sh2 = size.height() / 2;

        for ( int i = 0; i < numPoints; i++ )
        {
            if ( orientations & Qt::Horizontal )
            {
                const int x = qRound( points[i].x() ) - sw2;
                const int y = qRound( points[i].y() );

                QwtPainter::drawLine( painter, x, y, x + sw + off, y );
            }
            if ( orientations & Qt::Vertical )
            {
                const int x = qRound( points[i].x() );
                const int y = qRound( points[i].y() ) - sh2;

                QwtPainter::drawLine( painter, x, y, x, y + sh + off );
            }
        }
    }
    else
    {
        const double sw = size.width();
        const double sh = size.height();
        const double sw2 = 0.5 * size.width();
        const double sh2 = 0.5 * size.height();

        for ( int i = 0; i < numPoints; i++ )
        {
            if ( orientations & Qt::Horizontal )
            {
                const double x = points[i].x() - sw2;
                const double y = points[i].y();

                QwtPainter::drawLine( painter, x, y, x + sw, y );
            }
            if ( orientations & Qt::Vertical )
            {
                const double y = points[i].y() - sh2;
                const double x = points[i].x();

                QwtPainter::drawLine( painter, x, y, x, y + sh );
            }
        }
    }
}
/*! 
  Change color and fonts of a plot
  \sa QwtPlotPrintFilter::apply
*/
void QwtPlotPrintFilter::apply(QwtPlot *plot) const
{
    QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this;

    delete that->d_cache;
    that->d_cache = new QwtPlotPrintFilterCache;

    QwtPlotPrintFilterCache &cache = *that->d_cache;

    if ( plot->d_lblTitle )
    {
        QPalette palette = plot->d_lblTitle->palette();
        cache.titleColor = palette.color(
            QPalette::Active, QColorGroup::Foreground);
        palette.setColor(QPalette::Active, QColorGroup::Foreground,
                         color(cache.titleColor, Title));
        plot->d_lblTitle->setPalette(palette);

        cache.titleFont = plot->d_lblTitle->font();
        plot->d_lblTitle->setFont(font(cache.titleFont, Title));
    }
    if ( plot->d_legend )
    {
        QIntDictIterator<QWidget> it = plot->d_legend->itemIterator();
        for ( QWidget *w = it.toFirst(); w != 0; w = ++it)
        {
            const int key = it.currentKey();

            cache.legendFonts.insert(it.currentKey(), new QFont(w->font()));
            w->setFont(font(w->font(), Legend, key));

            if ( w->inherits("QwtLegendButton") )
            {
                QwtLegendButton *btn = (QwtLegendButton *)w;

                QwtSymbol symbol = btn->symbol();
                QPen pen = symbol.pen();
                QBrush brush = symbol.brush();

                pen.setColor(color(pen.color(), CurveSymbol, key));
                brush.setColor(color(brush.color(), CurveSymbol, key));

                symbol.setPen(pen);
                symbol.setBrush(brush);
                btn->setSymbol(symbol);

                pen = btn->curvePen();
                pen.setColor(color(pen.color(), Curve, key));
                btn->setCurvePen(pen);
            }
        }
    }
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        QwtScale *scale = plot->d_scale[axis];
        if ( scale )
        {
            cache.scaleColor[axis] = scale->palette().color(
                QPalette::Active, QColorGroup::Foreground);
            QPalette palette = scale->palette();
            palette.setColor(QPalette::Active, QColorGroup::Foreground,
                             color(cache.scaleColor[axis], AxisScale, axis));
            scale->setPalette(palette);

            cache.scaleFont[axis] = scale->font();
            scale->setFont(font(cache.scaleFont[axis], AxisScale, axis));

            cache.scaleTitleColor[axis] = scale->titleColor();
            scale->setTitleColor(
                color(cache.scaleTitleColor[axis], AxisTitle, axis));

            cache.scaleTitleFont[axis] = scale->titleFont();
            scale->setTitleFont(
                font(cache.scaleTitleFont[axis], AxisTitle, axis));

            int startDist, endDist;
            scale->minBorderDist(startDist, endDist);
            scale->setBorderDist(startDist, endDist);
        }
    }

    cache.widgetBackground = plot->backgroundColor();
    plot->setBackgroundColor(color(cache.widgetBackground, WidgetBackground));

    cache.canvasBackground = plot->canvasBackground();
    plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground));

    QPen pen = plot->d_grid->majPen();
    cache.gridColors[0] = pen.color();
    pen.setColor(color(pen.color(), MajorGrid));
    plot->d_grid->setMajPen(pen);

    pen = plot->d_grid->minPen();
    cache.gridColors[1] = pen.color();
    pen.setColor(color(pen.color(), MinorGrid));
    plot->d_grid->setMinPen(pen);
    
    QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves);
    for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )
    {
        const int key = itc.currentKey();

        QwtSymbol symbol = c->symbol();

        QPen pen = symbol.pen();
        cache.curveSymbolPenColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), CurveSymbol, key));
        symbol.setPen(pen);

        QBrush brush = symbol.brush();
        cache.curveSymbolBrushColors.insert(key, new QColor(brush.color()));
        brush.setColor(color(brush.color(), CurveSymbol, key));
        symbol.setBrush(brush);

        c->setSymbol(symbol);

        pen = c->pen();
        cache.curveColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), Curve, key));
        c->setPen(pen);
    }

    QIntDictIterator<QwtPlotMarker> itm(*plot->d_markers);
    for (QwtPlotMarker *m = itm.toFirst(); m != 0; m = ++itm )
    {
        const int key = itm.currentKey();

        cache.markerFonts.insert(key, new QFont(m->font()));
        m->setFont(font(m->font(), Marker, key));

        QPen pen = m->labelPen();
        cache.markerLabelColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), Marker, key));
        m->setLabelPen(pen);
        
        pen = m->linePen();
        cache.markerLineColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), Marker, key));
        m->setLinePen(pen);

        QwtSymbol symbol = m->symbol();

        pen = symbol.pen();
        cache.markerSymbolPenColors.insert(key, new QColor(pen.color()));
        pen.setColor(color(pen.color(), MarkerSymbol, key));
        symbol.setPen(pen);

        QBrush brush = symbol.brush();
        cache.markerSymbolBrushColors.insert(key, new QColor(brush.color()));
        brush.setColor(color(brush.color(), MarkerSymbol, key));
        symbol.setBrush(brush);

        m->setSymbol(symbol);
    }
}
/*! 
   Reset color and fonts of a plot
   \sa QwtPlotPrintFilter::apply
*/
void QwtPlotPrintFilter::reset(QwtPlot *plot) const
{
    if ( d_cache == 0 )
        return;

    QFont *font;
    QColor *color;

    if ( plot->d_lblTitle )
    {
        QPalette palette = plot->d_lblTitle->palette();
        palette.setColor(
            QPalette::Active, QColorGroup::Foreground, d_cache->titleColor);
        plot->d_lblTitle->setPalette(palette);

        plot->d_lblTitle->setFont(d_cache->titleFont);
    }

    if ( plot->d_legend )
    {
        QIntDictIterator<QWidget> it = plot->d_legend->itemIterator();
        for ( QWidget *w = it.toFirst(); w != 0; w = ++it)
        {
            const int key = it.currentKey();

            font = d_cache->legendFonts.find(key);
            if ( font )
                w->setFont(*font);

            if ( w->inherits("QwtLegendButton") )
            {
                QwtLegendButton *btn = (QwtLegendButton *)w;

                QwtSymbol symbol = btn->symbol();
                color = d_cache->curveSymbolPenColors.find(key);
                if ( color )
                {
                    QPen pen = symbol.pen();
                    pen.setColor(*color);
                    symbol.setPen(pen);
                }

                color = d_cache->curveSymbolBrushColors.find(key);
                if ( color )
                {
                    QBrush brush = symbol.brush();
                    brush.setColor(*color);
                    symbol.setBrush(brush);
                }
                btn->setSymbol(symbol);

                color = d_cache->curveColors.find(key);
                if ( color )
                {
                    QPen pen = btn->curvePen();
                    pen.setColor(*color);
                    btn->setCurvePen(pen);
                }
            }
        }
    }
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        QwtScale *scale = plot->d_scale[axis];
        if ( scale )
        {
            QPalette palette = scale->palette();
            palette.setColor(QPalette::Active, QColorGroup::Foreground,
                             d_cache->scaleColor[axis]);
            scale->setPalette(palette);
            scale->setFont(d_cache->scaleFont[axis]);

            scale->setTitleColor(d_cache->scaleTitleColor[axis]);
            scale->setTitleFont(d_cache->scaleTitleFont[axis]);

            int startDist, endDist;
            scale->minBorderDist(startDist, endDist);
            scale->setBorderDist(startDist, endDist);
        }
    }

    plot->setBackgroundColor(d_cache->widgetBackground);
    plot->setCanvasBackground(d_cache->canvasBackground);

    QPen pen = plot->d_grid->majPen();
    pen.setColor(d_cache->gridColors[0]);
    plot->d_grid->setMajPen(pen);

    pen = plot->d_grid->minPen();
    pen.setColor(d_cache->gridColors[1]);
    plot->d_grid->setMinPen(pen);
    
    QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves);
    for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )
    {
        const int key = itc.currentKey();

        QwtSymbol symbol = c->symbol();

        color = d_cache->curveSymbolPenColors.find(key);
        if ( color )
        {
            QPen pen = symbol.pen();
            pen.setColor(*color);
            symbol.setPen(pen);
        }

        color = d_cache->curveSymbolBrushColors.find(key);
        if ( color )
        {
            QBrush brush = symbol.brush();
            brush.setColor(*color);
            symbol.setBrush(brush);
        }
        c->setSymbol(symbol);

        color = d_cache->curveColors.find(key);
        if ( color )
        {
            QPen pen = c->pen();
            pen.setColor(*color);
            c->setPen(pen);
        }
    }

    QIntDictIterator<QwtPlotMarker> itm(*plot->d_markers);
    for (QwtPlotMarker *m = itm.toFirst(); m != 0; m = ++itm )
    {
        const int key = itm.currentKey();

        font = d_cache->markerFonts.find(key);
        if ( font )
            m->setFont(*font);

        color = d_cache->markerLabelColors.find(key);
        if ( color )
        {
            QPen pen = m->labelPen();
            pen.setColor(*color);
            m->setLabelPen(pen);
        }

        color = d_cache->markerLineColors.find(key);
        if ( color )
        {
            QPen pen = m->linePen();
            pen.setColor(*color);
            m->setLinePen(pen);
        }
        
        QwtSymbol symbol = m->symbol();

        color = d_cache->markerSymbolPenColors.find(key);
        if ( color )
        {
            QPen pen = symbol.pen();
            pen.setColor(*color);
            symbol.setPen(pen);
        }

        color = d_cache->markerSymbolBrushColors.find(key);
        if ( color )
        {
            QBrush brush = symbol.brush();
            brush.setColor(*color);
            symbol.setBrush(brush);
        }

        m->setSymbol(symbol);

    }

    QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this;
    delete that->d_cache;
    that->d_cache = 0;
}
/*! 
  Change color and fonts of a plot
  \sa apply()
*/
void QwtPlotPrintFilter::apply(QwtPlot *plot) const
{
    const bool doAutoReplot = plot->autoReplot();
    plot->setAutoReplot(false);

    delete d_data->cache;
    d_data->cache = new PrivateData::Cache;

    PrivateData::Cache &cache = *d_data->cache;

    if ( plot->titleLabel() )
    {
        QPalette palette = plot->titleLabel()->palette();
        cache.titleColor = palette.color(
            QPalette::Active, Palette::Text);
        palette.setColor(QPalette::Active, Palette::Text,
                         color(cache.titleColor, Title));
        plot->titleLabel()->setPalette(palette);

        cache.titleFont = plot->titleLabel()->font();
        plot->titleLabel()->setFont(font(cache.titleFont, Title));
    }
    if ( plot->legend() )
    {
#if QT_VERSION < 0x040000
        QValueList<QWidget *> list = plot->legend()->legendItems();
        for ( QValueListIterator<QWidget *> it = list.begin();
            it != list.end(); ++it )
#else
        QList<QWidget *> list = plot->legend()->legendItems();
        for ( QList<QWidget*>::iterator it = list.begin();
            it != list.end(); ++it )
#endif
        {
            QWidget *w = *it;

            cache.legendFonts.insert(w, w->font());
            w->setFont(font(w->font(), Legend));

            if ( w->inherits("QwtLegendItem") )
            {
                QwtLegendItem *label = (QwtLegendItem *)w;

                QwtSymbol symbol = label->symbol();
                QPen pen = symbol.pen();
                QBrush brush = symbol.brush();

                pen.setColor(color(pen.color(), CurveSymbol));
                brush.setColor(color(brush.color(), CurveSymbol));

                symbol.setPen(pen);
                symbol.setBrush(brush);
                label->setSymbol(symbol);

                pen = label->curvePen();
                pen.setColor(color(pen.color(), Curve));
                label->setCurvePen(pen);
            }
        }
    }
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        QwtScaleWidget *scaleWidget = plot->axisWidget(axis);
        if ( scaleWidget )
        {
            cache.scaleColor[axis] = scaleWidget->palette().color(
                QPalette::Active, Palette::Foreground);
            QPalette palette = scaleWidget->palette();
            palette.setColor(QPalette::Active, Palette::Foreground,
                             color(cache.scaleColor[axis], AxisScale));
            scaleWidget->setPalette(palette);

            cache.scaleFont[axis] = scaleWidget->font();
            scaleWidget->setFont(font(cache.scaleFont[axis], AxisScale));

            cache.scaleTitle[axis] = scaleWidget->title();

            QwtText scaleTitle = scaleWidget->title();
            if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextColor) )
            {
                cache.scaleTitleColor[axis] = scaleTitle.color();
                scaleTitle.setColor(
                    color(cache.scaleTitleColor[axis], AxisTitle));
            }

            if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextFont) )
            {
                cache.scaleTitleFont[axis] = scaleTitle.font();
                scaleTitle.setFont(
                    font(cache.scaleTitleFont[axis], AxisTitle));
            }

            scaleWidget->setTitle(scaleTitle);

            int startDist, endDist;
            scaleWidget->getBorderDistHint(startDist, endDist);
            scaleWidget->setBorderDist(startDist, endDist);
        }
    }

    if ( hasBackgroundColor(plot) )
    {
        QPalette p = plot->palette();
        cache.widgetBackground = plot->palette().color(
            QPalette::Active, Palette::Background);
        p.setColor(QPalette::Active, Palette::Background, 
            color(cache.widgetBackground, WidgetBackground));
        plot->setPalette(p);
    }

    if ( hasBackgroundColor(plot->canvas()))
    {
        cache.canvasBackground = plot->canvasBackground();
        plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground));
    }

    const QwtPlotItemList& itmList = plot->itemList();
    for ( QwtPlotItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
    {
        apply(*it);
    }

    plot->setAutoReplot(doAutoReplot);
}
Exemple #26
0
static inline void qwtDrawStar2Symbols( QPainter *painter,
    const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
    QPen pen = symbol.pen();
    if ( pen.width() > 1 )
        pen.setCapStyle( Qt::FlatCap );
    pen.setJoinStyle( Qt::MiterJoin );
    painter->setPen( pen );

    painter->setBrush( symbol.brush() );

    const double cos30 = 0.866025; // cos(30°)

    const double dy = 0.25 * symbol.size().height();
    const double dx = 0.5 * symbol.size().width() * cos30 / 3.0;

    QPolygonF star( 12 );
    QPointF *starPoints = star.data();

    const bool doAlign = QwtPainter::roundingAlignment( painter );

    for ( int i = 0; i < numPoints; i++ )
    {
        double x = points[i].x();
        double y = points[i].y();
        if ( doAlign )
        {
            x = qRound( x );
            y = qRound( y );
        }

        double x1 = x - 3 * dx;
        double y1 = y - 2 * dy;
        if ( doAlign )
        {
            x1 = qRound( x - 3 * dx );
            y1 = qRound( y - 2 * dy );
        }

        const double x2 = x1 + 1 * dx;
        const double x3 = x1 + 2 * dx;
        const double x4 = x1 + 3 * dx;
        const double x5 = x1 + 4 * dx;
        const double x6 = x1 + 5 * dx;
        const double x7 = x1 + 6 * dx;

        const double y2 = y1 + 1 * dy;
        const double y3 = y1 + 2 * dy;
        const double y4 = y1 + 3 * dy;
        const double y5 = y1 + 4 * dy;

        starPoints[0].rx() = x4;
        starPoints[0].ry() = y1;

        starPoints[1].rx() = x5;
        starPoints[1].ry() = y2;

        starPoints[2].rx() = x7;
        starPoints[2].ry() = y2;

        starPoints[3].rx() = x6;
        starPoints[3].ry() = y3;

        starPoints[4].rx() = x7;
        starPoints[4].ry() = y4;

        starPoints[5].rx() = x5;
        starPoints[5].ry() = y4;

        starPoints[6].rx() = x4;
        starPoints[6].ry() = y5;

        starPoints[7].rx() = x3;
        starPoints[7].ry() = y4;

        starPoints[8].rx() = x1;
        starPoints[8].ry() = y4;

        starPoints[9].rx() = x2;
        starPoints[9].ry() = y3;

        starPoints[10].rx() = x1;
        starPoints[10].ry() = y2;

        starPoints[11].rx() = x3;
        starPoints[11].ry() = y2;

        QwtPainter::drawPolygon( painter, star );
    }
}
void QwtPlotPrintFilter::apply(QwtPlotItem *item) const
{
    PrivateData::Cache &cache = *d_data->cache;

    switch(item->rtti())
    {
        case QwtPlotItem::Rtti_PlotGrid:
        {
            QwtPlotGrid *grid = (QwtPlotGrid *)item;

            QPen pen = grid->majPen();
            cache.gridColors[0] = pen.color();
            pen.setColor(color(pen.color(), MajorGrid));
            grid->setMajPen(pen);

            pen = grid->minPen();
            cache.gridColors[1] = pen.color();
            pen.setColor(color(pen.color(), MinorGrid));
            grid->setMinPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotCurve:
        {
            QwtPlotCurve *c = (QwtPlotCurve *)item;

            QwtSymbol symbol = c->symbol();

            QPen pen = symbol.pen();
            cache.curveSymbolPenColors.insert(c, pen.color());
            pen.setColor(color(pen.color(), CurveSymbol));
            symbol.setPen(pen);

            QBrush brush = symbol.brush();
            cache.curveSymbolBrushColors.insert(c, brush.color());
            brush.setColor(color(brush.color(), CurveSymbol));
            symbol.setBrush(brush);

            c->setSymbol(symbol);

            pen = c->pen();
            cache.curveColors.insert(c, pen.color());
            pen.setColor(color(pen.color(), Curve));
            c->setPen(pen);

            break;
        }
        case QwtPlotItem::Rtti_PlotMarker:
        {
            QwtPlotMarker *m = (QwtPlotMarker *)item;

            QwtText label = m->label();
            cache.markerFonts.insert(m, label.font());
            label.setFont(font(label.font(), Marker));
            cache.markerLabelColors.insert(m, label.color());
            label.setColor(color(label.color(), Marker));
            m->setLabel(label);
            
            QPen pen = m->linePen();
            cache.markerLineColors.insert(m, pen.color());
            pen.setColor(color(pen.color(), Marker));
            m->setLinePen(pen);

            QwtSymbol symbol = m->symbol();

            pen = symbol.pen();
            cache.markerSymbolPenColors.insert(m, pen.color());
            pen.setColor(color(pen.color(), MarkerSymbol));
            symbol.setPen(pen);

            QBrush brush = symbol.brush();
            cache.markerSymbolBrushColors.insert(m, brush.color());
            brush.setColor(color(brush.color(), MarkerSymbol));
            symbol.setBrush(brush);

            m->setSymbol(symbol);

            break;
        }
        default:    
            break;
    }
}