QwtSymbol *SAQwtPlotCurveItemSetWidget::makeSymbol(QwtSymbol::Style style) { if(nullptr == m_curveItem) { return nullptr; } const QwtSymbol* oldSymbol = m_curveItem->symbol(); QwtSymbol* newSymbol = nullptr; if(QwtSymbol::NoSymbol != style) { newSymbol = new QwtSymbol(style); if(nullptr == oldSymbol) { //初始没有符号,第一次设置 QColor penColor = m_curveItem->pen().color(); newSymbol->setPen(penColor); penColor.setAlpha(80); newSymbol->setBrush(QBrush(penColor)); newSymbol->setSize(6,6); } else { newSymbol->setPen(oldSymbol->pen()); newSymbol->setBrush(oldSymbol->brush()); newSymbol->setSize(oldSymbol->size()); } } return newSymbol; }
void VectorPlot::addDotPlot(const MarkupQwtAdapter&adapter, QColor color, const QString &name, bool addToLegend) { QwtPlotCurve *curve = new QwtPlotCurve(name); QwtSymbol sym; sym.setPen(QColor(color)); sym.setBrush(QColor(color)); sym.setStyle(QwtSymbol::Rect); sym.setSize( QSize(1, 20) ); curve->setSymbol(sym); curve->setStyle(QwtPlotCurve::NoCurve); if(adapter.size() > 0) { setupPlot(adapter.boundingRect()); curve->setData(adapter); curve->attach(plot); } if(!legend) { return; } // Добавляем кривую в легенду QwtLegendItem *item = new QwtLegendItem(0); item->setText(curve->title()); item->setSymbol(sym); item->setIdentifierMode(QwtLegendItem::ShowLine | QwtLegendItem::ShowSymbol | QwtLegendItem::ShowText); legend->insert(curve, item); }
void PfPvPlot::configChanged() { setCanvasBackground(GColor(CPLOTBACKGROUND)); // frame with inverse of background QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Ellipse); sym->setSize(4); sym->setPen(QPen(Qt::red)); sym->setBrush(QBrush(Qt::red)); curve->setSymbol(sym); curve->setStyle(QwtPlotCurve::Dots); curve->setRenderHint(QwtPlotItem::RenderAntialiased); QPalette palette; palette.setBrush(QPalette::Window, QBrush(GColor(CPLOTBACKGROUND))); palette.setColor(QPalette::WindowText, GColor(CPLOTMARKER)); palette.setColor(QPalette::Text, GColor(CPLOTMARKER)); setPalette(palette); axisWidget(QwtPlot::xBottom)->setPalette(palette); axisWidget(QwtPlot::yLeft)->setPalette(palette); // use grid line color for mX, mY and CPcurve QPen marker = GColor(CPLOTMARKER); QPen cp = GColor(CCP); mX->setLinePen(marker); mY->setLinePen(marker); cpCurve->setPen(cp); setCL(appsettings->value(this, GC_CRANKLENGTH).toDouble() / 1000.0); replot(); }
// Hightlight the selected point void CanvasPicker::showCursor( bool showIt ) { if ( !d_selectedCurve ) return; QwtSymbol *symbol = const_cast<QwtSymbol *>( d_selectedCurve->symbol() ); const QBrush brush = symbol->brush(); if ( showIt ) symbol->setBrush( symbol->brush().color().dark( 180 ) ); QwtPlotDirectPainter directPainter; directPainter.drawSeries( d_selectedCurve, d_selectedPoint, d_selectedPoint ); if ( showIt ) symbol->setBrush( brush ); // reset brush }
void PlotIterPath::setGrayPen() { QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setBrush(QBrush(Qt::gray)); sym.setPen(QPen(Qt::black, 1)); sym.setSize(10); iterPathPlot_.setSymbol(sym); iterPathPlot_.setPen(QPen(Qt::black, 3)); sym.setBrush(QBrush(Qt::red)); sym.setPen(QPen(Qt::red, 1)); sym.setSize(10); selectedIteratePlot_.setSymbol(sym); selectedLinePlot_.setPen(QPen(Qt::red, 3)); }
void PlotIterPath::setColorPen(const QColor &color) { QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setBrush(QBrush(color)); sym.setPen(QPen(color, 1)); sym.setSize(10); iterPathPlot_.setSymbol(sym); iterPathPlot_.setPen(QPen(color, 3)); sym.setBrush(QBrush(Qt::red)); sym.setPen(QPen(Qt::red, 1)); sym.setSize(10); selectedIteratePlot_.setSymbol(sym); selectedLinePlot_.setPen(QPen(Qt::red, 3)); }
SegmentInfo::SegmentInfo(const BinaryImageTreeItem *s): gammaStartIndex(0), gammaEndIndex(0), segment(s), arterySegment(NULL), sampleCurve(s->getName()), gammaCurve(s->getName()+ QObject::tr(" Gamma Fit")), patlakCurve(s->getName()), patlakRegression(s->getName() + QObject::tr(" linear Regression")), patlakCreated(false) { //get color of the segment QColor color = s->getColor(); //set color to the curve sampleCurve.setPen(QPen(color)); sampleCurve.setRenderHint(QwtPlotItem::RenderAntialiased, true); QwtSymbol symbol; //class for drawing symbols symbol.setStyle( QwtSymbol::Ellipse ); symbol.setSize(8); symbol.setPen(QPen(color)); symbol.setBrush(QBrush(color.darker(130))); //set the symbol to the curve sampleCurve.setSymbol( symbol ); //initialize curve data sampleCurve.setData( TimeDensityData() ); //create pen for gamma curve with dotted line QPen pen(color); pen.setStyle(Qt::DotLine); //set pen to gamma curve gammaCurve.setPen(pen); gammaCurve.setRenderHint(QwtPlotItem::RenderAntialiased, true); //initialize gamma curve data and hide it gammaCurve.setData( GammaFitData() ); gammaCurve.setVisible(false); //set style of the patlak curve patlakCurve.setRenderHint(QwtPlotItem::RenderAntialiased, true); patlakCurve.setStyle(QwtPlotCurve::NoCurve); symbol.setStyle( QwtSymbol::XCross ); symbol.setSize(8); symbol.setPen(QPen(color)); symbol.setBrush(QBrush(color.darker(130))); patlakCurve.setSymbol( symbol ); patlakRegression.setRenderHint(QwtPlotItem::RenderAntialiased, true); }
PlotIterPath::PlotIterPath(QwtPlot *parent) : parent_(parent) { QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setBrush(QBrush(Qt::gray)); sym.setPen(QPen(Qt::black, 1)); sym.setSize(10); iterPathPlot_.setSymbol(sym); iterPathPlot_.setPen(QPen(Qt::black, 3)); sym.setStyle(QwtSymbol::Ellipse); sym.setBrush(QBrush(Qt::red)); sym.setPen(QPen(Qt::red, 1)); sym.setSize(10); selectedIteratePlot_.setSymbol(sym); selectedLinePlot_.setPen(QPen(Qt::red, 3)); iterPathPlot_.attach(parent_); selectedIteratePlot_.attach(parent_); selectedLinePlot_.attach(parent_); }
void specCanvasItem::setSymbolBrushColor(const QColor& newColor) { if(oldSymbol) { QBrush brush(oldSymbol->brush()) ; brush.setColor(newColor) ; oldSymbol->setBrush(brush) ; } else { QwtSymbol* newSymbol = symbol() ? cloneSymbol(symbol()) : (new QwtSymbol) ; newSymbol->setBrush(newColor) ; setSymbol(newSymbol) ; } }
void PlotPropertiesGUI::symbolSizeValue(int value) { QwtPlotCurve *plotCurve = internalCurves.value(currentCurve)->plotCurve; // Changes only the symbol width QwtSymbol symbol = plotCurve->symbol(); symbol.setStyle((QwtSymbol::Style) (ui->curveSymbolCombo->currentIndex() - 1)); // starts in -1 if (symbol.brush().style() != Qt::NoBrush) symbol.setBrush(QBrush(plotCurve->pen().color())); symbol.setSize(value); plotCurve->setSymbol(symbol); plotter->replot(); }
PfPvPlot::PfPvPlot() : rideItem (NULL), cp_ (0), cad_ (85), cl_ (0.175), shade_zones(true) { setCanvasBackground(Qt::white); setAxisTitle(yLeft, "Average Effective Pedal Force (N)"); setAxisScale(yLeft, 0, 600); setAxisTitle(xBottom, "Circumferential Pedal Velocity (m/s)"); setAxisScale(xBottom, 0, 3); mX = new QwtPlotMarker(); mX->setLineStyle(QwtPlotMarker::VLine); mX->attach(this); mY = new QwtPlotMarker(); mY->setLineStyle(QwtPlotMarker::HLine); mY->attach(this); cpCurve = new QwtPlotCurve(); cpCurve->setRenderHint(QwtPlotItem::RenderAntialiased); cpCurve->attach(this); curve = new QwtPlotCurve(); QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setSize(6); sym.setPen(QPen(Qt::red)); sym.setBrush(QBrush(Qt::NoBrush)); curve->setSymbol(sym); curve->setStyle(QwtPlotCurve::Dots); curve->setRenderHint(QwtPlotItem::RenderAntialiased); curve->attach(this); boost::shared_ptr<QSettings> settings = GetApplicationSettings(); cl_ = settings->value(GC_CRANKLENGTH).toDouble() / 1000.0; recalc(); }
void IncrementalPlot::appendData(double *x, double *y, int size) { if (d_data == NULL) d_data = new CurveData; if (d_curve == NULL) { d_curve = new QwtPlotCurve("Data"); d_curve->setStyle(QwtPlotCurve::NoCurve); d_curve->setPaintAttribute(QwtPlotCurve::FilterPoints, true); const QColor &c = Qt::white; QwtSymbol *symbol = new QwtSymbol(QwtSymbol::Ellipse); symbol->setBrush(QBrush(c)); symbol->setPen(QPen(c)); symbol->setSize(QSize(6, 6)); d_curve->setSymbol(symbol); d_curve->attach(this); } d_data->append(x, y, size); d_curve->setRawSamples(d_data->x(), d_data->y(), d_data->count()); #ifdef __GNUC__ #warning better use QwtData #endif const bool cacheMode = qobject_cast<QwtPlotCanvas *>(canvas())->testPaintAttribute(QwtPlotCanvas::BackingStore); #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent // works on X11. This has an tremendous effect on the performance.. canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); #endif QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>(canvas()); plotCanvas->setPaintAttribute(QwtPlotCanvas::BackingStore, false); QPainter painter; QwtScaleMap xMap = plotCanvas->plot()->canvasMap(d_curve->xAxis()); QwtScaleMap yMap = plotCanvas->plot()->canvasMap(d_curve->yAxis()); d_curve->drawSeries(&painter, xMap, yMap, (d_curve->paintRect(xMap, yMap)), d_curve->dataSize() - size, d_curve->dataSize() -1); plotCanvas->setPaintAttribute(QwtPlotCanvas::BackingStore, cacheMode); #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false); #endif }
void PfPvPlot::configChanged() { setCanvasBackground(GColor(CPLOTBACKGROUND)); // frame with inverse of background QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setSize(6); sym.setPen(GCColor::invert(GColor(CPLOTBACKGROUND))); sym.setBrush(QBrush(Qt::NoBrush)); curve->setSymbol(new QwtSymbol(sym)); curve->setStyle(QwtPlotCurve::Dots); curve->setRenderHint(QwtPlotItem::RenderAntialiased); // use grid line color for mX, mY and CPcurve QPen marker = GColor(CPLOTMARKER); QPen cp = GColor(CCP); mX->setLinePen(marker); mY->setLinePen(marker); cpCurve->setPen(cp); setCL(appsettings->value(this, GC_CRANKLENGTH).toDouble() / 1000.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 ScatterPlot::setData (ScatterSettings *settings) { // get application settings cranklength = appsettings->value(this, GC_CRANKLENGTH, 0.0).toDouble() / 1000.0; // if there are no settings or incomplete settings // create a null data plot if (settings == NULL || settings->ride == NULL || settings->ride->ride() == NULL || settings->x == 0 || settings->y == 0 ) { return; } // if its not setup or no settings exist default to 175mm cranks if (cranklength == 0.0) cranklength = 0.175; // // Create Main Plot dataset - used to frame intervals // int points=0; x.clear(); y.clear(); x.resize(settings->ride->ride()->dataPoints().count()); y.resize(settings->ride->ride()->dataPoints().count()); double maxY = maxX = -65535; double minY = minX = 65535; foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) { double xv = x[points] = pointType(point, settings->x, context->athlete->useMetricUnits, cranklength); double yv = y[points] = pointType(point, settings->y, context->athlete->useMetricUnits, cranklength); // skip zeroes? if (!(settings->ignore && (x[points] == 0 || y[points] == 0))) { points++; if (yv > maxY) maxY = yv; if (yv < minY) minY = yv; if (xv > maxX) maxX = xv; if (xv < minX) minX = xv; } } QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setSize(6); sym.setPen(GCColor::invert(GColor(CPLOTBACKGROUND))); sym.setBrush(QBrush(Qt::NoBrush)); QPen p; p.setColor(GColor(CPLOTSYMBOL)); sym.setPen(p); // wipe away existing if (all) { all->detach(); delete all; } // setup the framing curve if (settings->frame) { all = new QwtPlotCurve(); all->setSymbol(new QwtSymbol(sym)); all->setStyle(QwtPlotCurve::Dots); all->setRenderHint(QwtPlotItem::RenderAntialiased); all->setData(x.constData(), y.constData(), points); all->attach(this); } else { all = NULL; } QPen gridPen(GColor(CPLOTGRID)); gridPen.setStyle(Qt::DotLine); if (grid) { grid->detach(); delete grid; } if (settings->gridlines) { grid = new QwtPlotGrid(); grid->setPen(gridPen); grid->enableX(true); grid->enableY(true); grid->attach(this); } else { grid = NULL; } setAxisTitle(yLeft, describeType(settings->y, true, useMetricUnits)); setAxisTitle(xBottom, describeType(settings->x, true, useMetricUnits)); // truncate PfPv values to make easier to read if (settings->y == MODEL_AEPF) setAxisScale(yLeft, 0, 600); else setAxisScale(yLeft, minY, maxY); if (settings->x == MODEL_CPV) setAxisScale(xBottom, 0, 3); else setAxisScale(xBottom, minX, maxX); // // Create Interval Plot dataset - used to frame intervals // // clear out any interval curves which are presently defined if (intervalCurves.size()) { QListIterator<QwtPlotCurve *> i(intervalCurves); while (i.hasNext()) { QwtPlotCurve *curve = i.next(); curve->detach(); delete curve; } } intervalCurves.clear(); // which ones are highlighted then? QVector<int> intervals; QMap<int,int> displaySequence; for (int child=0; child<context->athlete->allIntervalItems()->childCount(); child++) { IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(child)); if ((current != NULL) && current->isSelected()) { intervals.append(child); displaySequence.insert(current->displaySequence, intervals.count()-1); } } if (intervals.count() > 0) { // interval data in here QVector<QVector<double> > xvals(intervals.count()); // array of curve x arrays QVector<QVector<double> > yvals(intervals.count()); // array of curve x arrays QVector<int> points(intervals.count()); // points in eac curve // extract interval data foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) { double x = pointType(point, settings->x, useMetricUnits, cranklength); double y = pointType(point, settings->y, useMetricUnits, cranklength); if (!(settings->ignore && (x == 0 && y ==0))) { // which interval is it in? for (int idx=0; idx<intervals.count(); idx++) { IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(intervals[idx])); if (point->secs+settings->ride->ride()->recIntSecs() > current->start && point->secs< current->stop) { xvals[idx].append(x); yvals[idx].append(y); points[idx]++; } } } } // now we have the interval data lets create the curves QMapIterator<int, int> order(displaySequence); while (order.hasNext()) { order.next(); int idx = order.value(); QPen pen; QColor intervalColor; intervalColor.setHsv((255/context->athlete->allIntervalItems()->childCount()) * (intervals[idx]), 255,255); pen.setColor(intervalColor); sym.setPen(pen); QwtPlotCurve *curve = new QwtPlotCurve(); curve->setSymbol(new QwtSymbol(sym)); curve->setStyle(QwtPlotCurve::Dots); curve->setRenderHint(QwtPlotItem::RenderAntialiased); curve->setData(xvals[idx].constData(), yvals[idx].constData(), points[idx]); curve->attach(this); intervalCurves.append(curve); } }
void ComponentPlotter::plot(bool zoom) { qwt_plot_->clear(); if(component_matrix_==NULL||component_matrix_->cols()==0) calculateComponents(); if(component_matrix_==NULL||component_matrix_->cols()<2) return; // only 1 component double min_y=1e10; double max_y=-1e10; double min_x=1e10; double max_x=-1e10; const vector<string>* feature_names; if(!plot_loadings_) feature_names = model_item_->model()->getSubstanceNames(); else feature_names = model_item_->model()->getDescriptorNames(); const unsigned int size = feature_names->size(); unsigned int comp_one=component_one_combobox_->itemData(component_one_combobox_->currentIndex()).toInt(); unsigned int comp_two=component_two_combobox_->itemData(component_two_combobox_->currentIndex()).toInt(); QwtLinearColorMap color_map; color_map.setColorInterval(QColor(255,0,0),QColor(0,255,0)); QwtDoubleInterval interval(min_response_value_,max_response_value_); const QSARData* data = model_item_->inputDataItem()->data(); for(unsigned int j=1; j<=size; j++) { QwtPlotMarker* marker= new QwtPlotMarker; QwtSymbol symbol = data_symbol; if(!plot_loadings_) { vector<double>* resp = data->getActivity(j-1); double response_value = (*resp)[selected_activity_]; delete resp; QBrush b(QColor(color_map.rgb(interval,response_value)),Qt::SolidPattern); symbol.setBrush(b); } double x_j = (*component_matrix_)(j,comp_one); double y_j = (*component_matrix_)(j,comp_two); if(y_j<min_y) min_y=y_j; if(y_j>max_y) max_y=y_j; if(x_j<min_x) min_x=x_j; if(x_j>max_x) max_x=x_j; marker->setSymbol(symbol); marker->setValue(x_j,y_j); marker->attach(qwt_plot_); // attached object will be automatically deleted by QwtPlot if(show_data_labels) { QString s =(*feature_names)[j-1].c_str(); QwtText label(s); label.setFont(data_label_font); marker->setLabel(label); marker->setLabelAlignment(data_label_alignment); } } QString s1 = component_one_combobox_->itemText(component_one_combobox_->currentIndex()); QString s2 = component_two_combobox_->itemText(component_two_combobox_->currentIndex()); LatentVariableModel* lv_model = dynamic_cast<LatentVariableModel*>(model_item_->model()); const Eigen::MatrixXd* weights = lv_model->getWeights(); if(!plot_loadings_) { s1 += " c="; s1+=String((*weights)(comp_one,1)).c_str(); s2 += " c="; s2+=String((*weights)(comp_two,1)).c_str(); } qwt_plot_->setAxisTitle(QwtPlot::yLeft,s2); qwt_plot_->setAxisTitle(QwtPlot::xBottom,s1); double x_border=(max_x-min_x)*0.05; double y_border=(max_y-min_y)*0.05; min_x-=x_border; min_y-=y_border; max_x+=x_border; max_y+=y_border; QwtPlotCurve* zero_line = new QwtPlotCurve; QwtPlotCurve* zero_line2 = new QwtPlotCurve; double x[2]; x[0]=min_x; x[1]=max_x; double y[2]; y[0]=0; y[1]=0; zero_line->setData(x,y,2); x[0]=0; x[1]=0; y[0]=min_y; y[1]=max_y; zero_line2->setData(x,y,2); QColor c(135,135,135); // grey QPen pen(c); zero_line->setPen(pen); zero_line->attach(qwt_plot_); zero_line2->setPen(pen); zero_line2->attach(qwt_plot_); if(zoom) { qwt_plot_->setAxisScale(QwtPlot::yLeft,min_y,max_y); qwt_plot_->setAxisScale(QwtPlot::xBottom,min_x,max_x); } if(!plot_loadings_) { QwtScaleWidget* rightAxis = qwt_plot_->axisWidget(QwtPlot::yRight); rightAxis->setTitle("response value"); rightAxis->setColorBarEnabled(true); rightAxis->setColorMap(interval,color_map); qwt_plot_->setAxisScale(QwtPlot::yRight,min_response_value_,max_response_value_); } }
MainWin::MainWin() { int i; xMap.setScaleInterval(-0.5, 10.5); yMap.setScaleInterval(-1.1, 1.1); // // Frame style // setFrameStyle(QFrame::Box|QFrame::Raised); setLineWidth(2); setMidLineWidth(3); // // Calculate values // for(i=0; i<Size;i++) { xval[i] = double(i) * 10.0 / double(Size - 1); yval[i] = sin(xval[i]) * cos(2.0 * xval[i]); } // // define curve styles // QwtSymbol sym; i = 0; sym.setStyle(QwtSymbol::Cross); sym.setPen(QColor(Qt::black)); sym.setSize(5); crv[i].setSymbol(sym); crv[i].setPen(QColor(Qt::darkGreen)); crv[i].setStyle(QwtPlotCurve::Lines); crv[i].setCurveAttribute(QwtPlotCurve::Fitted); i++; sym.setStyle(QwtSymbol::Ellipse); sym.setPen(QColor(Qt::blue)); sym.setBrush(QColor(Qt::yellow)); sym.setSize(5); crv[i].setSymbol(sym); crv[i].setPen(QColor(Qt::red)); crv[i].setStyle(QwtPlotCurve::Sticks); i++; crv[i].setPen(QColor(Qt::darkBlue)); crv[i].setStyle(QwtPlotCurve::Lines); i++; #if QT_VERSION >= 0x040000 crv[i].setPen(QColor(Qt::darkBlue)); crv[i].setStyle(QwtPlotCurve::Lines); crv[i].setRenderHint(QwtPlotItem::RenderAntialiased); i++; #endif crv[i].setPen(QColor(Qt::darkCyan)); crv[i].setStyle(QwtPlotCurve::Steps); i++; sym.setStyle(QwtSymbol::XCross); sym.setPen(QColor(Qt::darkMagenta)); crv[i].setSymbol(sym); crv[i].setStyle(QwtPlotCurve::NoCurve); i++; // // attach data // for(i=0;i<CurvCnt;i++) crv[i].setRawData(xval,yval,Size); }
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(); }
void ObserverGraphic::setAttributes(const QStringList &attribs, const QStringList &curveTitles, /*const*/ QStringList &legKeys, /*const*/ QStringList &legAttribs) { attribList = attribs; InternalCurve *interCurve = 0; QColor color; int attrSize = attribList.size(); // Ignores the attribute of the x axis if (observerType == TObsGraphic) attrSize--; for (int i = 0; i < attrSize; i++) { interCurve = new InternalCurve(attribList.at(i), plotter); if (interCurve) { if (i < curveTitles.size()) interCurve->plotCurve->setTitle(curveTitles.at(i)); else interCurve->plotCurve->setTitle(QString("$curve %1").arg(i + 1)); internalCurves->insert(attribList.at(i), interCurve); // Sets a random color for the created curve color = QColor::fromHsvF(hueValues[(int)(qrand() % HUE_COUNT)], 1, 1); interCurve->plotCurve->setPen(color); interCurve->plotCurve->setLegendAttribute(QwtPlotCurve::LegendShowLine); int width = 0, style = 0, symbol = 0, colorBar = 0, num = 0, size = 0, penstyle = 0; width = legKeys.indexOf(WIDTH); style = legKeys.indexOf(STYLE); symbol = legKeys.indexOf(SYMBOL); size = legKeys.indexOf(SIZE_); penstyle = legKeys.indexOf(PENSTYLE); colorBar = legKeys.indexOf(COLOR_BAR); if ((!legAttribs.isEmpty()) && (colorBar > -1)) { QString aux; QStringList colorStrList; QPen pen; aux = legAttribs.at(colorBar).mid(0, legAttribs.at(colorBar).indexOf(COLOR_BAR_SEP)); colorStrList = aux.split(COLORS_SEP, QString::SkipEmptyParts) .first().split(ITEM_SEP).first().split(COMP_COLOR_SEP); // Retrieves the last colorBar value // colorStrList = aux.split(COLORS_SEP, QString::SkipEmptyParts) // .last().split(ITEM_SEP).first().split(COMP_COLOR_SEP); // color color.setRed(colorStrList.at(0).toInt()); color.setGreen(colorStrList.at(1).toInt()); color.setBlue(colorStrList.at(2).toInt()); // width num = legAttribs.at(width).toInt(); pen = QPen(color); pen.setWidth((num > 0) ? num : 1); interCurve->plotCurve->setPen(pen); // pen num = legAttribs.at(penstyle).toInt(); pen.setStyle((Qt::PenStyle) num); interCurve->plotCurve->setPen(pen); // style num = legAttribs.at(style).toInt(); interCurve->plotCurve->setStyle((QwtPlotCurve::CurveStyle) num); // symbol num = legAttribs.at(symbol).toInt(); QwtSymbol* qwtSymbol = new QwtSymbol; qwtSymbol->setStyle((QwtSymbol::Style) num); qwtSymbol->setPen(pen); if ((QwtSymbol::Style) num !=(QwtSymbol::Style) -1) { interCurve->plotCurve->setLegendAttribute(QwtPlotCurve::LegendShowSymbol); } //size num = legAttribs.at(size).toInt(); qwtSymbol->setSize(num); if (qwtSymbol->brush().style() != Qt::NoBrush) qwtSymbol->setBrush(pen.color()); interCurve->plotCurve->setSymbol(qwtSymbol); for (int j = 0; j < LEGEND_ITENS; j++) { legKeys.removeFirst(); legAttribs.removeFirst(); } } } else { if (execModes != Quiet) qWarning("%s", qPrintable(TerraMEObserver::MEMORY_ALLOC_FAILED)); } } plotter->setInternalCurves(internalCurves->values()); }
void PfPvPlot::setData(RideItem *_rideItem) { // clear out any interval curves which are presently defined if (intervalCurves.size()) { QListIterator<QwtPlotCurve *> i(intervalCurves); while (i.hasNext()) { QwtPlotCurve *curve = i.next(); curve->detach(); delete curve; } } intervalCurves.clear(); rideItem = _rideItem; RideFile *ride = rideItem->ride(); if (ride) { // quickly erase old data curve->setVisible(false); // due to the discrete power and cadence values returned by the // power meter, there will very likely be many duplicate values. // Rather than pass them all to the curve, use a set to strip // out duplicates. std::set<std::pair<double, double> > dataSet; std::set<std::pair<double, double> > dataSetSelected; long tot_cad = 0; long tot_cad_points = 0; foreach(const RideFilePoint *p1, ride->dataPoints()) { if (p1->watts != 0 && p1->cad != 0) { double aepf = (p1->watts * 60.0) / (p1->cad * cl_ * 2.0 * PI); double cpv = (p1->cad * cl_ * 2.0 * PI) / 60.0; if (aepf <= 2500) { // > 2500 newtons is our out of bounds dataSet.insert(std::make_pair<double, double>(aepf, cpv)); tot_cad += p1->cad; tot_cad_points++; } } } setCAD(tot_cad_points ? tot_cad / tot_cad_points : 0); if (tot_cad_points == 0) { //setTitle(tr("no cadence")); refreshZoneItems(); curve->setVisible(false); } else { // Now that we have the set of points, transform them into the // QwtArrays needed to set the curve's data. QwtArray<double> aepfArray; QwtArray<double> cpvArray; std::set<std::pair<double, double> >::const_iterator j(dataSet.begin()); while (j != dataSet.end()) { const std::pair<double, double>& dataPoint = *j; aepfArray.push_back(dataPoint.first); cpvArray.push_back(dataPoint.second); ++j; } curve->setData(cpvArray, aepfArray); QwtSymbol sym; sym.setStyle(QwtSymbol::Ellipse); sym.setSize(6); sym.setBrush(QBrush(Qt::NoBrush)); // now show the data (zone shading would already be visible) refreshZoneItems(); curve->setVisible(true); } } else {
void PlotCurve::restoreCurveLayout(const QStringList& lst) { QStringList::const_iterator line = lst.begin(); for (line = lst.begin(); line != lst.end(); line++) { QString s = (*line).stripWhiteSpace(); if (s == "<Pen>") { QPen pen; pen.setCosmetic(true); while(s != "</Pen>") { s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Alpha>")) { QColor c = pen.color(); c.setAlpha(s.remove("<Alpha>").remove("</Alpha>").toInt()); pen.setColor(c); } else if (s.contains("<Style>")) pen.setStyle(Graph::getPenStyle(s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Width>")) pen.setWidthF(s.remove("<Width>").remove("</Width>").toDouble()); } setPen(pen); } else if (s == "<Brush>") { QBrush brush; while(s != "</Brush>") { s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Alpha>")) { QColor c = brush.color(); c.setAlpha(s.remove("<Alpha>").remove("</Alpha>").toInt()); brush.setColor(c); } else if (s.contains("<Style>")) brush.setStyle(PatternBox::brushStyle(s.remove("<Style>").remove("</Style>").toInt())); } setBrush(brush); } else if (s == "<Symbol>") { QwtSymbol symbol; while(s != "</Symbol>") { s = (*(++line)).stripWhiteSpace(); if (s.contains("<Style>")) symbol.setStyle(SymbolBox::style(s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Size>")) symbol.setSize((QwtSymbol::Style)s.remove("<Size>").remove("</Size>").toInt()); else if (s == "<SymbolPen>") { QPen pen; while(s != "</SymbolPen>") { s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Alpha>")) { QColor c = pen.color(); c.setAlpha(s.remove("<Alpha>").remove("</Alpha>").toInt()); pen.setColor(c); } else if (s.contains("<Style>")) pen.setStyle(Graph::getPenStyle(s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Width>")) pen.setWidthF(s.remove("<Width>").remove("</Width>").toDouble()); } pen.setCosmetic(true); symbol.setPen(pen); } else if (s == "<SymbolBrush>") { QBrush brush; while(s != "</SymbolBrush>") { s = (*(++line)).stripWhiteSpace(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Alpha>")) { QColor c = brush.color(); c.setAlpha(s.remove("<Alpha>").remove("</Alpha>").toInt()); brush.setColor(c); } else if (s.contains("<Style>")) brush.setStyle(PatternBox::brushStyle(s.remove("<Style>").remove("</Style>").toInt())); } symbol.setBrush(brush); } setSymbol(symbol); } } else if (s.contains("<xAxis>")) setXAxis(s.remove("<xAxis>").remove("</xAxis>").toInt()); else if (s.contains("<yAxis>")) setYAxis(s.remove("<yAxis>").remove("</yAxis>").toInt()); else if (s.contains("<CurveType>")) setCurveType((QwtPlotCurve::CurveType)s.remove("<CurveType>").remove("</CurveType>").toInt()); else if (s.contains("<Visible>")) setVisible(s.remove("<Visible>").remove("</Visible>").toInt()); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPvtPlotWidget::updateTrackerPlotMarkerAndLabelFromPicker() { bool hasValidSamplePoint = false; QPointF samplePoint; QString mixRatioText = ""; double mixRat = HUGE_VAL; if (m_qwtPicker && m_qwtPicker->isActive()) { const QPoint trackerPos = m_qwtPicker->trackerPosition(); int pointSampleIdx = -1; const QwtPlotCurve* closestQwtCurve = closestCurveSample(trackerPos, &pointSampleIdx); if (closestQwtCurve && pointSampleIdx >= 0) { samplePoint = closestQwtCurve->sample(pointSampleIdx); hasValidSamplePoint = true; size_t curveIdx = indexOfQwtCurve(closestQwtCurve); if (curveIdx < m_pvtCurveArr.size()) { const RigFlowDiagSolverInterface::PvtCurve& pvtCurve = m_pvtCurveArr[curveIdx]; if (static_cast<size_t>(pointSampleIdx) < pvtCurve.mixRatVals.size()) { mixRat = pvtCurve.mixRatVals[pointSampleIdx]; // The text is Rs or Rv depending on phase mixRatioText = (pvtCurve.phase == RigFlowDiagSolverInterface::PvtCurve::GAS) ? "Rv" : "Rs"; } } } } m_trackerLabel = ""; bool needsReplot = false; if (hasValidSamplePoint) { if (!m_trackerPlotMarker) { m_trackerPlotMarker = new QwtPlotMarker; QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Ellipse); symbol->setSize(13, 13); symbol->setPen(QPen(QColor(0, 0, 0), 2)); symbol->setBrush(Qt::NoBrush); m_trackerPlotMarker->setSymbol(symbol); m_trackerPlotMarker->attach(m_qwtPlot); needsReplot = true; } if (m_trackerPlotMarker->value() != samplePoint) { m_trackerPlotMarker->setValue(samplePoint); needsReplot = true; } m_trackerLabel = QString("%1 (%2)").arg(samplePoint.y()).arg(samplePoint.x()); if (mixRat != HUGE_VAL) { m_trackerLabel += QString("\n%1 = %2").arg(mixRatioText).arg(mixRat); } } else { if (m_trackerPlotMarker) { m_trackerPlotMarker->detach(); delete m_trackerPlotMarker; m_trackerPlotMarker = nullptr; needsReplot = true; } } if (needsReplot) { m_qwtPlot->replot(); } }
// We are going to support multiple models; normal, normal-skew, linear // So for now lets make it a parameter for the model curve creation // The model may end up being comprised of 'sub models' for each fibre type void MUPlot::setModel(int model) { this->model = model; // first lets clear any curves we shouldn't be displaying // no model curve if not power ! if (modelCurve) { modelCurve->detach(); delete modelCurve; modelCurve = NULL; } if (slowCurve) { slowCurve->detach(); delete slowCurve; slowCurve = NULL; } if (slowHandle) { slowHandle->detach(); delete slowHandle; slowHandle = NULL; } if (slowLine) { slowLine->detach(); delete slowLine; slowLine = NULL; } if (fastCurve) { fastCurve->detach(); delete fastCurve; fastCurve = NULL; } if (fastHandle) { fastHandle->detach(); delete fastHandle; fastHandle = NULL; } if (fastLine) { fastLine->detach(); delete fastLine; fastLine = NULL; } if (mmpCurve) { mmpCurve->detach(); delete mmpCurve; mmpCurve = NULL; } switch (model) { case 0 : // no model - do nothing { } break; case 2 : // 2 Normal distribution -- drops through to case 1 below { fastCurve = new QwtPlotCurve( "MU Distribution" ); fastCurve->setData(fastNormal = new MUNormal(MU_FASTMEAN, 0.05f)); fastCurve->attach(this); QColor handleColor = QColor(Qt::magenta).darker(30); // customise (?) handleColor.setAlpha(64); // now a mean line fastLine = new QwtPlotMarker(); fastLine->setLineStyle(QwtPlotMarker::VLine); fastLine->setLinePen(QPen(QColor(handleColor), 0, Qt::SolidLine)); fastLine->setValue(MU_FASTMEAN, 0); // mean fastLine->setZ(50); fastLine->attach(this); // now add a handle QColor color = GColor(CPLOTBACKGROUND); double x = MU_FASTMEAN; // mean is ok double y = 0.05f * 40.0f; // variance scaled to w(x) QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Rect); sym->setSize(8 *dpiXFactor); sym->setPen(QPen(handleColor)); // customise ? sym->setBrush(QBrush(color)); fastHandle = new QwtPlotMarker(); fastHandle->setValue(x, y); fastHandle->setYAxis(yLeft); fastHandle->setZ(100); fastHandle->setSymbol(sym); fastHandle->attach(this); } // intentional fallthrough case 1 : // Normal distribution { slowCurve = new QwtPlotCurve( "MU Distribution" ); slowCurve->setData(slowNormal = new MUNormal(MU_SLOWMEAN, 0.05f)); slowCurve->attach(this); QColor handleColor = GColor(CCP).darker(30); handleColor.setAlpha(64); // now a mean line slowLine = new QwtPlotMarker(); slowLine->setLineStyle(QwtPlotMarker::VLine); slowLine->setLinePen(QPen(QColor(handleColor), 0, Qt::SolidLine)); slowLine->setValue(MU_SLOWMEAN, 0); // mean slowLine->setZ(50); slowLine->attach(this); // now add a handle QColor color = GColor(CPLOTBACKGROUND); double x = MU_SLOWMEAN; // mean is ok double y = 0.05f * 40.0f; // variance scaled to w(x) QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Rect); sym->setSize(8 *dpiXFactor); sym->setPen(QPen(handleColor)); // customise ? sym->setBrush(QBrush(color)); slowHandle = new QwtPlotMarker(); slowHandle->setValue(x, y); slowHandle->setYAxis(yLeft); slowHandle->setZ(100); slowHandle->setSymbol(sym); slowHandle->attach(this); // mmp curve mmpCurve = new QwtPlotCurve( "MU Distribution" ); mmpCurve->attach(parent->cpPlot); } break; } // set the colors etc for our curve(s) if (fastCurve) { // antialias bool antialias = appsettings->value(this, GC_ANTIALIAS, false).toBool(); if (antialias) fastCurve->setRenderHint(QwtPlotItem::RenderAntialiased); // color and brush QColor color = QColor(Qt::magenta); //XXX customise QPen pen(color); pen.setWidth(1.0); color.setAlpha(80); QBrush brush(color); fastCurve->setPen(pen); fastCurve->setBrush(brush); } if (slowCurve) { // antialias bool antialias = appsettings->value(this, GC_ANTIALIAS, false).toBool(); if (antialias) slowCurve->setRenderHint(QwtPlotItem::RenderAntialiased); // color and brush QColor color = GColor(CCP); // customise ? QPen pen(color); pen.setWidth(1.0); color.setAlpha(80); QBrush brush(color); slowCurve->setPen(pen); slowCurve->setBrush(brush); QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Ellipse); sym->setSize(4 *dpiXFactor); sym->setPen(QPen(Qt::yellow)); // customise ? sym->setBrush(QBrush(Qt::yellow)); mmpCurve->setPen(QPen(Qt::yellow)); mmpCurve->setSymbol(sym); mmpCurve->setBrush(Qt::NoBrush); // and refresh the MMP setMUSet(); } if (model) { modelCurve = new QwtPlotCurve( "Total Distribution" ); modelCurve->setData(this); // we provide the data too! QColor color = QColor(Qt::yellow); //XXX customise QPen pen(color); pen.setWidth(1.0); color.setAlpha(80); modelCurve->setPen(pen); modelCurve->setBrush(Qt::NoBrush); modelCurve->attach(this); } replot(); }
/*! 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); }
void QcepPlot::setPlotCurveStyle(int index, QwtPlotCurve *curve) { const int nColors = 10; const int nSymbols = 4; const int nStyles = 3; int colorIndex = index % nColors; int symbolIndex = (index / nColors) % nSymbols; int styleIndex = (index / (nColors * nSymbols)) % nStyles; QPen pen; QwtSymbol *symb = new QwtSymbol(); QBrush brush; switch (colorIndex) { case 0: pen = QPen(QColor(255,0,0)); // red break; case 1: pen = QPen(QColor(255,170,0)); // Orange break; case 2: pen = QPen(QColor(255,232,137)); // Yellow break; case 3: pen = QPen(QColor(0,255,0)); // Green break; case 4: pen = QPen(QColor(0,170,0)); // Dk green break; case 5: pen = QPen(QColor(0,255,255)); // Cyan break; case 6: pen = QPen(QColor(0,170,255)); // Sea blue break; case 7: pen = QPen(QColor(0,0,255)); // Blue break; case 8: pen = QPen(QColor(145,0,255)); // Violet break; case 9: pen = QPen(QColor(255,0,255)); // Magenta break; } switch (styleIndex) { case 0: pen.setStyle(Qt::SolidLine); break; case 1: pen.setStyle(Qt::DashLine); break; case 2: pen.setStyle(Qt::DotLine); break; case 3: pen.setStyle(Qt::DashDotLine); break; } symb->setPen(pen); symb->setBrush(QBrush(pen.color())); symb->setSize(5,5); switch (symbolIndex) { case 0: symb->setStyle(QwtSymbol::Ellipse); break; case 1: symb->setStyle(QwtSymbol::Rect); break; case 2: symb->setStyle(QwtSymbol::Triangle); break; case 3: symb->setStyle(QwtSymbol::DTriangle); break; } curve -> setPen(pen); curve -> setSymbol(symb); }
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 PlotCurve::restoreCurveLayout(const QStringList &lst) { QStringList::const_iterator line = lst.begin(); for (++line; line != lst.end(); ++line) { QString s = *line; if (s == "<Pen>") { QPen pen; while (s != "</Pen>") { s = (*(++line)).trimmed(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) pen.setStyle(Graph::getPenStyle( s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Width>")) pen.setWidthF(s.remove("<Width>").remove("</Width>").toDouble()); } setPen(pen); } else if (s == "<Brush>") { QBrush brush; while (s != "</Brush>") { s = (*(++line)).trimmed(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) brush.setStyle(PatternBox::brushStyle( s.remove("<Style>").remove("</Style>").toInt())); } setBrush(brush); } else if (s == "<Symbol>") { QwtSymbol symbol; while (s != "</Symbol>") { s = (*(++line)).trimmed(); if (s.contains("<Style>")) symbol.setStyle( SymbolBox::style(s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Size>")) symbol.setSize( (QwtSymbol::Style)s.remove("<Size>").remove("</Size>").toInt()); else if (s == "<SymbolPen>") { QPen pen; while (s != "</SymbolPen>") { s = (*(++line)).trimmed(); if (s.contains("<Color>")) pen.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) pen.setStyle(Graph::getPenStyle( s.remove("<Style>").remove("</Style>").toInt())); else if (s.contains("<Width>")) pen.setWidthF(s.remove("<Width>").remove("</Width>").toDouble()); } symbol.setPen(pen); } else if (s == "<SymbolBrush>") { QBrush brush; while (s != "</SymbolBrush>") { s = (*(++line)).trimmed(); if (s.contains("<Color>")) brush.setColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<Style>")) brush.setStyle(PatternBox::brushStyle( s.remove("<Style>").remove("</Style>").toInt())); } symbol.setBrush(brush); } setSymbol(symbol); } } else if (s.contains("<xAxis>")) setXAxis(s.remove("<xAxis>").remove("</xAxis>").toInt()); else if (s.contains("<yAxis>")) setYAxis(s.remove("<yAxis>").remove("</yAxis>").toInt()); else if (s.contains("<Visible>")) setVisible(s.remove("<Visible>").remove("</Visible>").toInt()); } }
/*! 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); }