void PowerHist::configChanged() { // plot background setCanvasBackground(GColor(CPLOTBACKGROUND)); // curve QPen pen; QColor brush_color; switch (series) { case RideFile::watts: case RideFile::wattsKg: pen.setColor(GColor(CPOWER).darker(200)); brush_color = GColor(CPOWER); break; case RideFile::nm: pen.setColor(GColor(CTORQUE).darker(200)); brush_color = GColor(CTORQUE); break; case RideFile::kph: pen.setColor(GColor(CSPEED).darker(200)); brush_color = GColor(CSPEED); break; case RideFile::cad: pen.setColor(GColor(CCADENCE).darker(200)); brush_color = GColor(CCADENCE); break; default: case RideFile::hr: pen.setColor(GColor(CHEARTRATE).darker(200)); brush_color = GColor(CHEARTRATE); break; } double width = appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble(); if (appsettings->value(this, GC_ANTIALIAS, false).toBool()==true) { curve->setRenderHint(QwtPlotItem::RenderAntialiased); curveSelected->setRenderHint(QwtPlotItem::RenderAntialiased); } // use a linear gradient brush_color.setAlpha(240); QColor brush_color1 = brush_color; brush_color1.setAlpha(40); QLinearGradient linearGradient(0, 0, 0, height()); linearGradient.setColorAt(0.0, brush_color); linearGradient.setColorAt(1.0, brush_color1); linearGradient.setSpread(QGradient::PadSpread); curve->setBrush(linearGradient); // fill below the line if (zoned == false || (zoned == true && (series != RideFile::watts && series != RideFile::wattsKg && series != RideFile::hr))) { pen.setWidth(width); curve->setPen(pen); } else { pen.setWidth(width); curve->setPen(Qt::NoPen); } // intervalselection QPen ivl(GColor(CINTERVALHIGHLIGHTER).darker(200)); ivl.setWidth(width); curveSelected->setPen(ivl); QColor ivlbrush = GColor(CINTERVALHIGHLIGHTER); ivlbrush.setAlpha(64); curveSelected->setBrush(ivlbrush); // fill below the line // grid QPen gridPen(GColor(CPLOTGRID)); gridPen.setStyle(Qt::DotLine); grid->setPen(gridPen); }
Plot::Plot( QWidget *parent ): QwtPlot( parent ) { setAutoReplot( false ); setTitle( "Frequency Response of a Second-Order System" ); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setBorderRadius( 10 ); setCanvas( canvas ); setCanvasBackground( QColor( "MidnightBlue" ) ); // legend QwtLegend *legend = new QwtLegend; insertLegend( legend, QwtPlot::BottomLegend ); // grid QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin( true ); grid->setMajorPen( Qt::white, 0, Qt::DotLine ); grid->setMinorPen( Qt::gray, 0 , Qt::DotLine ); grid->attach( this ); // axes enableAxis( QwtPlot::yRight ); setAxisTitle( QwtPlot::xBottom, "Normalized Frequency" ); setAxisTitle( QwtPlot::yLeft, "Amplitude [dB]" ); setAxisTitle( QwtPlot::yRight, "Phase [deg]" ); setAxisMaxMajor( QwtPlot::xBottom, 6 ); setAxisMaxMinor( QwtPlot::xBottom, 9 ); setAxisScaleEngine( QwtPlot::xBottom, new QwtLogScaleEngine ); // curves d_curve1 = new QwtPlotCurve( "Amplitude" ); d_curve1->setRenderHint( QwtPlotItem::RenderAntialiased ); d_curve1->setPen( Qt::yellow ); d_curve1->setLegendAttribute( QwtPlotCurve::LegendShowLine ); d_curve1->setYAxis( QwtPlot::yLeft ); d_curve1->attach( this ); d_curve2 = new QwtPlotCurve( "Phase" ); d_curve2->setRenderHint( QwtPlotItem::RenderAntialiased ); d_curve2->setPen( Qt::cyan ); d_curve2->setLegendAttribute( QwtPlotCurve::LegendShowLine ); d_curve2->setYAxis( QwtPlot::yRight ); d_curve2->attach( this ); // marker d_marker1 = new QwtPlotMarker(); d_marker1->setValue( 0.0, 0.0 ); d_marker1->setLineStyle( QwtPlotMarker::VLine ); d_marker1->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom ); d_marker1->setLinePen( Qt::green, 0, Qt::DashDotLine ); d_marker1->attach( this ); d_marker2 = new QwtPlotMarker(); d_marker2->setLineStyle( QwtPlotMarker::HLine ); d_marker2->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom ); d_marker2->setLinePen( QColor( 200, 150, 0 ), 0, Qt::DashDotLine ); d_marker2->setSymbol( new QwtSymbol( QwtSymbol::Diamond, QColor( Qt::yellow ), QColor( Qt::green ), QSize( 8, 8 ) ) ); d_marker2->attach( this ); setDamp( 0.0 ); setAutoReplot( true ); }
PowerHist::PowerHist(MainWindow *mainWindow): rideItem(NULL), mainWindow(mainWindow), series(RideFile::watts), useMetricUnits(true), unit(0), lny(false), shade(false), zoned(false), binw(3), withz(true), dt(1), minX(0), absolutetime(true), cache(NULL), source(Ride) { unit = appsettings->value(this, GC_UNIT); useMetricUnits = (unit.toString() == "Metric"); binw = appsettings->value(this, GC_HIST_BIN_WIDTH, 5).toInt(); if (appsettings->value(this, GC_SHADEZONES, true).toBool() == true) shade = true; else shade = false; // create a background object for shading bg = new PowerHistBackground(this); bg->attach(this); hrbg = new HrHistBackground(this); hrbg->attach(this); setCanvasBackground(Qt::white); canvas()->setFrameStyle(QFrame::NoFrame); setParameterAxisTitle(); setAxisTitle(yLeft, absolutetime ? tr("Time (minutes)") : tr("Time (percent)")); curve = new QwtPlotCurve(""); curve->setStyle(QwtPlotCurve::Steps); curve->setRenderHint(QwtPlotItem::RenderAntialiased); curve->attach(this); curveSelected = new QwtPlotCurve(""); curveSelected->setStyle(QwtPlotCurve::Steps); curveSelected->setRenderHint(QwtPlotItem::RenderAntialiased); curveSelected->attach(this); grid = new QwtPlotGrid(); grid->enableX(false); grid->attach(this); zoneLabels = QList<PowerHistZoneLabel *>(); hrzoneLabels = QList<HrHistZoneLabel *>(); zoomer = new penTooltip(this->canvas()); canvasPicker = new LTMCanvasPicker(this); connect(canvasPicker, SIGNAL(pointHover(QwtPlotCurve*, int)), this, SLOT(pointHover(QwtPlotCurve*, int))); setAxisMaxMinor(xBottom, 0); setAxisMaxMinor(yLeft, 0); configChanged(); }
int QwtPlotWidget::interpret(const char *command, double *x, double *y) { if(command == NULL) return -1; line = command; if (isCommand("setCurveData(")) { if(x == NULL) return -1; if(y == NULL) return -1; int c,count; sscanf(command,"setCurveData(%d,%d",&c,&count); if(c<0 || c>=nCurves) return -1; if(curves[c] != NULL) curves[c]->setData(x,y,count); } else if(isCommand("replot(")) { replot(); } else if(isCommand("setTitle(")) { QString text; if(getText(command,text) != 0) return -1; setTitle(text); } else if(isCommand("setCanvasBackground(")) { int r,g,b; sscanf(command,"setCanvasBackground(%d,%d,%d",&r,&g,&b); setCanvasBackground(QColor(r,g,b)); } else if(isCommand("enableOutline(")) { int val; sscanf(command,"enableOutline(%d",&val); if( val == 0 || val == 1 ) { //xx enableOutline(val); //xx setOutlineStyle(Qwt::Rect ); } else { //xx enableOutline( 1 ); //xx setOutlineStyle(Qwt::Cross ); } } else if(isCommand("setOutlinePen(")) { int r,g,b; sscanf(command,"setOutlinePen(%d,%d,%d",&r,&g,&b); //xx setOutlinePen(QColor(r,g,b)); } else if(isCommand("setAutoLegend(")) { int val; sscanf(command,"setAutoLegend(%d",&val); //xx setAutoLegend(val); autolegend = val; } else if(isCommand("enableLegend(")) { int val; sscanf(command,"enableLegend(%d",&val); enablelegend = val; } else if(isCommand("setLegendPos(")) { int val; sscanf(command,"setLegendPos(%d",&val); if(opt.arg_debug) printf("SetLegendPos begin\n");; if(legend == NULL) legend = new QwtLegend(); if(opt.arg_debug) printf("SetLegendPos 1\n");; legend->setItemMode(QwtLegend::ClickableItem); if(opt.arg_debug) printf("SetLegendPos 2\n");; switch(val) { case PV::LeftLegend: insertLegend(legend, QwtPlot::LeftLegend); break; case PV::RightLegend: insertLegend(legend, QwtPlot::RightLegend); break; case PV::TopLegend: insertLegend(legend, QwtPlot::TopLegend); break; default: insertLegend(legend, QwtPlot::BottomLegend); break; } if(opt.arg_debug) printf("SetLegendPos end\n");; } else if(isCommand("setLegendFrameStyle(")) { int val; sscanf(command,"setLegendFrameStyle(%d",&val); legendframestyle = val; if(legend != NULL) legend->setFrameStyle(legendframestyle); } else if(isCommand("enableGridXMin(")) { grid.enableXMin(true); } else if(isCommand("setGridMajPen(")) { int r,g,b,style; sscanf(command,"setGridMajPen(%d,%d,%d,%d",&r,&g,&b,&style); grid.setMajPen(QPen(QColor(r,g,b),0,(Qt::PenStyle) style)); } else if(isCommand("setGridMinPen(")) { int r,g,b,style; sscanf(command,"setGridMinPen(%d,%d,%d,%d",&r,&g,&b,&style); grid.setMinPen(QPen(QColor(r,g,b),0,(Qt::PenStyle) style)); } else if(isCommand("enableAxis(")) { int pos; sscanf(command,"enableAxis(%d",&pos); enableAxis(pos); } else if(isCommand("setAxisTitle(")) { int pos; QString text; sscanf(command,"setAxisTitle(%d",&pos); if(getText(command,text) != 0) return -1; setAxisTitle(pos,text); } else if(isCommand("setAxisOptions(")) { int pos,val; sscanf(command,"setAxisOptions(%d,%d",&pos,&val); //xx setAxisOptions(pos,val); } else if(isCommand("setAxisMaxMajor(")) { int pos,val; sscanf(command,"setAxisMaxMajor(%d,%d",&pos,&val); setAxisMaxMajor(pos,val); } else if(isCommand("setAxisMaxMinor(")) { int pos,val; sscanf(command,"setAxisMaxMinor(%d,%d",&pos,&val); setAxisMaxMinor(pos,val); } else if(isCommand("insertCurve(")) { int pos; QString text; sscanf(command,"insertCurve(%d",&pos); if(getText(command,text) != 0) return -1; if(pos<0 || pos>=nCurves) return -1; //xx removeCurve( curves[pos] ); //xx curves[pos] = insertCurve(text); if(curves[pos] != NULL) delete curves[pos]; if(opt.arg_debug) printf("new QwtPlotCurve(%s)\n",(const char *) text.toUtf8()); curves[pos] = new QwtPlotCurve(text); curves[pos]->attach(this); if(legend != NULL) { QWidget *w = legend->find(curves[pos]); if(w != NULL) { if(opt.arg_debug) printf("setChecked(%d)\n",autolegend); ((QwtLegendItem *)w)->setChecked(autolegend); } } replot(); //if(autolegend && legend != NULL) curves[pos]->updateLegend(legend); } else if(isCommand("removeCurve(")) { int pos; sscanf(command,"removeCurve(%d",&pos); if(pos<0 || pos>=nCurves) return -1; //xx removeCurve( curves[pos] ); if(curves[pos] != NULL) curves[pos]->detach(); if(curves[pos] != NULL) delete curves[pos]; curves[pos] = NULL; } else if(isCommand("setCurvePen(")) { int pos,r,g,b,width,style; sscanf(command,"setCurvePen(%d,%d,%d,%d,%d,%d",&pos,&r,&g,&b,&width,&style); if(pos<0 || pos>=nCurves) return -1; //xx setCurvePen(curves[pos],QPen(QColor(r,g,b),width,(Qt::PenStyle) style)); QPen pen(QColor(r,g,b)); pen.setWidth(width); pen.setStyle((Qt::PenStyle) style); if(curves[pos] != NULL) curves[pos]->setPen(pen); } else if(isCommand("setCurveSymbol(")) { int pos,symbol,r1,g1,b1,r2,g2,b2,w,h; sscanf(command,"setCurveSymbol(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&pos,&symbol, &r1,&g1,&b1,&r2,&g2,&b2,&w,&h); if(pos<0 || pos>=nCurves) return -1; //xx setCurveSymbol(curves[pos], QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h))); if(curves[pos] != NULL) curves[pos]->setSymbol(QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h))); } else if(isCommand("setCurveYAxis(")) { int pos,pos2; sscanf(command,"setCurveYAxis(%d,%d",&pos,&pos2); if(pos<0 || pos>=nCurves) return -1; //xx setCurveYAxis(curves[pos],pos2); rl2013 if(curves[pos] != NULL) curves[pos]->setYAxis(pos2); } else if(isCommand("insertMarker(")) { int pos; sscanf(command,"insertMarker(%d",&pos); if(pos<0 || pos>=nMarker) return -1; //xx marker[pos] = insertMarker(); if(marker[pos] != NULL) delete marker[pos]; marker[pos] = new QwtPlotMarker(); marker[pos]->attach(this); } else if(isCommand("setMarkerLineStyle(")) { int pos,style; sscanf(command,"setMarkerLineStyle(%d,%d",&pos,&style); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerLineStyle(marker[pos],(QwtMarker::LineStyle) style); if(marker[pos] != NULL) marker[pos]->setLineStyle((QwtPlotMarker::LineStyle) style); } else if(isCommand("setMarkerPos(")) { int pos; float x,y; sscanf(command,"setMarkerPos(%d,%f,%f",&pos,&x,&y); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerPos(marker[pos],x,y); if(marker[pos] != NULL) marker[pos]->setValue(x,y); } else if(isCommand("setMarkerLabelAlign(")) { int pos,align; sscanf(command,"setMarkerLabelAlign(%d,%d",&pos,&align); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerLabelAlign(marker[pos],align); if(marker[pos] != NULL) marker[pos]->setLabelAlignment((Qt::Alignment) align); } else if(isCommand("setMarkerLabel(")) { int pos; QString text; sscanf( command, "setMarkerLabel(%d",&pos ); if(getText(command, text) != 0 ) return -1; //xx setMarkerLabel(marker[pos], text ); if(marker[pos] != NULL) marker[pos]->setLabel(text); } else if(isCommand("setMarkerPen(")) { int pos,r,g,b,style; sscanf(command,"setMarkerPen(%d,%d,%d,%d,%d",&pos,&r,&g,&b,&style); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerPen(marker[pos],QPen(QColor(r,g,b),0,(Qt::PenStyle) style)); if(marker[pos] != NULL) marker[pos]->setLinePen(QPen(QColor(r,g,b))); } else if(isCommand("setMarkerFont(")) { int pos,size,style; QString family; sscanf(command,"setMarkerFont(%d,%d,%d",&pos,&size,&style); if(pos<0 || pos>=nMarker) return -1; if(getText(command,family) != 0) return -1; //xx setMarkerFont(marker[pos],QFont(family,size,style)); } else if(isCommand("setMarkerSymbol(")) { int pos,symbol,r1,g1,b1,r2,g2,b2,w,h; sscanf(command,"setMarkerSymbol(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &pos,&symbol,&r1,&g1,&b1,&r2,&g2,&b2,&w,&h); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerSymbol(marker[pos], QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h))); if(marker[pos] != NULL) marker[pos]->setSymbol(QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h))); } else if(isCommand("insertLineMarker(")) { int pos,pos2; QString text; sscanf(command,"insertLineMarker(%d,%d",&pos,&pos2); if(getText(command,text) != 0) return -1; if(pos<0 || pos>=nMarker) return -1; //xx marker[pos] = insertLineMarker(text, pos2); if(marker[pos] != NULL) delete marker[pos]; marker[pos] = new QwtPlotMarker(); marker[pos]->attach(this); if(marker[pos] != NULL) marker[pos]->setLabel(text); } else if( isCommand("setAxisScaleDraw(")) { int pos; QString qtext; char text[1024]; sscanf( command, "setAxisScaleDraw(%d",&pos ); if( getText(command, qtext) != 0 ) return -1; if(qtext.length() < ((int) sizeof(text) -1)) { strcpy(text,qtext.toUtf8()); } else { strcpy(text,"text too long"); } if(opt.arg_debug) printf("setAxisScaleDraw(%s)\n",text); setAxisScaleDraw( pos, new UserScaleDraw( text )); } else if( isCommand("setAxisScale(")) { int pos; float min,max,step; sscanf( command, "setAxisScale(%d,%f,%f,%f",&pos ,&min, &max, &step); if(opt.arg_debug) printf("setAxisScale(%d,%f,%f,%f)\n",pos,min,max,step); setAxisScale(pos,min,max,step); } else { return -1; } return 0; }
PfPvPlot::PfPvPlot(MainWindow *mainWindow) : rideItem (NULL), mainWindow(mainWindow), cp_ (0), cad_ (85), cl_ (0.175), shade_zones(true) { setInstanceName("PfPv Plot"); setCanvasBackground(Qt::white); canvas()->setFrameStyle(QFrame::NoFrame); setAxisTitle(yLeft, tr("Average Effective Pedal Force (N)")); setAxisScale(yLeft, 0, 600); setAxisTitle(xBottom, tr("Circumferential Pedal Velocity (m/s)")); setAxisScale(xBottom, 0, 3); setAxisMaxMinor(yLeft, 0); setAxisMaxMinor(xBottom, 0); QwtScaleDraw *sd = new QwtScaleDraw; sd->setTickLength(QwtScaleDiv::MajorTick, 3); setAxisScaleDraw(xBottom, sd); sd = new QwtScaleDraw; sd->setTickLength(QwtScaleDiv::MajorTick, 3); setAxisScaleDraw(yLeft, sd); 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(); curve->attach(this); cl_ = appsettings->value(this, GC_CRANKLENGTH).toDouble() / 1000.0; // markup timeInQuadrant tiqMarker[0] = new QwtPlotMarker(); tiqMarker[0]->attach(this); tiqMarker[0]->setXValue(2.9); tiqMarker[0]->setYValue(580); tiqMarker[1] = new QwtPlotMarker(); tiqMarker[1]->attach(this); tiqMarker[1]->setXValue(0.1); tiqMarker[1]->setYValue(580); tiqMarker[2] = new QwtPlotMarker(); tiqMarker[2]->attach(this); tiqMarker[2]->setXValue(0.1); tiqMarker[2]->setYValue(10); tiqMarker[3] = new QwtPlotMarker(); tiqMarker[3]->attach(this); tiqMarker[3]->setXValue(2.9); tiqMarker[3]->setYValue(10); merge_intervals = false; frame_intervals = true; // only default on first time through, after this the user may have adjusted if (appsettings->value(this, GC_SHADEZONES, true).toBool()==false) shade_zones = false; else shade_zones = true; configChanged(); recalc(); }
ribi::QtToolTestApproximatorXyzMainDialog::QtToolTestApproximatorXyzMainDialog(QWidget *parent) noexcept : QtHideAndShowDialog(parent), ui(new Ui::QtToolTestApproximatorXyzMainDialog), m_approximator(), m_data(CreateData()) { #ifndef NDEBUG Test(); #endif ui->setupUi(this); //Set up the plots and curves GetPlot(0)->setTitle("Approximator, for z = 0.0"); GetPlot(1)->setTitle("Approximator, for z = 0.5"); GetPlot(2)->setTitle("Approximator, for z = 1.0"); for (auto i=0; i!=m_n_curves; ++i) { const auto plot = GetPlot(i); plot->setAxisTitle(QwtPlot::xBottom,"X"); plot->setAxisTitle(QwtPlot::yLeft,"Y"); #ifdef _WIN32 plot->setCanvasBackground(QBrush(QColor(255,255,255))); #else plot->setCanvasBackground(QColor(255,255,255)); #endif const auto curve_values = GetCurveValues(i); assert(curve_values); curve_values->setTitle("Points"); curve_values->attach(plot.get()); curve_values->setStyle(QwtPlotCurve::Dots); curve_values->setPen(QPen(QColor(255,0,0),5)); const auto curve_approximation = GetCurveApproximation(i); assert(curve_approximation); curve_approximation->setTitle("Approximation"); curve_approximation->attach(plot.get()); curve_approximation->setStyle(QwtPlotCurve::Dots); curve_approximation->setPen(QPen(QColor(0,0,255),3)); //Add grid { QwtPlotGrid * const grid = new QwtPlotGrid; grid->setPen(QPen(QColor(128,128,128))); grid->attach(plot.get()); } //Add zoomer { new QwtPlotZoomer(plot->canvas()); } //Add legend { QwtLegend * const legend = new QwtLegend; legend->setFrameStyle(QFrame::Box|QFrame::Sunken); plot->insertLegend(legend, QwtPlot::RightLegend); } plot->setAxisScale( QwtPlot::xBottom, static_cast<double>(ui->box_int_x->minimum()), static_cast<double>(ui->box_int_x->maximum()) ); plot->setAxisScale( QwtPlot::yLeft, static_cast<double>(ui->box_double_y->minimum()), static_cast<double>(ui->box_double_y->maximum()) ); //Add to dialog assert(ui->verticalLayout->layout()); ui->verticalLayout->layout()->addWidget(plot.get()); } //Add some nice testing values ui->box_int_x->setValue(ui->box_int_x->minimum() / 2); ui->box_double_y->setValue(ui->box_double_y->maximum() / 2.0); on_button_clicked(); ui->box_int_x->setValue(ui->box_int_x->minimum() / 4); ui->box_double_y->setValue(ui->box_double_y->minimum() / 2.0); on_button_clicked(); ui->box_int_x->setValue(ui->box_int_x->maximum() / 4); ui->box_double_y->setValue(ui->box_double_y->maximum() / 2.0); on_button_clicked(); ui->box_int_x->setValue(ui->box_int_x->maximum() / 2); ui->box_double_y->setValue(ui->box_double_y->minimum() / 2.0); on_button_clicked(); ui->box_int_x->setValue(0); ui->box_double_y->setValue(0.0); }
Plot::Plot (QString name, QWidget *p) : QwtPlot (p) { //TODO high = 0; low = 0; destroying = false; //PlotSettings _plotSettings.name = name; _plotSettings.spacing = 4; _plotSettings.high = 0; _plotSettings.low = 0; _plotSettings.startPos = -1; _plotSettings.endPos = -1; _plotSettings.selected = 0; _plotSettings.antiAlias = true; _plotSettings.barLength = BarLength::_DAILY; _plotSettings.status = PlotStatus::_NONE; _plotSettings.info = true; mpage = 360; //default setMinimumHeight(20); setCanvasBackground(QColor(Qt::black)); //TODO remove? setStyleSheet("QwtPlot { padding: 0px }"); enableAxis(QwtPlot::yRight, true); enableAxis(QwtPlot::yLeft, false); // add custom date scale drawing class to plot _dateScaleDraw = new PlotDateScaleDraw; setAxisScaleDraw(QwtPlot::xBottom, _dateScaleDraw); // add custom date scale drawing class to plot _plotScaleDraw = new PlotScaleDraw; setAxisScaleDraw(QwtPlot::yRight, _plotScaleDraw); _grid = new QwtPlotGrid; // _grid->enableXMin(false); _grid->enableX(false); _grid->enableYMin(false); _grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine)); _grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); _grid->setYAxis(QwtPlot::yRight); _grid->attach(this); // try to set the scale width to a sane size to keep plots aligned QwtScaleWidget *sw = axisWidget(QwtPlot::yRight); sw->scaleDraw()->setMinimumExtent(60); // setup the mouse events handler _picker = new PlotPicker(this); connect(_picker, SIGNAL(signalMouseMove(QPoint)), this, SLOT(mouseMove(QPoint))); connect(_picker, SIGNAL(signalMouseClick(int, QPoint)), this, SLOT(mouseClick(int, QPoint))); connect(_picker, SIGNAL(signalMouseDoubleClick(int, QPoint)), this, SLOT(mouseDoubleClick(int, QPoint))); // connect(_picker, SIGNAL(signalMouseRelease(int, QPoint)), this, SLOT(mouseRelease(int, QPoint))); // setup the context menu createMenu(); // grabGesture(Qt::TapAndHoldGesture); // grabGesture(Qt::SwipeGesture); _plotInfo = new PlotInfo; _plotInfo->attach(this); }
AllPlot::AllPlot(AllPlotWindow *parent, MainWindow *mainWindow): QwtPlot(parent), rideItem(NULL), unit(0), shade_zones(true), showPowerState(3), showHrState(Qt::Checked), showSpeedState(Qt::Checked), showCadState(Qt::Checked), showAltState(Qt::Checked), bydist(false), parent(parent) { boost::shared_ptr<QSettings> settings = GetApplicationSettings(); unit = settings->value(GC_UNIT); referencePlot = NULL; useMetricUnits = (unit.toString() == "Metric"); // options for turning off/on shading on all plot // will come in with a future patch, for now we // enable zone shading by default, since this is // the current default behaviour if (false) shade_zones = false; else shade_zones = true; smooth = settings->value(GC_RIDE_PLOT_SMOOTHING).toInt(); if (smooth < 1) smooth = 1; // create a background object for shading bg = new AllPlotBackground(this); bg->attach(this); insertLegend(new QwtLegend(), QwtPlot::BottomLegend); setCanvasBackground(GColor(CPLOTBACKGROUND)); setXTitle(); wattsCurve = new QwtPlotCurve(tr("Power")); hrCurve = new QwtPlotCurve(tr("Heart Rate")); hrCurve->setYAxis(yLeft2); speedCurve = new QwtPlotCurve(tr("Speed")); speedCurve->setYAxis(yRight); cadCurve = new QwtPlotCurve(tr("Cadence")); cadCurve->setYAxis(yLeft2); altCurve = new QwtPlotCurve(tr("Altitude")); // altCurve->setRenderHint(QwtPlotItem::RenderAntialiased); altCurve->setYAxis(yRight2); intervalHighlighterCurve = new QwtPlotCurve(); intervalHighlighterCurve->setYAxis(yLeft); intervalHighlighterCurve->setData(IntervalPlotData(this, mainWindow)); intervalHighlighterCurve->attach(this); this->legend()->remove(intervalHighlighterCurve); // don't show in legend grid = new QwtPlotGrid(); grid->enableX(false); grid->attach(this); // get rid of nasty blank space on right of the plot plotLayout()->setAlignCanvasToScales(true); configChanged(); // set colors }
void Plot::setBackgroundColor (QColor d) { setCanvasBackground(d); replot(); }
Plot::Plot(QWidget *parent, const char *) : QwtPlot(parent) { setAutoReplot (false); d_locale = QLocale::c(); marker_key = 0; curve_key = 0; minTickLength = 5; majTickLength = 9; setGeometry(QRect(0,0,500,400)); 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); }
BrainPlot::BrainPlot(QWidget *parent, int nChannels, int Length, int Amplitude): QwtPlot( parent ), d_curves( nChannels ), d_zeros( nChannels ) { /*Set some attributes*/ minusExpectedAmplitude = -Amplitude; plotLength = Length; this->nChannels = nChannels; /*Start sample counter*/ sample = 0; /*Painter*/ d_directPainter = new QwtPlotDirectPainter( this ); if ( QwtPainter::isX11GraphicsSystem() ) { #if QT_VERSION < 0x050000 canvas()->setAttribute( Qt::WA_PaintOutsidePaintEvent, true ); #endif canvas()->setAttribute( Qt::WA_PaintOnScreen, true ); } /*Activates the legend for channel tracking*/ QwtLegend *legend = new QwtLegend; legend->setDefaultItemMode( QwtLegendData::ReadOnly); insertLegend( legend, QwtPlot::LeftLegend ); /*Instantiate the reference lines and the data curves for each channel*/ int Hfactor = 360/(nChannels+1);//different colors for each curve char name[15]; for(int c = 0; c < nChannels; c++) { /*Curve*/ sprintf(name, "Channel %d", c+1); d_curves[c] = new QwtPlotCurve( name); d_curves[c]->setData( new CurveData(plotLength, minusExpectedAmplitude*(2*c+1)) ); d_curves[c]->setPen( QColor::fromHsv ( Hfactor*c, 255, 255)); d_curves[c]->setStyle( QwtPlotCurve::Lines ); d_curves[c]->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol)); d_curves[c]->attach( this ); /*Reference line*/ d_zeros[c] = new QwtPlotCurve; d_zeros[c]->setData( new CurveData() ); d_zeros[c]->setPen( QColor::fromHsv ( Hfactor*c, 255, 140)); d_zeros[c]->setStyle( QwtPlotCurve::Lines ); d_zeros[c]->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol)); d_zeros[c]->setItemAttribute(QwtPlotItem::Legend, false); d_zeros[c]->attach( this ); /*Draw reference lines*/ CurveData *data = static_cast<CurveData *>( d_zeros[c]->data() ); data->append(QPointF(0, minusExpectedAmplitude*(2*c+1))); data->append(QPointF(plotLength, minusExpectedAmplitude*(2*c+1))); d_directPainter->drawSeries( d_zeros[c], 0, 1); } /*Sweeping line*/ d_sweep = new QwtPlotCurve; d_sweep->setData( new CurveData() ); d_sweep->setPen( Qt::black, plotLength/100, Qt::SolidLine); d_sweep->setStyle( QwtPlotCurve::Lines ); d_sweep->setSymbol( new QwtSymbol( QwtSymbol::NoSymbol)); d_sweep->setItemAttribute(QwtPlotItem::Legend, false); d_sweep->attach( this ); CurveData *data = static_cast<CurveData *>( d_sweep->data() ); data->append(QPointF(0, plotLength)); data->append(QPointF(0, 2*nChannels*minusExpectedAmplitude)); /*Axis*/ setAxisScale( xBottom, 0, plotLength ); setAxisScale( yLeft, 2*nChannels*minusExpectedAmplitude, 0 ); enableAxis(xBottom, false); enableAxis(yLeft, false); /*Frame*/ setFrameStyle( QFrame::NoFrame ); setLineWidth( 0 ); /*Canvas*/ plotLayout()->setAlignCanvasToScales( true ); plotLayout()->setCanvasMargin(100, QwtPlot::xBottom); plotLayout()->setCanvasMargin(100, QwtPlot::xTop); setCanvasBackground( Qt::black ); /*Grid*/ QwtPlotGrid *grid = new QwtPlotGrid; grid->setMajorPen( Qt::gray, 0, Qt::DotLine ); grid->setMinorPen( Qt::gray, 0, Qt::DotLine ); grid->enableYMin(true); grid->attach( this ); /*Optimizaion for real-time data collecting*/ setAutoReplot( false ); /*Show*/ replot(); }
SingleCellViewGraphPanelPlotWidget::SingleCellViewGraphPanelPlotWidget(QWidget *pParent) : QwtPlot(pParent), Core::CommonWidget(pParent), mGui(new Ui::SingleCellViewGraphPanelPlotWidget), mGraphs(QList<SingleCellViewGraphPanelPlotGraph *>()), mAction(None), mOriginPoint(QPoint()), mPoint(QPoint()), mCanZoomInX(true), mCanZoomOutX(true), mCanZoomInY(true), mCanZoomOutY(true), mNeedContextMenu(false) { // Set up the GUI mGui->setupUi(this); // Get ourselves a direct painter mDirectPainter = new QwtPlotDirectPainter(this); // Speedup painting on X11 systems // Note: this can only be done on X11 systems... if (QwtPainter::isX11GraphicsSystem()) canvas()->setAttribute(Qt::WA_PaintOnScreen, true); // Customise ourselves a bit setCanvasBackground(Qt::white); mAxisX = new SingleCellViewGraphPanelPlotScaleDraw(); mAxisY = new SingleCellViewGraphPanelPlotScaleDraw(); setAxisScaleDraw(QwtPlot::xBottom, mAxisX); setAxisScaleDraw(QwtPlot::yLeft, mAxisY); // We don't want a frame around ourselves qobject_cast<QwtPlotCanvas *>(canvas())->setFrameShape(QFrame::NoFrame); // Set our axes' values // Note: we are not all initialised yet, so we don't want to setAxes() to // replot ourselves... setAxes(DefMinAxis, DefMaxAxis, DefMinAxis, DefMaxAxis, false); // Attach a grid to ourselves QwtPlotGrid *grid = new QwtPlotGrid(); grid->setMajorPen(Qt::gray, 0, Qt::DotLine); grid->attach(this); // Create our overlay widget mOverlayWidget = new SingleCellViewGraphPanelPlotOverlayWidget(this); // Create our context menu mContextMenu = new QMenu(this); mContextMenu->addAction(mGui->actionCopyToClipboard); mContextMenu->addSeparator(); mContextMenu->addAction(mGui->actionZoomIn); mContextMenu->addAction(mGui->actionZoomOut); mContextMenu->addSeparator(); mContextMenu->addAction(mGui->actionResetZoom); }
HrPwPlot::HrPwPlot(Context *context, HrPwWindow *hrPwWindow) : QwtPlot(hrPwWindow), hrPwWindow(hrPwWindow), context(context), bg(NULL), delay(-1), minHr(50), minWatt(50), maxWatt(500) { setCanvasBackground(Qt::white); static_cast<QwtPlotCanvas*>(canvas())->setFrameStyle(QFrame::NoFrame); setXTitle(); // Power (Watts) // Linear Regression Curve regCurve = new QwtPlotCurve("reg"); regCurve->setPen(QPen(GColor(CPLOTMARKER))); regCurve->attach(this); // Power distribution wattsStepCurve = new QwtPlotCurve("Power"); wattsStepCurve->setStyle(QwtPlotCurve::Steps); wattsStepCurve->setRenderHint(QwtPlotItem::RenderAntialiased); QColor wattsColor = QColor(200,200,255); QColor wattsColor2 = QColor(100,100,255); wattsStepCurve->setPen(QPen(wattsColor2)); wattsStepCurve->setBrush(QBrush(wattsColor)); wattsStepCurve->attach(this); // Hr distribution hrStepCurve = new QwtPlotCurve("Hr"); hrStepCurve->setStyle(QwtPlotCurve::Steps); hrStepCurve->setRenderHint(QwtPlotItem::RenderAntialiased); QColor hrColor = QColor(255,200,200); QColor hrColor2 = QColor(255,100,100); hrStepCurve->setPen(QPen(hrColor2)); hrStepCurve->setBrush(QBrush(hrColor)); hrStepCurve->attach(this); // Heart Rate Curve hrCurves.resize(36); for (int i = 0; i < 36; ++i) { hrCurves[i] = new QwtPlotCurve; hrCurves[i]->attach(this); } // Grid grid = new QwtPlotGrid(); grid->enableX(true); grid->enableY(true); grid->attach(this); // axis markers r_mrk1 = new QwtPlotMarker; r_mrk2 = new QwtPlotMarker; r_mrk1->attach(this); r_mrk2->attach(this); shade_zones = true; connect(context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged(qint32))); // setup colors on first run configChanged(CONFIG_APPEARANCE); }