void Legend::toggleHide(bool hide) { QList<PlotCurve*> list = mpPlot->getPlotCurvesList(); for(int i = 0; i < list.length(); i++) { if(list[i]->title().text() == mLegendItemStr) { if (hide) { QwtText text = list[i]->title(); text.setColor(QColor(Qt::gray)); list[i]->setTitle(text); list[i]->setVisible(false); } else { QwtText text = list[i]->title(); text.setColor(QColor(Qt::black)); list[i]->setTitle(text.text()); list[i]->setVisible(true); } } } mpPlot->replot(); }
/** * Constructor, creates a new HistogramToolWindow * * @param title * @param parent */ HistogramToolWindow::HistogramToolWindow(QString title,QWidget *parent) : PlotWindow(title, parent) { p_plot->enableAxis(QwtPlot::yRight); QwtText *leftLabel = new QwtText("Frequency", QwtText::PlainText); leftLabel->setColor(Qt::darkCyan); QFont font = leftLabel->font(); font.setPointSize(13); font.setBold(true); leftLabel->setFont(font); p_plot->setAxisTitle(QwtPlot::yLeft, *leftLabel); p_dock = new QDockWidget("Histogram Info",this); p_dock->setAllowedAreas(Qt::AllDockWidgetAreas); p_dock->setFloating(false); p_dock->setObjectName("DockWidget"); p_dock->setMinimumWidth(130); p_mainWindow->addDockWidget(Qt::LeftDockWidgetArea, p_dock, Qt::Vertical); QwtText *rtLabel = new QwtText("Percentage", QwtText::PlainText); rtLabel->setColor(Qt::red); font = rtLabel->font(); font.setPointSize(13); font.setBold(true); rtLabel->setFont(font); p_plot->setAxisTitle(QwtPlot::yRight,*rtLabel); setAxisLabel(QwtPlot::xBottom,"Pixel Value (DN)"); setScale(QwtPlot::yRight,0,100); setPlotBackground(Qt::white); }
void Plot2DProfile::setLegendLine( bool showLegendLine ){ QwtText text = title(); if ( showLegendLine ){ setLegendIconSize(QSize(36,8)); text.setColor( "black"); } else { setLegendIconSize(QSize(0,0)); text.setColor( m_defaultColor ); } setTitle( text ); }
void Spectrogram::createLabels() { clearLabels(); QwtValueList levels = contourLevels(); const int numLevels = levels.size(); for (int l = 0; l < numLevels; l++){ PlotMarker *m = new PlotMarker(l, d_labels_angle); QwtText t = QwtText(QString::number(levels[l])); t.setColor(d_labels_color); t.setFont(d_labels_font); if (d_white_out_labels) t.setBackgroundBrush(QBrush(Qt::white)); else t.setBackgroundBrush(QBrush(Qt::transparent)); m->setLabel(t); int x_axis = xAxis(); int y_axis = yAxis(); m->setAxis(x_axis, y_axis); if (d_graph && d_show_labels) m->attach(d_graph); d_labels_list << m; } }
QwtText CurveTracker::trackerTextF( const QPointF &pos ) const { QwtText trackerText; trackerText.setColor( Qt::black ); QColor c( "#333333" ); trackerText.setBorderPen( QPen( c, 2 ) ); c.setAlpha( 200 ); trackerText.setBackgroundBrush( c ); QString info; const QwtPlotItemList curves = plot()->itemList( QwtPlotItem::Rtti_PlotCurve ); for ( int i = 0; i < curves.size(); i++ ) { const QString curveInfo = curveInfoAt( static_cast<const QwtPlotCurve *>( curves[i] ), pos ); if ( !curveInfo.isEmpty() ) { if ( !info.isEmpty() ) info += "<br>"; info += curveInfo; } } trackerText.setText( info ); return trackerText; }
PfPvPlotZoneLabel(PfPvPlot *_parent, int _zone_number) { parent = _parent; zone_number = _zone_number; RideItem *rideItem = parent->rideItem; const Zones *zones = rideItem->zones; int zone_range = rideItem->zoneRange(); setZ(1.0 + zone_number / 100.0); // create new zone labels if we're shading if (zone_range >= 0) { // retrieve zone setup QList <int> zone_lows = zones->getZoneLows(zone_range); QList <QString> zone_names = zones->getZoneNames(zone_range); int num_zones = zone_lows.size(); assert(zone_names.size() == num_zones); if (zone_number < num_zones) { watts = ((zone_number + 1 < num_zones) ? 0.5 * (zone_lows[zone_number] + zone_lows[zone_number + 1]) : ( (zone_number > 0) ? (1.5 * zone_lows[zone_number] - 0.5 * zone_lows[zone_number - 1]) : 2.0 * zone_lows[zone_number])); text = QwtText(zone_names[zone_number]); text.setFont(QFont("Helvetica",24, QFont::Bold)); QColor text_color = zoneColor(zone_number, num_zones); text_color.setAlpha(64); text.setColor(text_color); } } }
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(); }
PfPvPlotZoneLabel(PfPvPlot *_parent, int _zone_number) { parent = _parent; RideItem *rideItem = parent->rideItem; zone_number = _zone_number; // get zone data from ride or athlete ... const Zones *zones; int zone_range = -1; if (parent->context->isCompareIntervals) { zones = parent->context->athlete->zones(); if (!zones) return; // use first compare interval date if (parent->context->compareIntervals.count()) zone_range = zones->whichRange(parent->context->compareIntervals[0].data->startTime().date()); // still not set if (zone_range == -1) zone_range = zones->whichRange(QDate::currentDate()); } else if (rideItem) { zones = rideItem->zones; zone_range = rideItem->zoneRange(); } else { return; // nulls } setZ(1.0 + zone_number / 100.0); // create new zone labels if we're shading if (zone_range >= 0) { // retrieve zone setup QList <int> zone_lows = zones->getZoneLows(zone_range); QList <QString> zone_names = zones->getZoneNames(zone_range); int num_zones = zone_lows.size(); if(zone_names.size() != num_zones) return; if (zone_number < num_zones) { watts = ((zone_number + 1 < num_zones) ? 0.5 * (zone_lows[zone_number] + zone_lows[zone_number + 1]) : ( (zone_number > 0) ? (1.5 * zone_lows[zone_number] - 0.5 * zone_lows[zone_number - 1]) : 2.0 * zone_lows[zone_number])); text = QwtText(zone_names[zone_number]); text.setFont(QFont("Helvetica",24, QFont::Bold)); QColor text_color = zoneColor(zone_number, num_zones); text_color.setAlpha(64); text.setColor(text_color); } } }
void QwtHistogram::loadLabels() { clearLabels(); int size = this->dataSize(); if (!size) return; QwtPlot *d_plot = plot(); if (!d_plot) return; int index = 0; for (int i = 0; i < size; i++){ PlotMarker *m = new PlotMarker(index, d_labels_angle); QwtText t = QwtText(QString::number(y(i))); t.setColor(d_labels_color); t.setFont(d_labels_font); if (d_white_out_labels) t.setBackgroundBrush(QBrush(Qt::white)); else t.setBackgroundBrush(QBrush(Qt::transparent)); m->setLabel(t); int x_axis = xAxis(); int y_axis = yAxis(); m->setAxis(x_axis, y_axis); QSize size = t.textSize(); int dx = int(d_labels_x_offset*0.01*size.height()); int dy = -int((d_labels_y_offset*0.01 + 0.5)*size.height()); int x2 = d_plot->transform(x_axis, x(index)) + dx; int y2 = d_plot->transform(y_axis, y(index)) + dy; switch(d_labels_align){ case Qt::AlignLeft: break; case Qt::AlignHCenter: x2 -= size.width()/2; break; case Qt::AlignRight: x2 -= size.width(); break; } m->setXValue(d_plot->invTransform(x_axis, x2)); m->setYValue(d_plot->invTransform(y_axis, y2)); m->attach(d_plot); d_labels_list << m; index++; } d_show_labels = true; }
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(); }
Plot::Plot(int width, int height, QWidget *parent, const char *) : QwtPlot(parent) { setAutoReplot (false); marker_key = 0; curve_key = 0; minTickLength = 5; majTickLength = 9; setGeometry(QRect(0, 0, width, height)); setAxisTitle(QwtPlot::yLeft, tr("Y Axis Title")); setAxisTitle(QwtPlot::xBottom, tr("X Axis Title")); //due to the plot layout updates, we must always have a non empty title setAxisTitle(QwtPlot::yRight, tr(" ")); setAxisTitle(QwtPlot::xTop, tr(" ")); // grid d_grid = new Grid(); d_grid->attach(this); //custom scale for (int i= 0; i<QwtPlot::axisCnt; i++) { QwtScaleWidget *scale = (QwtScaleWidget *) axisWidget(i); if (scale) { scale->setMargin(0); //the axis title color must be initialized... QwtText title = scale->title(); title.setColor(Qt::black); scale->setTitle(title); //...same for axis color QPalette pal = scale->palette(); pal.setColor(QPalette::Foreground, QColor(Qt::black)); scale->setPalette(pal); ScaleDraw *sd = new ScaleDraw(this); sd->setTickLength(QwtScaleDiv::MinorTick, minTickLength); sd->setTickLength(QwtScaleDiv::MediumTick, minTickLength); sd->setTickLength(QwtScaleDiv::MajorTick, majTickLength); setAxisScaleDraw (i, sd); setAxisScaleEngine (i, new ScaleEngine()); } } QwtPlotLayout *pLayout = plotLayout(); pLayout->setCanvasMargin(0); pLayout->setAlignCanvasToScales (true); QwtPlotCanvas* plCanvas = canvas(); plCanvas->setFocusPolicy(Qt::StrongFocus); plCanvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator); //plCanvas->setFocus(); plCanvas->setFrameShadow(QwtPlot::Plain); plCanvas->setCursor(Qt::arrowCursor); plCanvas->setLineWidth(0); plCanvas->setPaintAttribute(QwtPlotCanvas::PaintCached, false); plCanvas->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); QColor background = QColor(Qt::white); background.setAlpha(255); QPalette palette; palette.setColor(QPalette::Window, background); setPalette(palette); setCanvasBackground (background); setFocusPolicy(Qt::StrongFocus); //setFocusProxy(plCanvas); setFrameShape(QFrame::Box); setLineWidth(0); }
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 MavPlot::apply_print_colors(bool yes) { if (yes && !_havePrintColors) { const QColor printcol = QColor(0,0,0); // default color: black /******************* * ENABLE PRINT COLS *******************/ // title QwtText plottitle = title(); _col_title_screen = plottitle.color(); plottitle.setColor(printcol); setTitle(plottitle); // all legend entries -> for (dataplotmap::iterator d = _series.begin(); d != _series.end(); ++d) { QWT_ABSTRACT_SERIESITEM * s = d->second; if (!s) continue; if (d == _series.begin()) { _col_legend_screen = s->title().color(); // save color of first legend text } // thicker lines for all QwtPlotCurve * const q = dynamic_cast<QwtPlotCurve * const>(s); if (q) { QPen p = q->pen(); p.setWidth(PLOT_LINE_WIDTH); p.setCosmetic(true); q->setPen(p); } // text of legend -> black QwtText title = s->title(); title.setColor(printcol); s->setTitle(title); } // axes _pal_axis_screen = axisWidget(QwtPlot::xBottom)->palette(); QPalette pal_print; pal_print.setColor(QPalette::WindowText, printcol); pal_print.setColor(QPalette::Text, printcol); axisWidget(QwtPlot::xBottom)->setPalette(pal_print); axisWidget(QwtPlot::yLeft)->setPalette(pal_print); } else { if (_havePrintColors) { /******************* * UNDO *******************/ // title QwtText plottitle = title(); plottitle.setColor(_col_title_screen); setTitle(plottitle); // all legend entries -> for (dataplotmap::iterator d = _series.begin(); d != _series.end(); ++d) { QWT_ABSTRACT_SERIESITEM * s = d->second; if (!s) continue; // thinner lines for all QwtPlotCurve * const q = dynamic_cast<QwtPlotCurve * const>(s); if (q) { QPen p = q->pen(); p.setWidth(1); p.setCosmetic(false); q->setPen(p); } // restore legend text color QwtText title = s->title(); title.setColor(_col_legend_screen); s->setTitle(title); } // axes axisWidget(QwtPlot::xBottom)->setPalette(_pal_axis_screen); axisWidget(QwtPlot::yLeft)->setPalette(_pal_axis_screen); } } _havePrintColors = yes; }
/*! 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); }
void DataCurve::loadLabels() { if (!validCurveType()) return; clearLabels(); int xcol = d_table->colIndex(d_x_column); int ycol = d_table->colIndex(title().text()); int labelsCol = d_table->colIndex(d_labels_column); int cols = d_table->numCols(); if (xcol < 0 || ycol < 0 || labelsCol < 0 || xcol >= cols || ycol >= cols || labelsCol >= cols) return; QwtPlot *d_plot = plot(); if (!d_plot) return; int index = 0; for (int i = d_start_row; i <= d_end_row; i++) { if (d_table->text(i, xcol).isEmpty() || d_table->text(i, ycol).isEmpty()) continue; PlotMarker *m = new PlotMarker(index, d_labels_angle); QwtText t = QwtText(d_table->text(i, labelsCol)); t.setColor(d_labels_color); t.setFont(d_labels_font); if (d_white_out_labels) t.setBackgroundBrush(QBrush(Qt::white)); else t.setBackgroundBrush(QBrush(Qt::transparent)); m->setLabel(t); int x_axis = xAxis(); int y_axis = yAxis(); m->setAxis(x_axis, y_axis); QSize size = t.textSize(); int dx = int(d_labels_x_offset*0.01*size.height()); int dy = -int((d_labels_y_offset*0.01 + 0.5)*size.height()); int x2 = d_plot->transform(x_axis, x(index)) + dx; int y2 = d_plot->transform(y_axis, y(index)) + dy; switch(d_labels_align) { case Qt::AlignLeft: break; case Qt::AlignHCenter: x2 -= size.width()/2; break; case Qt::AlignRight: x2 -= size.width(); break; } m->setXValue(d_plot->invTransform(x_axis, x2)); m->setYValue(d_plot->invTransform(y_axis, y2)); m->attach(d_plot); d_labels_list << m; index++; } d_show_labels = true; }
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; } }
/*! 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); }
Plot::Plot(QWidget *parent, const char *name) : QwtPlot(parent) { marker_key = 0; curve_key = 0; minTickLength = 5; majTickLength = 9; movedGraph=FALSE; graphToResize=FALSE; ShiftButton=FALSE; setGeometry(QRect(0,0,500,400)); setAxisTitle(QwtPlot::yLeft, tr("Y Axis Title")); setAxisTitle(QwtPlot::xBottom, tr("X Axis Title")); // grid d_grid = new Grid; d_grid->enableX(false); d_grid->enableY(false); d_grid->setMajPen(QPen(Qt::blue, 0, Qt::SolidLine)); d_grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); d_grid->attach(this); //custom scale for (int i= 0; i<QwtPlot::axisCnt; i++) { QwtScaleWidget *scale = (QwtScaleWidget *) axisWidget(i); if (scale) { scale->setMargin(0); //the axis title color must be initialized QwtText title = scale->title(); title.setColor(Qt::black); scale->setTitle(title); ScaleDraw *sd = new ScaleDraw(); sd->setTickLength (QwtScaleDiv::MinorTick, minTickLength); sd->setTickLength (QwtScaleDiv::MediumTick, minTickLength); sd->setTickLength (QwtScaleDiv::MajorTick, majTickLength); setAxisScaleDraw (i, sd); } } QwtPlotLayout *pLayout=plotLayout(); pLayout->setCanvasMargin(0); QwtPlotCanvas* plCanvas = canvas(); plCanvas->setFocusPolicy(QWidget::StrongFocus); plCanvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator); plCanvas->setFocus(); plCanvas->setFrameShadow(QwtPlot::Plain); plCanvas->setCursor(Qt::arrowCursor); plCanvas->setLineWidth(0); setFocusPolicy(QWidget::StrongFocus); setFocusProxy(plCanvas); setFrameShape (QFrame::Box); setLineWidth(0); }
void HrPwPlot::recalc() { if (timeArray.count() == 0) return; int rideTimeSecs = (int) ceil(timeArray[arrayLength - 1]); if (rideTimeSecs > SECONDS_IN_A_WEEK) { return; } // ------ smoothing ----- double totalWatts = 0.0; double totalHr = 0.0; QList<DataPoint*> list; int i = 0; QVector<double> smoothWatts(rideTimeSecs + 1); QVector<double> smoothHr(rideTimeSecs + 1); QVector<double> smoothTime(rideTimeSecs + 1); int decal=0; //int interval = 0; int smooth = hrPwWindow->smooth; for (int secs = smooth; secs <= rideTimeSecs; ++secs) { while ((i < arrayLength) && (timeArray[i] <= secs)) { DataPoint *dp = new DataPoint(timeArray[i], hrArray[i], wattsArray[i], interArray[i]); totalWatts += wattsArray[i]; totalHr += hrArray[i]; list.append(dp); ++i; } while (!list.empty() && (list.front()->time < secs - smooth)) { DataPoint *dp = list.front(); list.removeFirst(); totalWatts -= dp->watts; totalHr -= dp->hr; delete dp; } if (list.empty()) ++decal; else { smoothWatts[secs-decal] = totalWatts / list.size(); smoothHr[secs-decal] = totalHr / list.size(); } smoothTime[secs] = secs / 60.0; } // Delete temporary list qDeleteAll(list); list.clear(); rideTimeSecs = rideTimeSecs-decal; smoothWatts.resize(rideTimeSecs); smoothHr.resize(rideTimeSecs); // Clip to max QVector<double> clipWatts(rideTimeSecs); QVector<double> clipHr(rideTimeSecs); decal = 0; for (int secs = 0; secs < rideTimeSecs; ++secs) { if (smoothHr[secs]>= minHr && smoothWatts[secs]>= minWatt && smoothWatts[secs]<maxWatt) { clipWatts[secs-decal] = smoothWatts[secs]; clipHr[secs-decal] = smoothHr[secs]; } else decal ++; } rideTimeSecs = rideTimeSecs-decal; clipWatts.resize(rideTimeSecs); clipHr.resize(rideTimeSecs); // Find Hr Delay if (delay == -1) delay = hrPwWindow->findDelay(clipWatts, clipHr, clipWatts.size()); else if (delay>rideTimeSecs) delay=rideTimeSecs; // Apply delay QVector<double> delayWatts(rideTimeSecs-delay); QVector<double> delayHr(rideTimeSecs-delay); for (int secs = 0; secs < rideTimeSecs-delay; ++secs) { delayWatts[secs] = clipWatts[secs]; delayHr[secs] = clipHr[secs+delay]; } rideTimeSecs = rideTimeSecs-delay; double rslope = hrPwWindow->slope(delayWatts, delayHr, delayWatts.size()); double rintercept = hrPwWindow->intercept(delayWatts, delayHr, delayWatts.size()); double maxr = hrPwWindow->corr(delayWatts, delayHr, delayWatts.size()); // ----- limit plotted points --- int intpoints = 10; // could be ride length dependent int nbpoints = (int)floor(rideTimeSecs/intpoints); QVector<double> plotedWatts(nbpoints); QVector<double> plotedHr(nbpoints); for (int secs = 0; secs < nbpoints; ++secs) { plotedWatts[secs] = clipWatts[secs*intpoints]; plotedHr[secs] = clipHr[secs*intpoints]; } int nbpoints2 = (int)floor(nbpoints/36)+2; double *plotedWattsArray[36]; double *plotedHrArray[36]; for (int i = 0; i < 36; ++i) { plotedWattsArray[i]= new double[nbpoints2]; plotedHrArray[i]= new double[nbpoints2]; } for (int secs = 0; secs < nbpoints; ++secs) { for (int i = 0; i < 36; ++i) { if (secs >= i*nbpoints2 && secs< (i+1)*nbpoints2) { plotedWattsArray[i][secs-i*nbpoints2] = plotedWatts[secs-i]; plotedHrArray[i][secs-i*nbpoints2] = plotedHr[secs-i]; } } } for (int i = 0; i < 36; ++i) { if (nbpoints-i*nbpoints2>0) { hrCurves[i]->setSamples(plotedWattsArray[i], plotedHrArray[i], (nbpoints-i*nbpoints2<nbpoints2?nbpoints-i*nbpoints2:nbpoints2)); hrCurves[i]->setVisible(true); } else hrCurves[i]->setVisible(false); } // Clean up memory for (int i = 0; i < 36; ++i) { delete plotedWattsArray[i]; delete plotedHrArray[i]; } setAxisScale(xBottom, 0.0, maxWatt); setYMax(); refreshZoneLabels(); QString labelp; labelp.setNum(rslope, 'f', 3); QString labelo; labelo.setNum(rintercept, 'f', 1); QString labelr; labelr.setNum(maxr, 'f', 3); QString labeldelay; labeldelay.setNum(delay); int power150 = (int)floor((150-rintercept)/rslope); QString labelpower150; labelpower150.setNum(power150); QwtText textr = QwtText(labelp+"*x+"+labelo+" : R "+labelr+" ("+labeldelay+") \n Power@150:"+labelpower150+"W"); textr.setFont(QFont("Helvetica", 10, QFont::Bold)); textr.setColor(GColor(CPLOTMARKER)); r_mrk1->setValue(0,0); r_mrk1->setLineStyle(QwtPlotMarker::VLine); r_mrk1->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom); r_mrk1->setLinePen(QPen(GColor(CPLOTMARKER), 0, Qt::DashDotLine)); double averagewatt = hrPwWindow->average(clipWatts, clipWatts.size()); r_mrk1->setValue(averagewatt, 0.0); r_mrk1->setLabel(textr); r_mrk2->setValue(0,0); r_mrk2->setLineStyle(QwtPlotMarker::HLine); r_mrk2->setLabelAlignment(Qt::AlignRight | Qt::AlignTop); r_mrk2->setLinePen(QPen(GColor(CPLOTMARKER), 0, Qt::DashDotLine)); double averagehr = hrPwWindow->average(clipHr, clipHr.size()); r_mrk2->setValue(0.0,averagehr); addWattStepCurve(clipWatts, clipWatts.size()); addHrStepCurve(clipHr, clipHr.size()); addRegLinCurve(rslope, rintercept); setJoinLine(joinLine); replot(); }