ScopePanel::ScopePanel( const QString& name, double* sample_x, double* sample_y, int num_samples, QWidget* parent ) : QWidget(parent), name(name), plot(QwtText(name),this) { #if QWT_VERSION >= 0x60100 plot_curve.setPaintAttribute( QwtPlotCurve::PaintAttribute::FilterPoints ); #endif plot_curve.setRawSamples( sample_x, sample_y, num_samples ); setXRange( 0, num_samples, false ); setYRange( -1, 1, true ); setPen(QPen(QColor("deeppink"), 2)); plot_curve.attach(&plot); QSizePolicy sp(QSizePolicy::MinimumExpanding,QSizePolicy::Expanding); plot.setSizePolicy(sp); QVBoxLayout* layout = new QVBoxLayout(); layout->addWidget(&plot); layout->setContentsMargins(0,0,0,0); layout->setSpacing(0); setLayout(layout); }
/*! Constructor \param title title of the curve */ QwtPolarCurve::QwtPolarCurve( const QString &title ): QwtPolarItem( QwtText( title ) ) { init(); }
void CpintPlot::calculate(RideItem *rideItem) { if (!rideItem) return; QString fileName = rideItem->fileName; QDateTime dateTime = rideItem->dateTime; QDir dir(path); QFileInfo file(fileName); // get current ride statistics current = new RideFileCache(mainWindow, mainWindow->home.absolutePath() + "/" + fileName); // get aggregates - incase not initialised from date change if (bests == NULL) bests = new RideFileCache(mainWindow, startDate, endDate, isFiltered, files); // // PLOT MODEL CURVE (DERIVED) // curveTitle.setLabel(QwtText("", QwtText::PlainText)); // default to no title if (series == RideFile::xPower || series == RideFile::NP || series == RideFile::watts || series == RideFile::wattsKg || series == RideFile::none) { if (bests->meanMaxArray(series).size() > 1) { // calculate CP model from all-time best data cp = tau = t0 = 0; deriveCPParameters(); } // // CP curve only relevant for Energy or Watts (?) // if (series == RideFile::watts || series == RideFile::wattsKg || series == RideFile::none) { if (!CPCurve) plot_CP_curve(this, cp, tau, t0); else { // make sure color reflects latest config QPen pen(GColor(CCP)); pen.setWidth(2.0); pen.setStyle(Qt::DashLine); CPCurve->setPen(pen); } } // // PLOT ZONE (RAINBOW) AGGREGATED CURVE // if (bests->meanMaxArray(series).size()) { int maxNonZero = 0; for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) { if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i; } plot_allCurve(this, maxNonZero, bests->meanMaxArray(series).constData() + 1); } } else { // // PLOT BESTS IN SERIES COLOR // if (allCurve) { delete allCurve; allCurve = NULL; } if (bests->meanMaxArray(series).size()) { int maxNonZero = 0; QVector<double> timeArray(bests->meanMaxArray(series).size()); for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) { timeArray[i] = i / 60.0; if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i; } if (maxNonZero > 1) { allCurve = new QwtPlotCurve(dateTime.toString(tr("ddd MMM d, yyyy h:mm AP"))); allCurve->setRenderHint(QwtPlotItem::RenderAntialiased); QPen line; QColor fill; switch (series) { case RideFile::kph: line.setColor(GColor(CSPEED).darker(200)); fill = (GColor(CSPEED)); break; case RideFile::cad: line.setColor(GColor(CCADENCE).darker(200)); fill = (GColor(CCADENCE)); break; case RideFile::nm: line.setColor(GColor(CTORQUE).darker(200)); fill = (GColor(CTORQUE)); break; case RideFile::hr: line.setColor(GColor(CHEARTRATE).darker(200)); fill = (GColor(CHEARTRATE)); break; case RideFile::vam: line.setColor(GColor(CALTITUDE).darker(200)); fill = (GColor(CALTITUDE)); break; default: case RideFile::watts: // won't ever get here case RideFile::NP: case RideFile::xPower: line.setColor(GColor(CPOWER).darker(200)); fill = (GColor(CPOWER)); break; } // wow, QVector really doesn't have a max/min method! double ymax = 0; double ymin = 100000; foreach(double v, current->meanMaxArray(series)) { if (v > ymax) ymax = v; if (v && v < ymin) ymin = v; } foreach(double v, bests->meanMaxArray(series)) { if (v > ymax) ymax = v; if (v&& v < ymin) ymin = v; } if (ymin == 100000) ymin = 0; // VAM is a bit special if (series == RideFile::vam) { if (bests->meanMaxArray(series).size() > 300) ymax = bests->meanMaxArray(series)[300]; else ymax = 2000; } ymax *= 1.1; // bit of headroom ymin *= 0.9; // xmax is directly related to the size of the arrays double xmax = current->meanMaxArray(series).size(); if (bests->meanMaxArray(series).size() > xmax) xmax = bests->meanMaxArray(series).size(); xmax /= 60; // its in minutes not seconds setAxisScale(yLeft, ymin, ymax); if (series == RideFile::vam) setAxisScale(xBottom, 4.993, xmax); else setAxisScale(xBottom, 0.017, xmax); allCurve->setPen(line); fill.setAlpha(64); // use a linear gradient fill.setAlpha(240); QColor fill1 = fill; fill1.setAlpha(40); QLinearGradient linearGradient(0, 0, 0, height()); linearGradient.setColorAt(0.0, fill); linearGradient.setColorAt(1.0, fill1); linearGradient.setSpread(QGradient::PadSpread); allCurve->setBrush(linearGradient); allCurve->attach(this); allCurve->setData(timeArray.data() + 1, bests->meanMaxArray(series).constData() + 1, maxNonZero - 1); } }
/*! Constructor \param title Title of the curve */ QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QString &title ): QwtPlotSeriesItem<QwtPoint3D>( QwtText( title ) ) { init(); }
//! Constructor QwtPlotRasterItem::QwtPlotRasterItem( const QString& title ): QwtPlotItem( QwtText( title ) ) { init(); }
/*! Constructor \param title Title of the curve */ QwtPlotCurve::QwtPlotCurve(const QString &title): QwtPlotItem(QwtText(title)) { init(); }
QwtText ScaleDraw::label(double value) const { switch (d_type){ case Numeric: { QLocale locale = ((Graph *)d_plot->parent())->multiLayer()->locale(); if (d_numeric_format == Superscripts){ QString txt = locale.toString(transformValue(value), 'e', d_prec); QStringList list = txt.split("e", QString::SkipEmptyParts); if (list[0].toDouble() == 0.0) return QString("0"); QString s = list[1]; int l = s.length(); QChar sign = s[0]; s.remove (sign); while (l>1 && s.startsWith ("0", false)){ s.remove ( 0, 1 ); l = s.length(); } if (sign == '-') s.prepend(sign); if (list[0] == "1") return QwtText("10<sup>" + s + "</sup>"); else return QwtText(list[0] + "x10<sup>" + s + "</sup>"); } else return QwtText(locale.toString(transformValue(value), d_fmt, d_prec)); break; } case Day: { int val = static_cast<int>(transformValue(value))%7; if (val < 0) val = 7 - abs(val); else if (val == 0) val = 7; QString day; switch(d_name_format){ case ShortName: day = QDate::shortDayName (val); break; case LongName: day = QDate::longDayName (val); break; case Initial: day = (QDate::shortDayName (val)).left(1); break; } return QwtText(day); break; } case Month: { int val = static_cast<int>(transformValue(value))%12; if (val < 0) val = 12 - abs(val); else if (val == 0) val = 12; QString day; switch(d_name_format){ case ShortName: day = QDate::shortMonthName (val); break; case LongName: day = QDate::longMonthName (val); break; case Initial: day = (QDate::shortMonthName (val)).left(1); break; } return QwtText(day); break; } case Time: return QwtText(d_date_time_origin.time().addMSecs((int)value).toString(d_format_info)); break; case Date: return QwtText(d_date_time_origin.addSecs((int)value).toString(d_format_info)); break; case ColHeader: case Text: { const QwtScaleDiv scDiv = scaleDiv(); if (!scDiv.contains (value)) return QwtText(); QwtValueList ticks = scDiv.ticks (QwtScaleDiv::MajorTick); double break_offset = 0; ScaleEngine *se = (ScaleEngine *)d_plot->axisScaleEngine(axis()); /*QwtScaleEngine *qwtsc_engine=d_plot->axisScaleEngine(axis()); ScaleEngine *se =dynamic_cast<ScaleEngine*>(qwtsc_engine); if(se!=NULL) {*/ bool inverted = se->testAttribute(QwtScaleEngine::Inverted); if(se->hasBreak()){ double lb = se->axisBreakLeft(); double rb = se->axisBreakRight(); if(inverted){ if (value <= lb){ int n_ticks = (int)ticks.count() - 1; double val0 = ticks[0]; double val1 = ticks[n_ticks]; for (int i = 1; i < n_ticks; i++){ double aux = ticks[i]; if(aux >= rb && val0 > aux){ val0 = aux; continue; } if(aux <= lb && val1 < aux) val1 = aux; } break_offset = fabs(val1 - val0); } } else { if (value >= rb){ double val0 = ticks[0]; for (int i = 1; i < (int)ticks.count(); i++){ double val = ticks[i]; if(val0 <= lb && val >= rb){ break_offset = fabs(val - val0); break; } val0 = val; } } } } double step = ticks[1] - ticks[0]; int index = static_cast<int>(ticks[0] + step*ticks.indexOf(value) - 1); int offset = abs((int)floor(break_offset/step)); if (offset) offset--; if (step > 0) index += offset; else index -= offset; if (index >= 0 && index < (int)d_text_labels.count()) return QwtText(d_text_labels[index]); else return QwtText(); //} break; } } return QwtText(); }
RateStateSimWindow::RateStateSimWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { QWidget *main_widget; QVBoxLayout *control_layout, *plot_layout; QHBoxLayout *main_layout; int i; QwtSlider *a_param_slider, *ab_ratio_slider, *k_param_slider, *r_param_slider; param_a = 0.0625; param_b = 0.125;//param_a*2.84184246806358;// param_k = 20; param_r = 1e-5; param_w = 0.5; a_param_slider = new QwtSlider(0); a_param_slider->setScale(-2, 0); a_param_slider->setRange(-2, 0); a_param_slider->setValue(log10(param_a)); a_param_slider->setScalePosition(QwtSlider::TopScale); ab_ratio_slider = new QwtSlider(0); ab_ratio_slider->setScale(0.001, 1.0); ab_ratio_slider->setRange(0.001, 1.0); ab_ratio_slider->setValue(param_a/param_b); ab_ratio_slider->setScalePosition(QwtSlider::TopScale); k_param_slider = new QwtSlider(0); k_param_slider->setScale(15, 25); k_param_slider->setRange(15, 25); k_param_slider->setValue(param_k); k_param_slider->setScalePosition(QwtSlider::TopScale); r_param_slider = new QwtSlider(0); r_param_slider->setScale(-7, 1); r_param_slider->setRange(-7, 1); r_param_slider->setValue(log10(param_r)); r_param_slider->setScalePosition(QwtSlider::TopScale); connect(a_param_slider, SIGNAL(valueChanged(double)), this, SLOT(a_param_changed(double))); connect(ab_ratio_slider, SIGNAL(valueChanged(double)), this, SLOT(ab_ratio_changed(double))); connect(k_param_slider, SIGNAL(valueChanged(double)), this, SLOT(k_param_changed(double))); connect(r_param_slider, SIGNAL(valueChanged(double)), this, SLOT(r_param_changed(double))); control_layout = new QVBoxLayout; control_layout->addWidget(a_param_slider); control_layout->addWidget(ab_ratio_slider); control_layout->addWidget(k_param_slider); control_layout->addWidget(r_param_slider); position_data = new QwtPlotCurve(QwtText("X")); velocity_data = new QwtPlotCurve(QwtText("V")); theta_data = new QwtPlotCurve(QwtText("Theta")); force_data = new QwtPlotCurve(QwtText("Force")); driver_data = new QwtPlotCurve(QwtText("Driver Plate")); position_plot = new QwtPlot(QwtText("X")); velocity_plot = new QwtPlot(QwtText("Velocity")); velocity_plot->setAxisScaleEngine(QwtPlot::yLeft, new QwtLog10ScaleEngine); theta_plot = new QwtPlot(QwtText("Theta")); force_plot = new QwtPlot(QwtText("Force")); double min_t = 0, max_t = 160; position_plot->setAxisScale(QwtPlot::xBottom, min_t, max_t, 0); position_plot->setAxisScale(QwtPlot::yLeft, 100, 140, 0); velocity_plot->setAxisScale(QwtPlot::xBottom, min_t, max_t, 0); theta_plot->setAxisScale(QwtPlot::xBottom, min_t, max_t, 0); force_plot->setAxisScale(QwtPlot::xBottom, min_t, max_t, 0); position_data->attach(position_plot); driver_data->attach(position_plot); velocity_data->attach(velocity_plot); theta_data->attach(theta_plot); force_data->attach(force_plot); plot_layout = new QVBoxLayout; plot_layout->setContentsMargins(0, 0, 0, 0); plot_layout->addWidget(position_plot, 0); plot_layout->addWidget(velocity_plot, 0); plot_layout->addWidget(theta_plot, 0); plot_layout->addWidget(force_plot, 0); main_layout = new QHBoxLayout; main_layout->addLayout(control_layout); main_layout->addLayout(plot_layout); main_widget = new QWidget; main_widget->setLayout(main_layout); setCentralWidget(main_widget); emit recalc(); };
/** Called each time the mouse moves over the canvas */ QwtText CustomPicker::trackerText(const QwtDoublePoint &pos) const { emit mouseMoved(pos.x(), pos.y()); return QwtText(); }
/* Extract all layout relevant data from the plot components */ void QwtPlotLayout::LayoutData::init( const QwtPlot *plot, const QRectF &rect ) { // legend if ( plot->legend() ) { legend.frameWidth = plot->legend()->frameWidth(); legend.hScrollExtent = plot->legend()->scrollExtent( Qt::Horizontal ); legend.vScrollExtent = plot->legend()->scrollExtent( Qt::Vertical ); const QSize hint = plot->legend()->sizeHint(); int w = qMin( hint.width(), qFloor( rect.width() ) ); int h = plot->legend()->heightForWidth( w ); if ( h <= 0 ) h = hint.height(); if ( h > rect.height() ) w += legend.hScrollExtent; legend.hint = QSize( w, h ); } // title title.frameWidth = 0; title.text = QwtText(); if ( plot->titleLabel() ) { const QwtTextLabel *label = plot->titleLabel(); title.text = label->text(); if ( !( title.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) ) title.text.setFont( label->font() ); title.frameWidth = plot->titleLabel()->frameWidth(); } // footer footer.frameWidth = 0; footer.text = QwtText(); if ( plot->footerLabel() ) { const QwtTextLabel *label = plot->footerLabel(); footer.text = label->text(); if ( !( footer.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) ) footer.text.setFont( label->font() ); footer.frameWidth = plot->footerLabel()->frameWidth(); } // scales for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( plot->axisEnabled( axis ) ) { const QwtScaleWidget *scaleWidget = plot->axisWidget( axis ); scale[axis].isEnabled = true; scale[axis].scaleWidget = scaleWidget; scale[axis].scaleFont = scaleWidget->font(); scale[axis].start = scaleWidget->startBorderDist(); scale[axis].end = scaleWidget->endBorderDist(); scale[axis].baseLineOffset = scaleWidget->margin(); scale[axis].tickOffset = scaleWidget->margin(); if ( scaleWidget->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) ) { scale[axis].tickOffset += scaleWidget->scaleDraw()->maxTickLength(); } scale[axis].dimWithoutTitle = scaleWidget->dimForLength( QWIDGETSIZE_MAX, scale[axis].scaleFont ); if ( !scaleWidget->title().isEmpty() ) { scale[axis].dimWithoutTitle -= scaleWidget->titleHeightForWidth( QWIDGETSIZE_MAX ); } } else { scale[axis].isEnabled = false; scale[axis].start = 0; scale[axis].end = 0; scale[axis].baseLineOffset = 0; scale[axis].tickOffset = 0.0; scale[axis].dimWithoutTitle = 0; } } // canvas plot->canvas()->getContentsMargins( &canvas.contentsMargins[ QwtPlot::yLeft ], &canvas.contentsMargins[ QwtPlot::xTop ], &canvas.contentsMargins[ QwtPlot::yRight ], &canvas.contentsMargins[ QwtPlot::xBottom ] ); }
// create new AllPlotSlopeCurve AllPlotSlopeCurve::AllPlotSlopeCurve( const QString &title ): QwtPlotCurve( QwtText( title ) ) { init(); }
QwtText DateScaleDraw::label(double value) const { QDate t = t_origin.addDays( (int) value ); return QwtText(t.toString ( t_format )); }
QwtText TimeScaleDraw::label(double value) const { QTime t = t_origin.addMSecs ( (int)value ); return QwtText(t.toString ( t_format )); }
LogPlotZoomer::LogPlotZoomer(QWidget *canvas) : QwtPlotZoomer(canvas) #else LogPlotZoomer::LogPlotZoomer(QwtPlotCanvas *canvas): QwtPlotZoomer(canvas) #endif {} #if QWT_VERSION > 0x060000 QwtText LogPlotZoomer::trackerTextF(const QwtDoublePoint &pos) const #else QwtText LogPlotZoomer::trackerText(const QwtDoublePoint &pos) const #endif { switch (rubberBand()) { case HLineRubberBand: return QString().sprintf("%.4g", pos.y()); case VLineRubberBand: return QString().sprintf("%.4g", pos.x()); default: return QString().sprintf("%.4g, %.4g", pos.x(), pos.y()); } return QwtText(); // make some dumb compilers happy } /*void QwtPlotZoomer::move(double x, double y) { x = qwtMax(x, zoomBase().left()); x = qwtMin(x, zoomBase().right() - zoomRect().width()); y = qwtMax(y, zoomBase().top()); y = qwtMin(y, zoomBase().bottom() - zoomRect().height()); if (x != zoomRect().left() || y != zoomRect().top()) { d_data->zoomStack[d_data->zoomRectIndex].moveTo(x, y); rescale(); } }*/ #if QWT_VERSION > 0x060000 void LogPlotZoomer::moveTo(const QPointF & pos) { double x = pos.x(); double y = pos.y(); #else void LogPlotZoomer::move(double x, double y) { #endif //QwtPlotZoomer::move(x,y); x = qwtMax(x, (double)zoomBase().left()); x = qwtMin(x, (double)(zoomBase().right() - zoomRect().width())); y = qwtMax(y, (double)zoomBase().top()); y = qwtMin(y, (double)(zoomBase().bottom() - zoomRect().height())); if (x != zoomRect().left() || y != zoomRect().top()) { //zoomStack()[zoomRectIndex()].moveTo(x, y); QwtDoubleRect & rect = const_cast<QwtDoubleRect &>(zoomStack()[zoomRectIndex()]); //handle x axis const int xAxis = QwtPlotZoomer::xAxis(); const QwtScaleEngine *sex = plot()->axisScaleEngine(xAxis); #if QWT_VERSION > 0x060000 if (dynamic_cast<const QwtLogScaleEngine*>(sex)) #else if (dynamic_cast<const QwtLog10ScaleEngine*>(sex)) #endif { //logarithmic double factor = rect.right() / rect.left(); rect.setRight(x * factor); rect.setLeft(x); } else { rect.moveLeft(x); } const int yAxis = QwtPlotZoomer::yAxis(); const QwtScaleEngine *sey = plot()->axisScaleEngine(yAxis); #if QWT_VERSION > 0x060000 if (dynamic_cast<const QwtLogScaleEngine*>(sey)) #else if (dynamic_cast<const QwtLog10ScaleEngine*>(sey)) #endif { //logarithmic double factor = rect.bottom() / rect.top(); rect.setBottom(y * factor); rect.setTop(y); } else { rect.moveTop(y); } //zoomStack()[zoomRectIndex()].moveTo(x, y); rescale(); } }
//! Update the widget that represents the curve on the legend void QwtPlotCurve::updateLegend(QwtLegend *legend) const { if ( !legend ) return; QwtPlotItem::updateLegend(legend); QWidget *widget = legend->find(this); if ( !widget || !widget->inherits("QwtLegendItem") ) return; QwtLegendItem *legendItem = (QwtLegendItem *)widget; #if QT_VERSION < 0x040000 const bool doUpdate = legendItem->isUpdatesEnabled(); #else const bool doUpdate = legendItem->updatesEnabled(); #endif legendItem->setUpdatesEnabled(false); const int policy = legend->displayPolicy(); if (policy == QwtLegend::FixedIdentifier) { int mode = legend->identifierMode(); if (mode & QwtLegendItem::ShowLine) legendItem->setCurvePen(pen()); if (mode & QwtLegendItem::ShowSymbol) legendItem->setSymbol(symbol()); if (mode & QwtLegendItem::ShowText) legendItem->setText(title()); else legendItem->setText(QwtText()); legendItem->setIdentifierMode(mode); } else if (policy == QwtLegend::AutoIdentifier) { int mode = 0; if (QwtPlotCurve::NoCurve != style()) { legendItem->setCurvePen(pen()); mode |= QwtLegendItem::ShowLine; } if (QwtSymbol::NoSymbol != symbol().style()) { legendItem->setSymbol(symbol()); mode |= QwtLegendItem::ShowSymbol; } if ( !title().isEmpty() ) { legendItem->setText(title()); mode |= QwtLegendItem::ShowText; } else { legendItem->setText(QwtText()); } legendItem->setIdentifierMode(mode); } legendItem->setUpdatesEnabled(doUpdate); legendItem->update(); }
//! Enables major grid, disables minor grid QwtPlotGrid::QwtPlotGrid(): QwtPlotItem( QwtText( "Grid" ) ) { d_data = new PrivateData; setZ( 10.0 ); }
//! Constructor QwtPlotCurve::QwtPlotCurve(): QwtPlotItem(QwtText()) { init(); }
/*! \brief Constructor Sets the following item attributes: - QwtPlotItem::AutoScale: true - QwtPlotItem::Legend: false \param title Title */ QwtPlotShapeItem::QwtPlotShapeItem( const QString& title ): QwtPlotItem( QwtText( title ) ) { init(); }
/*! Constructor \param title Title of the curve */ QwtPlotCurve::QwtPlotCurve( const QString &title ): QwtPlotSeriesItem<QPointF>( QwtText( title ) ) { init(); }
QwtText TimeScaleDraw::label(double v) const { return QwtText(QDateTime::fromMSecsSinceEpoch((quint64)v).toString(q_format)); }
void QwtPlotLayout::LayoutData::init( const QwtPlot *plot, const QRectF &rect ) { // legend if ( plot->plotLayout()->legendPosition() != QwtPlot::ExternalLegend && plot->legend() ) { legend.frameWidth = plot->legend()->frameWidth(); legend.vScrollBarWidth = plot->legend()->verticalScrollBar()->sizeHint().width(); legend.hScrollBarHeight = plot->legend()->horizontalScrollBar()->sizeHint().height(); const QSize hint = plot->legend()->sizeHint(); int w = qMin( hint.width(), ( int )rect.width() ); int h = plot->legend()->heightForWidth( w ); if ( h == 0 ) h = hint.height(); if ( h > rect.height() ) w += legend.vScrollBarWidth; legend.hint = QSize( w, h ); } // title title.frameWidth = 0; title.text = QwtText(); if ( plot->titleLabel() ) { const QwtTextLabel *label = plot->titleLabel(); title.text = label->text(); if ( !( title.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) ) title.text.setFont( label->font() ); title.frameWidth = plot->titleLabel()->frameWidth(); } // scales for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( plot->axisEnabled( axis ) ) { const QwtScaleWidget *scaleWidget = plot->axisWidget( axis ); scale[axis].isEnabled = true; scale[axis].scaleWidget = scaleWidget; scale[axis].scaleFont = scaleWidget->font(); scale[axis].start = scaleWidget->startBorderDist(); scale[axis].end = scaleWidget->endBorderDist(); scale[axis].baseLineOffset = scaleWidget->margin(); scale[axis].tickOffset = scaleWidget->margin(); if ( scaleWidget->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) ) { scale[axis].tickOffset += ( int )scaleWidget->scaleDraw()->maxTickLength(); } scale[axis].dimWithoutTitle = scaleWidget->dimForLength( QWIDGETSIZE_MAX, scale[axis].scaleFont ); if ( !scaleWidget->title().isEmpty() ) { scale[axis].dimWithoutTitle -= scaleWidget->titleHeightForWidth( QWIDGETSIZE_MAX ); } } else { scale[axis].isEnabled = false; scale[axis].start = 0; scale[axis].end = 0; scale[axis].baseLineOffset = 0; scale[axis].tickOffset = 0; scale[axis].dimWithoutTitle = 0; } } // canvas canvas.frameWidth = plot->canvas()->frameWidth(); }
//! Sets alignment to Qt::AlignCenter, and style to NoLine QwtPlotMarker::QwtPlotMarker(): QwtPlotItem(QwtText("Marker")) { d_data = new PrivateData; setZ(30.0); }
/*! Constructor \param parent Parent widget */ QwtPolarPlot::QwtPolarPlot( QWidget *parent ): QFrame( parent ) { initPlot( QwtText() ); }
/*! \brief Constructor Enables major and disables minor grid lines. The azimuth and right radial axis are visible. all other axes are hidden. Autoscaling is enabled. */ QwtPolarGrid::QwtPolarGrid(): QwtPolarItem( QwtText( "Grid" ) ) { d_data = new PrivateData; for ( int axisId = 0; axisId < QwtPolar::AxesCount; axisId++ ) { AxisData &axis = d_data->axisData[axisId]; switch ( axisId ) { case QwtPolar::AxisAzimuth: { axis.scaleDraw = new QwtRoundScaleDraw; axis.scaleDraw->setTickLength( QwtScaleDiv::MinorTick, 2 ); axis.scaleDraw->setTickLength( QwtScaleDiv::MediumTick, 2 ); axis.scaleDraw->setTickLength( QwtScaleDiv::MajorTick, 4 ); axis.isVisible = true; break; } case QwtPolar::AxisLeft: { QwtScaleDraw *scaleDraw = new QwtScaleDraw; scaleDraw->setAlignment( QwtScaleDraw::BottomScale ); axis.scaleDraw = scaleDraw; axis.isVisible = false; break; } case QwtPolar::AxisRight: { QwtScaleDraw *scaleDraw = new QwtScaleDraw; scaleDraw->setAlignment( QwtScaleDraw::BottomScale ); axis.scaleDraw = scaleDraw; axis.isVisible = true; break; } case QwtPolar::AxisTop: { QwtScaleDraw *scaleDraw = new QwtScaleDraw; scaleDraw->setAlignment( QwtScaleDraw::LeftScale ); axis.scaleDraw = scaleDraw; axis.isVisible = false; break; } case QwtPolar::AxisBottom: { QwtScaleDraw *scaleDraw = new QwtScaleDraw; scaleDraw->setAlignment( QwtScaleDraw::LeftScale ); axis.scaleDraw = scaleDraw; axis.isVisible = true; break; } default:; } } d_data->attributes = AutoScaling; d_data->displayFlags = 0; d_data->displayFlags |= SmartOriginLabel; d_data->displayFlags |= HideMaxRadiusLabel; d_data->displayFlags |= ClipAxisBackground; d_data->displayFlags |= SmartScaleDraw; d_data->displayFlags |= ClipGridLines; setZ( 10.0 ); #if QT_VERSION >= 0x040000 setRenderHint( RenderAntialiased, true ); #endif }
//! Constructor QwtPolarCurve::QwtPolarCurve(): QwtPolarItem( QwtText() ) { init(); }
/*! Interface for the designer plugin - does the same as setText() \sa plainText() */ void QwtTextLabel::setPlainText( const QString &text ) { setText( QwtText( text ) ); }
void CpintPlot::plot_CP_curve(CpintPlot *thisPlot, // the plot we're currently displaying double cp, double tau, double t0) { if (CPCurve) { delete CPCurve; CPCurve = NULL; } // if there's no cp, then there's nothing to do if (cp <= 0) return; // populate curve data with a CP curve const int curve_points = 100; double tmin = USE_T0_IN_CP_MODEL ? 1.0/60 : tau; double tmax = 180.0; QVector<double> cp_curve_power(curve_points); QVector<double> cp_curve_time(curve_points); int i; for (i = 0; i < curve_points; i ++) { double x = (double) i / (curve_points - 1); double t = pow(tmax, x) * pow(tmin, 1-x); cp_curve_time[i] = t; if (series == RideFile::none) //XXX this is ENERGY cp_curve_power[i] = (cp * t + cp * tau) * 60.0 / 1000.0; else cp_curve_power[i] = cp * (1 + tau / (t + t0)); } // generate a plot QString curve_title; #if USE_T0_IN_CP_MODEL curve_title.sprintf("CP=%.1f W; AWC/CP=%.2f m; t0=%.1f s", cp, tau, 60 * t0); #else if (series == RideFile::wattsKg) curve_title.sprintf("CP=%.2f W/kg; AWC=%.2f kJ/kg", cp, cp * tau * 60.0 / 1000.0); else curve_title.sprintf("CP=%.0f W; AWC=%.0f kJ", cp, cp * tau * 60.0 / 1000.0); #endif if (series == RideFile::watts || series == RideFile::wattsKg) curveTitle.setLabel(QwtText(curve_title, QwtText::PlainText)); if (series == RideFile::wattsKg) curveTitle.setYValue(0.6); else curveTitle.setYValue(20); CPCurve = new QwtPlotCurve(curve_title); if (appsettings->value(this, GC_ANTIALIAS, false).toBool() == true) CPCurve->setRenderHint(QwtPlotItem::RenderAntialiased); QPen pen(GColor(CCP)); pen.setWidth(appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble()); pen.setStyle(Qt::DashLine); CPCurve->setPen(pen); CPCurve->setData(cp_curve_time.data(), cp_curve_power.data(), curve_points); CPCurve->attach(thisPlot); }
/*! Constructor \param title Title of the curve */ QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString &title ): QwtPlotSeriesItem<QwtIntervalSample>( QwtText( title ) ) { init(); }
/*! Set a new title \param title Title \sa title() */ void QwtPlotItem::setTitle(const QString &title) { setTitle(QwtText(title)); }
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; }