void Grid::enableZeroLineX(bool enable) { Plot *d_plot = (Plot *)plot(); if (!d_plot) return; if (mrkX<0 && enable) { QwtPlotMarker *m = new QwtPlotMarker(); mrkX = d_plot->insertMarker(m); m->setRenderHint(QwtPlotItem::RenderAntialiased, false); m->setAxis(xAxis(), yAxis()); m->setLineStyle(QwtPlotMarker::VLine); m->setValue(0.0, 0.0); double width = 1; if (d_plot->canvas()->lineWidth()) width = d_plot->canvas()->lineWidth(); else if (d_plot->axisEnabled (QwtPlot::yLeft) || d_plot->axisEnabled (QwtPlot::yRight)) width = d_plot->axesLinewidth(); m->setLinePen(QPen(Qt::black, width, Qt::SolidLine)); } else if (mrkX >= 0 && !enable) { d_plot->removeMarker(mrkX); mrkX=-1; } }
void PlotWindow::drawLapMarkers() { if (_data_log->numLaps() > 1) { for (int i=0; i < _data_log->numLaps(); ++i) { QwtPlotMarker* marker = new QwtPlotMarker; marker->setLineStyle(QwtPlotMarker::VLine); marker->setLinePen(QPen(Qt::DotLine)); if (_x_axis_measurement->currentIndex() == 0) // time { const double time = _data_log->time(_data_log->lap(i).second); marker->setXValue(time); } else // distance { const double dist = _data_log->dist(_data_log->lap(i).second); marker->setXValue(dist); } marker->attach(_plot); marker->show(); _lap_markers.push_back(marker); } } }
void Grid::enableZeroLineY(bool enable) { Plot *d_plot = dynamic_cast<Plot *>(plot()); if (!d_plot) return; if (mrkY < 0 && enable) { QwtPlotMarker *m = new QwtPlotMarker(); mrkY = d_plot->insertMarker(m); m->setRenderHint(QwtPlotItem::RenderAntialiased, false); m->setAxis(xAxis(), yAxis()); m->setLineStyle(QwtPlotMarker::HLine); m->setValue(0.0, 0.0); double width = 1; if (d_plot->canvas()->lineWidth()) width = d_plot->canvas()->lineWidth(); else if (d_plot->axisEnabled(QwtPlot::xBottom) || d_plot->axisEnabled(QwtPlot::xTop)) width = d_plot->axesLinewidth(); m->setLinePen(QPen(Qt::black, width, Qt::SolidLine)); } else if (mrkY >= 0 && !enable) { d_plot->removeMarker(mrkY); mrkY = -1; } }
void Plot::clear() { this->detachItems(); pointsArr.clear(); // ...a horizontal line at y = 1... QwtPlotMarker *mY1 = new QwtPlotMarker(); mY1->setLabel( QString::fromLatin1( "y = 1" ) ); mY1->setLabelAlignment( Qt::AlignRight | Qt::AlignTop ); mY1->setLineStyle( QwtPlotMarker::HLine ); mY1->setYValue( 1.0 ); mY1->setLinePen(Qt::black, 1, Qt::DashLine); mY1->attach( this ); QwtPlotMarker *mY = new QwtPlotMarker(); mY->setLabel( QString::fromLatin1( "y = 0" ) ); mY->setLabelAlignment( Qt::AlignRight | Qt::AlignTop ); mY->setLineStyle( QwtPlotMarker::HLine ); mY->setYValue( 0.0 ); mY->attach( this ); // ...a vertical line at x = 0 QwtPlotMarker *mX = new QwtPlotMarker(); mX->setLabel( QString::fromLatin1( "x = 0" ) ); mX->setLabelAlignment( Qt::AlignLeft | Qt::AlignBottom ); mX->setLabelOrientation( Qt::Vertical ); mX->setLineStyle( QwtPlotMarker::VLine ); mX->setLinePen( Qt::black, 0, Qt::DashDotLine ); mX->setXValue( 0 ); mX->attach( this ); }
void Plot_AddHLine(QwtPlot* plot, double value , double r , double g, double b) { QwtPlotMarker *marker = new QwtPlotMarker(); marker->setLineStyle ( QwtPlotMarker::HLine ); marker->setLinePen(QPen(QColor(r, g, b, 128), 1, Qt::DashDotLine)); marker->attach( plot ); marker->setYValue( value ); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QwtPlotMarker* RicGridStatisticsDialog::createVerticalPlotMarker(const QColor& color, double xValue) { QwtPlotMarker* marker = new QwtPlotMarker(); marker->setXValue(xValue); marker->setLineStyle(QwtPlotMarker::VLine); marker->setLinePen(color, 2, Qt::SolidLine); return marker; }
/** * This is a helper method to create new band markers with the same line * style and a custom color. * * @param color The color of the band marker * @return The requested plot marker; ownership is passed to the caller */ QwtPlotMarker *SpectralPlotWindow::createMarker(QColor color) { QPen markerPen(color); markerPen.setWidth(1); QwtPlotMarker *newMarker = new QwtPlotMarker; newMarker->setLineStyle(QwtPlotMarker::LineStyle(2)); newMarker->setLinePen(markerPen); newMarker->attach(plot()); newMarker->setVisible(false); return newMarker; }
/*! \brief Specify a pen for a marker's label. \param key Marker key \param p New pen \return \c TRUE if the specified marker exists */ bool QwtPlot::setMarkerPen(long key, const QPen &p) { int rv = FALSE; QwtPlotMarker *m; if ((m = d_markers->find(key))) { m->setLinePen(p); m->setLabelPen(p); rv = TRUE; } return rv; }
Plot::Plot() { setTitle("A Simple QwtPlot Demonstration"); insertLegend(new QwtLegend(), QwtPlot::RightLegend); // Set axis titles setAxisTitle(xBottom, "x -->"); setAxisTitle(yLeft, "y -->"); // Insert new curves QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)"); #if QT_VERSION >= 0x040000 cSin->setRenderHint(QwtPlotItem::RenderAntialiased); #endif cSin->setPen(QPen(Qt::red)); cSin->attach(this); QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)"); #if QT_VERSION >= 0x040000 cCos->setRenderHint(QwtPlotItem::RenderAntialiased); #endif cCos->setPen(QPen(Qt::blue)); cCos->attach(this); // Create sin and cos data const int nPoints = 100; cSin->setData(SimpleData(::sin, nPoints)); cCos->setData(SimpleData(::cos, nPoints)); // Insert markers // ...a horizontal line at y = 0... QwtPlotMarker *mY = new QwtPlotMarker(); mY->setLabel(QString::fromLatin1("y = 0")); mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop); mY->setLineStyle(QwtPlotMarker::HLine); mY->setYValue(0.0); mY->attach(this); // ...a vertical line at x = 2 * pi QwtPlotMarker *mX = new QwtPlotMarker(); mX->setLabel(QString::fromLatin1("x = 2 pi")); mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom); mX->setLabelOrientation(Qt::Vertical); mX->setLineStyle(QwtPlotMarker::VLine); mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine)); mX->setXValue(2.0 * M_PI); mX->attach(this); }
void Graph::addMarker(double val, const QColor &color, int axis) { QwtPlotMarker *m = new QwtPlotMarker(); m->setLineStyle(axis == QwtPlot::xBottom ? QwtPlotMarker::VLine : QwtPlotMarker::HLine); m->setLinePen(QPen(color)); m->setYAxis(axis); m->setValue(val, val); m->attach(this); m->setLabel(QString::number(val)); if(axis == QwtPlot::xBottom) m->setLabelAlignment(Qt::AlignLeft | Qt::AlignVCenter); else m->setLabelAlignment(Qt::AlignTop | Qt::AlignHCenter); getMarkers(axis).push_back(m); }
void QmitkTbssRoiAnalysisWidget::drawBar(int x) { m_Plot->detachItems(QwtPlotItem::Rtti_PlotMarker, true); QwtPlotMarker *mX = new QwtPlotMarker(); //mX->setLabel(QString::fromLatin1("selected point")); mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom); mX->setLabelOrientation(Qt::Vertical); mX->setLineStyle(QwtPlotMarker::VLine); mX->setLinePen(QPen(Qt::black, 0, Qt::SolidLine)); mX->setXValue(x); mX->attach(m_Plot); this->Replot(); }
void VectorPlot::addHorizontalLine(double value, QString labelText) { QPen pen(QColor(0, 0, 255)); QwtPlotMarker* horizontalLineMarker = new QwtPlotMarker(); horizontalLineMarker->setLineStyle(QwtPlotMarker::HLine); horizontalLineMarker->setLinePen(pen); horizontalLineMarker->setYValue(value); QwtText label; label.setText(labelText); QFont font = label.font(); font.setPointSize(9); label.setFont(font); horizontalLineMarker->setLabel(label); horizontalLineMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignLeft); horizontalLineMarker->attach(plot); }
void Plot::populate() { // Insert new curves QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)"); cSin->setRenderHint(QwtPlotItem::RenderAntialiased); cSin->setLegendAttribute(QwtPlotCurve::LegendShowLine, true); cSin->setPen(QPen(Qt::red)); cSin->attach(this); QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)"); cCos->setRenderHint(QwtPlotItem::RenderAntialiased); cCos->setLegendAttribute(QwtPlotCurve::LegendShowLine, true); cCos->setPen(QPen(Qt::blue)); cCos->attach(this); // Create sin and cos data cSin->setData(new FunctionData(::sin)); cCos->setData(new FunctionData(::cos)); // Insert markers // ...a horizontal line at y = 0... QwtPlotMarker *mY = new QwtPlotMarker(); mY->setLabel(QString::fromLatin1("y = 0")); mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop); mY->setLineStyle(QwtPlotMarker::HLine); mY->setYValue(0.0); mY->attach(this); // ...a vertical line at x = 2 * pi QwtPlotMarker *mX = new QwtPlotMarker(); mX->setLabel(QString::fromLatin1("x = 2 pi")); mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom); mX->setLabelOrientation(Qt::Vertical); mX->setLineStyle(QwtPlotMarker::VLine); mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine)); mX->setXValue(2.0 * M_PI); mX->attach(this); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_accelXPoints(100, QPointF(0, 0)), m_accelYPoints(100, QPointF(0, 0)), m_gyroXPoints(100, QPointF(0, 0)), m_gyroYPoints(100, QPointF(0, 0)), m_counter(0), m_power(0) { ui->setupUi(this); // init scenes xScene = new QGraphicsScene(); yScene = new QGraphicsScene(); xScene->setBackgroundBrush(Qt::white); yScene->setBackgroundBrush(Qt::white); ui->xGraphicsView->setScene(xScene); ui->yGraphicsView->setScene(yScene); m_tcpSocket = new QTcpSocket(this); connect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(onTcpRead())); m_controlSocket = new QTcpSocket(this); connect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(onControlRead())); // connecting connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(connectToServer())); connect(ui->disconnectButton, SIGNAL(clicked()), this, SLOT(disconnectFromServer())); // control buttons connect(ui->up2Button, SIGNAL(clicked()), this, SLOT(handleControlButton())); connect(ui->up1Button, SIGNAL(clicked()), this, SLOT(handleControlButton())); connect(ui->zeroButton, SIGNAL(clicked()), this, SLOT(handleControlButton())); connect(ui->down1Button, SIGNAL(clicked()), this, SLOT(handleControlButton())); connect(ui->down2Button, SIGNAL(clicked()), this, SLOT(handleControlButton())); // plotting setup m_accelXData = new QwtPointSeriesData(); m_accelYData = new QwtPointSeriesData(); m_accelXCurve = new QwtPlotCurve("Accel X"); m_accelYCurve = new QwtPlotCurve("Accel Y"); m_accelXCurve->setPen( QPen( Qt::black ) ); m_accelYCurve->setPen( QPen( Qt::red)); m_accelXCurve->attach( ui->plot ); m_accelYCurve->attach(ui->plot); m_gyroXData = new QwtPointSeriesData(); m_gyroYData = new QwtPointSeriesData(); m_gyroXCurve = new QwtPlotCurve("Gyro X"); m_gyroYCurve = new QwtPlotCurve("Gyro Y"); m_gyroXCurve->setPen( QPen( Qt::green ) ); m_gyroYCurve->setPen( QPen( Qt::blue)); m_gyroXCurve->attach( ui->plot ); m_gyroYCurve->attach(ui->plot); ui->plot->setCanvasBackground(Qt::white); // Axes ui->plot->setAxisTitle( QwtPlot::xBottom, "Seconds" ); ui->plot->setAxisTitle( QwtPlot::yLeft, "Degrees" ); ui->plot->setAxisScale( QwtPlot::yLeft, -90, 90 ); // zero line QwtPlotMarker* zeroMarker = new QwtPlotMarker(); zeroMarker->setLineStyle(QwtPlotMarker::HLine); zeroMarker->setLinePen(QPen(Qt::DotLine)); zeroMarker->setSymbol(new QwtSymbol(QwtSymbol::HLine)); zeroMarker->setYValue(0); zeroMarker->attach(ui->plot); updatePlot(0, 0, 0, 0); }
/*! 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 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); } }
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; } }
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; } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPvtPlotWidget::plotCurves(RiaEclipseUnitTools::UnitSystem unitSystem, const std::vector<RigFlowDiagSolverInterface::PvtCurve>& curveArr, double pressure, double pointMarkerYValue, QString pointMarkerLabel, QString plotTitle, QString yAxisTitle) { m_qwtPlot->detachItems(QwtPlotItem::Rtti_PlotCurve); m_qwtPlot->detachItems(QwtPlotItem::Rtti_PlotMarker); m_qwtCurveArr.clear(); m_pvtCurveArr.clear(); m_trackerPlotMarker = nullptr; // Construct an auxiliary curve that connects the first point in all the input curves as a visual aid // This should only be shown when the phase being plotted is oil // Will not be added to our array of qwt curves since we do not expect the user to interact with it { std::vector<double> xVals; std::vector<double> yVals; for (size_t i = 0; i < curveArr.size(); i++) { const RigFlowDiagSolverInterface::PvtCurve& curve = curveArr[i]; if (curve.phase == RigFlowDiagSolverInterface::PvtCurve::OIL && curve.pressureVals.size() > 0 && curve.yVals.size() > 0) { xVals.push_back(curve.pressureVals[0]); yVals.push_back(curve.yVals[0]); } } if (xVals.size() > 1) { QwtPlotCurve* qwtCurve = new QwtPlotCurve(); qwtCurve->setSamples(xVals.data(), yVals.data(), static_cast<int>(xVals.size())); qwtCurve->setStyle(QwtPlotCurve::Lines); qwtCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true); QColor curveClr = Qt::darkGreen; const QPen curvePen(curveClr); qwtCurve->setPen(curvePen); qwtCurve->attach(m_qwtPlot); } } // Add the primary curves for (size_t i = 0; i < curveArr.size(); i++) { const RigFlowDiagSolverInterface::PvtCurve& curve = curveArr[i]; QwtPlotCurve* qwtCurve = new QwtPlotCurve(); CVF_ASSERT(curve.pressureVals.size() == curve.yVals.size()); qwtCurve->setSamples(curve.pressureVals.data(), curve.yVals.data(), static_cast<int>(curve.pressureVals.size())); qwtCurve->setStyle(QwtPlotCurve::Lines); QColor curveClr = Qt::magenta; if (curve.phase == RigFlowDiagSolverInterface::PvtCurve::GAS) curveClr = QColor(Qt::red); else if (curve.phase == RigFlowDiagSolverInterface::PvtCurve::OIL) curveClr = QColor(Qt::green); const QPen curvePen(curveClr); qwtCurve->setPen(curvePen); qwtCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true); QwtSymbol* curveSymbol = new QwtSymbol(QwtSymbol::Ellipse); curveSymbol->setSize(6, 6); curveSymbol->setPen(curvePen); curveSymbol->setBrush(Qt::NoBrush); qwtCurve->setSymbol(curveSymbol); qwtCurve->attach(m_qwtPlot); m_qwtCurveArr.push_back(qwtCurve); } m_pvtCurveArr = curveArr; CVF_ASSERT(m_pvtCurveArr.size() == m_qwtCurveArr.size()); // Add vertical marker line to indicate cell pressure if (pressure != HUGE_VAL) { QwtPlotMarker* lineMarker = new QwtPlotMarker; lineMarker->setXValue(pressure); lineMarker->setLineStyle(QwtPlotMarker::VLine); lineMarker->setLinePen(QPen(QColor(128, 128, 255), 1, Qt::DashLine)); lineMarker->setLabel(QString("PRESSURE")); lineMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignRight); lineMarker->setLabelOrientation(Qt::Vertical); lineMarker->attach(m_qwtPlot); } // Then point marker if (pressure != HUGE_VAL && pointMarkerYValue != HUGE_VAL) { QwtPlotMarker* pointMarker = new QwtPlotMarker; pointMarker->setValue(pressure, pointMarkerYValue); QColor markerClr(128, 0, 255); QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Ellipse); symbol->setSize(13, 13); symbol->setPen(QPen(markerClr, 2)); symbol->setBrush(Qt::NoBrush); pointMarker->setSymbol(symbol); if (!pointMarkerLabel.isEmpty()) { QwtText text(pointMarkerLabel); text.setRenderFlags(Qt::AlignLeft); text.setColor(markerClr); pointMarker->setLabel(text); pointMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignRight); } pointMarker->attach(m_qwtPlot); } m_qwtPlot->setTitle(plotTitle); m_qwtPlot->setAxisTitle(QwtPlot::xBottom, QString("Pressure [%1]").arg(RiaEclipseUnitTools::unitStringPressure(unitSystem))); m_qwtPlot->setAxisTitle(QwtPlot::yLeft, yAxisTitle); updateTrackerPlotMarkerAndLabelFromPicker(); m_qwtPlot->replot(); }
Plot::Plot(QWidget *parent): QwtPlot( parent ) { setAutoFillBackground( true ); setPalette( QPalette( QColor( 165, 193, 228 ) ) ); updateGradient(); setTitle( "График аппроксимации" ); insertLegend( new QwtLegend(), QwtPlot::RightLegend ); // axes setAxisTitle( xBottom, "" ); setAxisScale( xBottom, 0.0, 10.0 ); setAxisTitle( yLeft, "Функция принадлежности -->" ); setAxisScale( yLeft, 0, 2 ); // canvas QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setLineWidth( 1 ); canvas->setFrameStyle( QFrame::Box | QFrame::Plain ); canvas->setBorderRadius( 15 ); QPalette canvasPalette( Qt::white ); canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) ); canvas->setPalette( canvasPalette ); setCanvas( canvas ); // panning with the left mouse button ( void ) new QwtPlotPanner( canvas ); // zoom in/out with the wheel ( void ) new QwtPlotMagnifier( canvas ); // ...a horizontal line at y = 0... QwtPlotMarker *mY = new QwtPlotMarker(); mY->setLabel( QString::fromLatin1( "y = 0" ) ); mY->setLabelAlignment( Qt::AlignRight | Qt::AlignTop ); mY->setLineStyle( QwtPlotMarker::HLine ); mY->setYValue( 0.0 ); mY->attach( this ); // ...a horizontal line at y = 1... QwtPlotMarker *mY1 = new QwtPlotMarker(); mY1->setLabel( QString::fromLatin1( "y = 1" ) ); mY1->setLabelAlignment( Qt::AlignRight | Qt::AlignTop ); mY1->setLineStyle( QwtPlotMarker::HLine ); mY1->setYValue( 1.0 ); mY1->setLinePen(Qt::black, 1, Qt::DashLine); mY1->attach( this ); // ...a vertical line at x = 0 QwtPlotMarker *mX = new QwtPlotMarker(); mX->setLabel( QString::fromLatin1( "x = 0" ) ); mX->setLabelAlignment( Qt::AlignLeft | Qt::AlignBottom ); mX->setLabelOrientation( Qt::Vertical ); mX->setLineStyle( QwtPlotMarker::VLine ); mX->setLinePen( Qt::black, 0, Qt::DashDotLine ); mX->setXValue( 0 ); mX->attach( this ); // curvePoints = new QwtPlotCurve(); // curvePoints->setStyle( QwtPlotCurve::Dots ); // curvePoints->attach( this ); }
void Plot::populate() { GridItem *gridItem = new GridItem(); #if 0 gridItem->setOrientations( Qt::Horizontal ); #endif gridItem->attach( this ); const Qt::GlobalColor colors[] = { Qt::red, Qt::blue, Qt::darkCyan, Qt::darkMagenta, Qt::darkYellow }; const int numColors = sizeof( colors ) / sizeof( colors[0] ); for ( int i = 0; i < QuoteFactory::NumStocks; i++ ) { QuoteFactory::Stock stock = static_cast<QuoteFactory::Stock>( i ); QwtPlotTradingCurve *curve = new QwtPlotTradingCurve(); curve->setTitle( QuoteFactory::title( stock ) ); curve->setOrientation( Qt::Vertical ); curve->setSamples( QuoteFactory::samples2010( stock ) ); // as we have one sample per day a symbol width of // 12h avoids overlapping symbols. We also bound // the width, so that is is not scaled below 3 and // above 15 pixels. curve->setSymbolExtent( 12 * 3600 * 1000.0 ); curve->setMinSymbolWidth( 3 ); curve->setMaxSymbolWidth( 15 ); const Qt::GlobalColor color = colors[ i % numColors ]; curve->setSymbolPen( color ); curve->setSymbolBrush( QwtPlotTradingCurve::Decreasing, color ); curve->setSymbolBrush( QwtPlotTradingCurve::Increasing, Qt::white ); curve->attach( this ); showItem( curve, true ); } for ( int i = 0; i < 2; i++ ) { QwtPlotMarker *marker = new QwtPlotMarker(); marker->setTitle( QString( "Event %1" ).arg( i + 1 ) ); marker->setLineStyle( QwtPlotMarker::VLine ); marker->setLinePen( colors[ i % numColors ], 0, Qt::DashLine ); marker->setVisible( false ); QDateTime dt( QDate( 2010, 1, 1 ) ); dt = dt.addDays( 77 * ( i + 1 ) ); marker->setValue( QwtDate::toDouble( dt ), 0.0 ); marker->setItemAttribute( QwtPlotItem::Legend, true ); marker->attach( this ); } // to show how QwtPlotZoneItem works ZoneItem *zone1 = new ZoneItem( "Zone 1"); zone1->setColor( Qt::darkBlue ); zone1->setInterval( QDate( 2010, 3, 10 ), QDate( 2010, 3, 27 ) ); zone1->setVisible( false ); zone1->attach( this ); ZoneItem *zone2 = new ZoneItem( "Zone 2"); zone2->setColor( Qt::darkMagenta ); zone2->setInterval( QDate( 2010, 8, 1 ), QDate( 2010, 8, 24 ) ); zone2->setVisible( false ); zone2->attach( this ); }