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 ); }
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 Variog_plot::mouseReleaseEvent(QMouseEvent * event) { std::cerr << "show_pairs_count() called " << std::endl; if( event->button() != Qt::RightButton ) return; const float offset=1.02; QFont font; font.setPointSize( 7 ); if( !pairs_shown_ ) { for( unsigned int i=0; i < pairs_.size(); i++ ) { QString label; label.setNum( pairs_[i] ); QwtText T(label); QwtPlotMarker * marker = new QwtPlotMarker(); marker->attach(this); T.setFont(font); marker->setValue(pairs_coord_x_[i], pairs_coord_y_[i]*offset); marker->setLabel(T); } pairs_shown_ = true; } else { detachItems(QwtPlotItem::Rtti_PlotMarker); pairs_shown_ = false; } replot(); }
/*! This function is a shortcut to insert a horizontal or vertical line marker, dependent on the specified axis. \param label Label \param axis Axis to be attached \return New key if the marker could be inserted, 0 if not. */ long QwtPlot::insertLineMarker(const QString &label, int axis) { QwtMarker::LineStyle lineStyle = QwtMarker::NoLine; int xAxis = QwtPlot::xBottom; int yAxis = QwtPlot::yLeft; switch(axis) { case yLeft: case yRight: yAxis = axis; lineStyle = QwtMarker::HLine; break; case xTop: case xBottom: xAxis = axis; lineStyle = QwtMarker::VLine; break; } QwtPlotMarker *marker = new QwtPlotMarker(this); if ( marker == 0 ) return 0; marker->setAxis(xAxis, yAxis); marker->setLabel(label); marker->setLineStyle(lineStyle); marker->setLabelAlignment(Qt::AlignRight|Qt::AlignTop); long key = insertMarker(marker); if ( key == 0 ) delete marker; return key; }
void SweepInspector::loadSweep(int index) { //load in new sweep values from data if (data == NULL) return; if ( (index < 0) || (index >= data->getNumSweeps())) return; //remove old data and get new if (d_curve) d_curve->attach(NULL); detachItems(); fsweep sweep = data->getSweep(index); d_curve = new QwtPlotCurve( data->timestampFromIndex(index) ); //Qwt will delete() this when its done with it d_curve->setRenderHint( QwtPlotItem::RenderAntialiased ); d_curve->setStyle( QwtPlotCurve::Lines ); d_curve->setPen( QColor( Qt::yellow ), 2, Qt::SolidLine ); d_curve->setSamples( sweep ); d_curve->attach(this); QwtInterval frange = data->limits(FREQ); //setAxisScale(QwtPlot::xBottom, frange.minValue(), frange.maxValue(), (frange.maxValue() - frange.minValue())/ 5.0); //setAxisScale(QwtPlot::yLeft, -135, 20, 10.0); setTitle( QString("RF Sweep @ %1").arg(data->timestampFromIndex(index)) ); //set maximum zoom out zoomer->setZoomBase(QRectF(QPointF(frange.minValue(), 40), QPointF(frange.maxValue(), -135))); zoomer->zoomBase(); //find max, min, and average values and drop it on plot as well double max = sweep.first().y(), min = sweep.first().y(), avg=0; for(int i=0; i < sweep.size(); i++) { max = std::max(max, sweep.at(i).y()); min = std::min(min, sweep.at(i).y()); avg += sweep.at(i).y(); } avg /= sweep.size(); //add markers onto the plot QwtPlotMarker *one = new QwtPlotMarker(), *two = new QwtPlotMarker(); one->attach(this); one->setAxes(QwtPlot::xTop, QwtPlot::yRight); two->attach(this); two->setAxes(QwtPlot::xTop, QwtPlot::yRight); QwtText tone = QwtText(QString("Max: %1 dBm\nMin: %2 dBm\nAvg: %3 dBm").arg(max).arg(min).arg(avg)); tone.setFont( QFont( "Helvetica", 10, QFont::Bold ) ); tone.setColor( Qt::green ); tone.setRenderFlags(Qt::AlignTop | Qt::AlignLeft); one->setLabel(tone); one->setValue(0, 10); one->setLabelAlignment(Qt::AlignBottom | Qt::AlignRight); QwtText ttwo(data->plotText()); ttwo.setFont( QFont( "Helvetica", 10, QFont::Bold ) ); ttwo.setColor( Qt::white ); ttwo.setRenderFlags(Qt::AlignBottom | Qt::AlignRight); two->setLabel(ttwo); two->setValue(10, 10); two->setLabelAlignment(Qt::AlignBottom | Qt::AlignLeft); replot(); repaint(); }
void wykres::dodaj_naj(double d) { QwtPlotMarker *mY = new QwtPlotMarker(); mY->setLabel(QString::fromLatin1("Osobnik najlepszy = ")+QString::number(-d)); mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop); mY->setLineStyle(QwtPlotMarker::HLine); mY->setYValue(-d); mY->attach(this); }
/*! \brief Set the marker label \param key Marker key \param text the label text \param font the font of the label text \param color the color of the label text \param pen the pen of the bounding box of the label text \param brush the brush of the bounding box of the label text \return \c TRUE if the specified marker exists */ bool QwtPlot::setMarkerLabel(long key, const QString &text, const QFont &font, const QColor &color, const QPen &pen, const QBrush &brush) { QwtPlotMarker *m; if ((m = d_markers->find(key))) { m->setLabel(text, font, color, pen, brush); return TRUE; } return FALSE; }
/** * Dodaje dodatkowy opis wykresu. * * @param caption opis wykresu * @param x pozycja na wykresie w skali czasu * @param y pozycja na wykresie w skali pionowej (np. częstotliwości) */ void SpectrogramPlot::setExtraCaption(QString caption, double x, double y) { QwtPlotMarker* marker = new QwtPlotMarker(); QwtText label(caption); label.setColor(QColor::fromRgba(0x88FFFFFF)); label.setFont(QFont("Arial", 10, QFont::Bold)); marker->setLabel(label); marker->setLineStyle(QwtPlotMarker::NoLine); marker->setValue(x, y); marker->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom); marker->attach(this); }
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); }
void caStripPlot::addText(double x, double y, char* text, QColor c, int fontsize) { QwtPlotMarker *mY = new QwtPlotMarker(); QwtText txt; txt.setText(text); txt.setFont(QFont("Helvetica",fontsize, QFont::Bold)); txt.setColor(c); mY->setLabel(txt); mY->setLabelAlignment(Qt::AlignRight | Qt::AlignTop); mY->setXValue(x); mY->setYValue(y); mY->attach(this); replot(); }
/*! \brief Insert a new marker \param label Label \param xAxis X axis to be attached \param yAxis Y axis to be attached \return New key if the marker could be inserted, 0 if not. */ long QwtPlot::insertMarker(const QString &label, int xAxis, int yAxis) { QwtPlotMarker *marker = new QwtPlotMarker(this); if ( marker == 0 ) return 0; marker->setAxis(xAxis, yAxis); marker->setLabel(label); long key = insertMarker(marker); if ( key == 0 ) delete marker; return key; }
void MainWindow::setInitialTimeDisplay(int start) { std::size_t ncols = _vm["file.ncols"].as<int>(); std::size_t nrows = _vm["file.nrows"].as<int>(); //TODO: move plotting to appropiate method std::size_t numofplottedsamples = _vm["plot.num.samples"].as<int>(); _gridPlot->p->detachItems(); _gridPlot->setoffset(start); double interrowoffset = _vm["inter.row.offset"].as<double>(); for (std::size_t row=0; row<nrows; ++row){ // for (std::size_t row=0; row<1; ++row){ std::vector<double> xs(numofplottedsamples); std::vector<double> ys(numofplottedsamples); std::stringstream strst; std::string strTitle = "Row"; strst << strTitle << "-" << row; strTitle = strst.str(); QwtPlotCurve *tscurve = new QwtPlotCurve((char *)strTitle.c_str()); for (std::size_t x = 0; x < numofplottedsamples; ++x) { if (x+start<ncols){ xs[x] = (x+start)/_gridPlot->gridXpixelsperunit; //position in seconds if (_bf!=NULL) { ys[x] = row*interrowoffset + (*_bf)(row,x+start)/_gridPlot->gridYpixelsperunit; //y value of that sample } else if (_bfsi!=NULL) { ys[x] = row*interrowoffset + (*_bfsi)(row,x+start)/_gridPlot->gridYpixelsperunit; //y value of that sample } } } tscurve->setSamples(&xs[0],&ys[0],xs.size()); tscurve->setPen(QPen(Qt::black)); QwtPlotMarker *rowNameText = new QwtPlotMarker(); rowNameText->setLabel(QString(strTitle.c_str())); rowNameText->setXValue(xs[0]+0.25); rowNameText->setYValue(row*interrowoffset-0.5); rowNameText->attach(_gridPlot->p); tscurve->attach(_gridPlot->p); } _gridPlot->resetzoom(); }
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 VectorPlot::addMarking(const std::vector<int> &marking) { QwtDoubleRect boundingRect(0, 1, marking.size() - 1, 2); setupPlot(boundingRect); // this is gonna be slow... for(unsigned i = 0; i < marking.size(); ++i) { QwtPlotMarker* marker = new QwtPlotMarker(); QwtText text; text.setText(QString::number(marking[i])); marker->setLabel(text); marker->setXValue((double)i); marker->setYValue(0.0); marker->attach(plot); } }
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 QgsHistogramWidget::drawHistogram() { if ( !mVectorLayer || mSourceFieldExp.isEmpty() ) return; QApplication::setOverrideCursor( Qt::WaitCursor ); if ( mValues.empty() ) { bool ok; mValues = mVectorLayer->getDoubleValues( mSourceFieldExp, ok ); if ( ! ok ) { QApplication::restoreOverrideCursor(); return; } qSort( mValues.begin(), mValues.end() ); mHistogram.setValues( mValues ); mBinsSpinBox->blockSignals( true ); mBinsSpinBox->setValue( qMax( mHistogram.optimalNumberBins(), 30 ) ); mBinsSpinBox->blockSignals( false ); mStats.setStatistics( QgsStatisticalSummary::StDev ); mStats.calculate( mValues ); } // clear plot mpPlot->detachItems(); //ensure all children get removed mpPlot->setAutoDelete( true ); // Set axis titles mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr( "Value" ) ); mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr( "Count" ) ); mpPlot->setAxisAutoScale( QwtPlot::yLeft ); mpPlot->setAxisAutoScale( QwtPlot::xBottom ); // add a grid QwtPlotGrid * grid = new QwtPlotGrid(); grid->enableX( false ); grid->setPen( mGridPen ); grid->attach( mpPlot ); // make colors list mHistoColors.clear(); foreach ( QgsRendererRangeV2 range, mRanges ) { mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black ); } //draw histogram #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 QwtPlotHistogram * plotHistogram = 0; plotHistogram = createPlotHistogram( mRanges.count() > 0 ? mRanges.at( 0 ).label() : QString(), mRanges.count() > 0 ? QBrush( mHistoColors.at( 0 ) ) : mBrush, mRanges.count() > 0 ? Qt::NoPen : mPen ); #else HistogramItem *plotHistogramItem = 0; plotHistogramItem = createHistoItem( mRanges.count() > 0 ? mRanges.at( 0 ).label() : QString(), mRanges.count() > 0 ? QBrush( mHistoColors.at( 0 ) ) : mBrush, mRanges.count() > 0 ? Qt::NoPen : mPen ); #endif #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 QVector<QwtIntervalSample> dataHisto; #else // we safely assume that QT>=4.0 (min version is 4.7), therefore QwtArray is a QVector, so don't set size here QwtArray<QwtDoubleInterval> intervalsHisto; QwtArray<double> valuesHisto; #endif int bins = mBinsSpinBox->value(); QList<double> edges = mHistogram.binEdges( bins ); QList<int> counts = mHistogram.counts( bins ); int rangeIndex = 0; int lastValue = 0; for ( int bin = 0; bin < bins; ++bin ) { int binValue = counts.at( bin ); //current bin crosses two graduated ranges, so we split between //two histogram items if ( rangeIndex < mRanges.count() - 1 && edges.at( bin ) > mRanges.at( rangeIndex ).upperValue() ) { rangeIndex++; #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 plotHistogram->setSamples( dataHisto ); plotHistogram->attach( mpPlot ); plotHistogram = createPlotHistogram( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) ); dataHisto.clear(); dataHisto << QwtIntervalSample( lastValue, mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) ); #else plotHistogramItem->setData( QwtIntervalData( intervalsHisto, valuesHisto ) ); plotHistogramItem->attach( mpPlot ); plotHistogramItem = createHistoItem( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) ); intervalsHisto.clear(); valuesHisto.clear(); intervalsHisto.append( QwtDoubleInterval( mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) ) ); valuesHisto.append( lastValue ); #endif } double upperEdge = mRanges.count() > 0 ? qMin( edges.at( bin + 1 ), mRanges.at( rangeIndex ).upperValue() ) : edges.at( bin + 1 ); #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge ); #else intervalsHisto.append( QwtDoubleInterval( edges.at( bin ), upperEdge ) ); valuesHisto.append( double( binValue ) ); #endif lastValue = binValue; } #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 plotHistogram->setSamples( dataHisto ); plotHistogram->attach( mpPlot ); #else plotHistogramItem->setData( QwtIntervalData( intervalsHisto, valuesHisto ) ); plotHistogramItem->attach( mpPlot ); #endif mRangeMarkers.clear(); foreach ( QgsRendererRangeV2 range, mRanges ) { QwtPlotMarker* rangeMarker = new QwtPlotMarker(); rangeMarker->attach( mpPlot ); rangeMarker->setLineStyle( QwtPlotMarker::VLine ); rangeMarker->setXValue( range.upperValue() ); rangeMarker->setLabel( QString::number( range.upperValue() ) ); rangeMarker->setLabelOrientation( Qt::Vertical ); rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop ); rangeMarker->show(); mRangeMarkers << rangeMarker; }
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; } }
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 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(); }