void ColorMapEditor::setColorMap(const QwtLinearColorMap& map) { scaleColorsBox->setChecked(map.mode() == QwtLinearColorMap::ScaledColors); QwtArray <double> colors = map.colorStops(); int rows = (int)colors.size(); table->setRowCount(rows); table->blockSignals(true); for (int i = 0; i < rows; i++) { QwtDoubleInterval range = QwtDoubleInterval(min_val, max_val); double val = min_val + colors[i] * range.width(); QTableWidgetItem *it = new QTableWidgetItem(QString::number(val)); table->setItem(i, 0, it); QColor c = QColor(map.rgb(QwtDoubleInterval(0, 1), colors[i])); it = new QTableWidgetItem(c.name()); it->setFlags(Qt::ItemFlags(!Qt::ItemIsEditable)); it->setBackground(QBrush(c)); it->setForeground(QBrush(c)); table->setItem(i, 1, it); } table->blockSignals(false); color_map = map; }
static QwtArray<QwtPicker *> activePickers(QWidget *w) { QwtArray<QwtPicker *> pickers; #if QT_VERSION >= 0x040000 QObjectList children = w->children(); for ( int i = 0; i < children.size(); i++ ) { QObject *obj = children[i]; if ( obj->inherits("QwtPicker") ) { QwtPicker *picker = (QwtPicker *)obj; if ( picker->isEnabled() ) pickers += picker; } } #else QObjectList *children = (QObjectList *)w->children(); if ( children ) { for ( QObjectListIterator it(*children); it.current(); ++it ) { QObject *obj = (QObject *)it.current(); if ( obj->inherits("QwtPicker") ) { QwtPicker *picker = (QwtPicker *)obj; if ( picker->isEnabled() ) { pickers.resize(pickers.size() + 1); pickers[int(pickers.size()) - 1] = picker; } } } } #endif return pickers; }
void Matrix::save(const QString &fn, const QString &info, bool saveAsTemplate) { QFile f(fn); if (!f.isOpen()){ if (!f.open(QIODevice::Append)) return; } bool notTemplate = !saveAsTemplate; QTextStream t( &f ); t.setEncoding(QTextStream::UnicodeUTF8); t << "<matrix>\n"; if (notTemplate) t << QString(objectName()) + "\t"; t << QString::number(numRows())+"\t"; t << QString::number(numCols())+"\t"; if (notTemplate) t << birthDate() + "\n"; t << info; t << "ColWidth\t" + QString::number(d_column_width)+"\n"; t << "<formula>\n" + formula_str + "\n</formula>\n"; t << "TextFormat\t" + QString(txt_format) + "\t" + QString::number(num_precision) + "\n"; if (notTemplate) t << "WindowLabel\t" + windowLabel() + "\t" + QString::number(captionPolicy()) + "\n"; t << "Coordinates\t" + QString::number(x_start,'g',15) + "\t" +QString::number(x_end,'g',15) + "\t"; t << QString::number(y_start,'g',15) + "\t" + QString::number(y_end,'g',15) + "\n"; t << "ViewType\t" + QString::number((int)d_view_type) + "\n"; t << "HeaderViewType\t" + QString::number((int)d_header_view_type) + "\n"; if (d_color_map_type != Custom) t << "ColorPolicy\t" + QString::number(d_color_map_type) + "\n"; else { t << "<ColorMap>\n"; t << "\t<Mode>" + QString::number(d_color_map.mode()) + "</Mode>\n"; t << "\t<MinColor>" + d_color_map.color1().name() + "</MinColor>\n"; t << "\t<MaxColor>" + d_color_map.color2().name() + "</MaxColor>\n"; QwtArray <double> colors = d_color_map.colorStops(); int stops = (int)colors.size(); t << "\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n"; for (int i = 1; i < stops - 1; i++){ t << "\t<Stop>" + QString::number(colors[i]) + "\t"; t << QColor(d_color_map.rgb(QwtDoubleInterval(0,1), colors[i])).name(); t << "</Stop>\n"; } t << "</ColorMap>\n"; } if (notTemplate) t << d_matrix_model->saveToString(); t <<"</matrix>\n"; }
QString Spectrogram::saveToString() { QString s = "<spectrogram>\n"; s += "\t<matrix>" + QString(d_matrix->objectName()) + "</matrix>\n"; if (color_map_policy != Custom) s += "\t<ColorPolicy>" + QString::number(color_map_policy) + "</ColorPolicy>\n"; else { s += "\t<ColorMap>\n"; s += "\t\t<Mode>" + QString::number(color_map.mode()) + "</Mode>\n"; s += "\t\t<MinColor>" + color_map.color1().name() + "</MinColor>\n"; s += "\t\t<MaxColor>" + color_map.color2().name() + "</MaxColor>\n"; QwtArray <double> colors = color_map.colorStops(); int stops = (int)colors.size(); s += "\t\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n"; for (int i = 1; i < stops - 1; i++) { s += "\t\t<Stop>" + QString::number(colors[i]) + "\t"; s += QColor(color_map.rgb(QwtDoubleInterval(0,1), colors[i])).name(); s += "</Stop>\n"; } s += "\t</ColorMap>\n"; } s += "\t<Image>"+QString::number(testDisplayMode(QwtPlotSpectrogram::ImageMode))+"</Image>\n"; bool contourLines = testDisplayMode(QwtPlotSpectrogram::ContourMode); s += "\t<ContourLines>"+QString::number(contourLines)+"</ContourLines>\n"; if (contourLines) { s += "\t\t<Levels>"+QString::number(levels())+"</Levels>\n"; bool defaultPen = defaultContourPen().style() != Qt::NoPen; s += "\t\t<DefaultPen>"+QString::number(defaultPen)+"</DefaultPen>\n"; if (defaultPen) { s += "\t\t\t<PenColor>"+defaultContourPen().color().name()+"</PenColor>\n"; s += "\t\t\t<PenWidth>"+QString::number(defaultContourPen().widthF())+"</PenWidth>\n"; s += "\t\t\t<PenStyle>"+QString::number(defaultContourPen().style() - 1)+"</PenStyle>\n"; } } QwtScaleWidget *colorAxis = plot()->axisWidget(color_axis); if (colorAxis && colorAxis->isColorBarEnabled()) { s += "\t<ColorBar>\n\t\t<axis>" + QString::number(color_axis) + "</axis>\n"; s += "\t\t<width>" + QString::number(colorAxis->colorBarWidth()) + "</width>\n"; s += "\t</ColorBar>\n"; } s += "\t<Visible>"+ QString::number(isVisible()) + "</Visible>\n"; return s+"</spectrogram>\n"; }
QString ColorMapEditor::saveToXmlString(const QwtLinearColorMap &color_map) { QString s = "<ColorMap>\n"; s += "\t<Mode>" + QString::number(color_map.mode()) + "</Mode>\n"; s += "\t<MinColor>" + color_map.color1().name() + "</MinColor>\n"; s += "\t<MaxColor>" + color_map.color2().name() + "</MaxColor>\n"; QwtArray<double> colors = color_map.colorStops(); int stops = (int)colors.size(); s += "\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n"; for (int i = 1; i < stops - 1; i++) { s += "\t<Stop>" + QString::number(colors[i]) + "\t"; s += QColor(color_map.rgb(QwtDoubleInterval(0, 1), colors[i])).name(); s += "</Stop>\n"; } return s += "</ColorMap>\n"; }
/*! Handle a mouse press event for the observed widget. \param me Mouse event \sa eventFilter(), widgetMouseReleaseEvent(), widgetMouseMoveEvent(), */ void QwtPanner::widgetMousePressEvent(QMouseEvent *me) { if ( me->button() != d_data->button ) return; QWidget *w = parentWidget(); if ( w == NULL ) return; #if QT_VERSION < 0x040000 if ( (me->state() & Qt::KeyButtonMask) != (d_data->buttonState & Qt::KeyButtonMask) ) #else if ( (me->modifiers() & Qt::KeyboardModifierMask) != (int)(d_data->buttonState & Qt::KeyboardModifierMask) ) #endif { return; } #ifndef QT_NO_CURSOR showCursor(true); #endif d_data->initialPos = d_data->pos = me->pos(); QRect cr = parentWidget()->rect(); if ( parentWidget()->inherits("QFrame") ) { const QFrame* frame = (QFrame*)parentWidget(); cr = frame->contentsRect(); } setGeometry(cr); // We don't want to grab the picker ! QwtArray<QwtPicker *> pickers = activePickers(parentWidget()); for ( int i = 0; i < (int)pickers.size(); i++ ) pickers[i]->setEnabled(false); d_data->pixmap = QPixmap::grabWidget(parentWidget(), cr.x(), cr.y(), cr.width(), cr.height()); for ( int i = 0; i < (int)pickers.size(); i++ ) pickers[i]->setEnabled(true); show(); }
QString LinearColorMap::toXmlString() { QString s = "<ColorMap>\n"; s += "\t<Mode>" + QString::number(mode()) + "</Mode>\n"; s += "\t<MinColor>" + color1().name() + "</MinColor>\n"; s += "\t<MaxColor>" + color2().name() + "</MaxColor>\n"; if (d_range.isValid()) s += "\t<Range>" + QString::number(d_range.minValue(), 'g', 15) + "\t" + QString::number(d_range.maxValue(), 'g', 15) + "</Range>\n"; QwtArray <double> colors = colorStops(); int stops = (int)colors.size(); s += "\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n"; for (int i = 1; i < stops - 1; i++){ s += "\t<Stop>" + QString::number(colors[i], 'g', 15) + "\t"; s += color(i).name(); s += "</Stop>\n"; } return s += "</ColorMap>\n"; }
QString Matrix::saveToString(const QString &info, bool saveAsTemplate) { bool notTemplate = !saveAsTemplate; QString s = "<matrix>\n"; if (notTemplate) s += QString(objectName()) + "\t"; s += QString::number(numRows())+"\t"; s += QString::number(numCols())+"\t"; if (notTemplate) s += birthDate() + "\n"; s += info; s += "ColWidth\t" + QString::number(d_column_width)+"\n"; s += "<formula>\n" + formula_str + "\n</formula>\n"; s += "TextFormat\t" + QString(txt_format) + "\t" + QString::number(num_precision) + "\n"; if (notTemplate) s += "WindowLabel\t" + windowLabel() + "\t" + QString::number(captionPolicy()) + "\n"; s += "Coordinates\t" + QString::number(x_start,'g',15) + "\t" +QString::number(x_end,'g',15) + "\t"; s += QString::number(y_start,'g',15) + "\t" + QString::number(y_end,'g',15) + "\n"; s += "ViewType\t" + QString::number((int)d_view_type) + "\n"; s += "HeaderViewType\t" + QString::number((int)d_header_view_type) + "\n"; if (d_color_map_type != Custom) s += "ColorPolicy\t" + QString::number(d_color_map_type) + "\n"; else { s += "<ColorMap>\n"; s += "\t<Mode>" + QString::number(d_color_map.mode()) + "</Mode>\n"; s += "\t<MinColor>" + d_color_map.color1().name() + "</MinColor>\n"; s += "\t<MaxColor>" + d_color_map.color2().name() + "</MaxColor>\n"; QwtArray <double> colors = d_color_map.colorStops(); int stops = (int)colors.size(); s += "\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n"; for (int i = 1; i < stops - 1; i++){ s += "\t<Stop>" + QString::number(colors[i]) + "\t"; s += QColor(d_color_map.rgb(QwtDoubleInterval(0,1), colors[i])).name(); s += "</Stop>\n"; } s += "</ColorMap>\n"; } if (notTemplate) s += d_matrix_model->saveToString(); s +="</matrix>\n"; return s; }
void ColorMapEditor::setColorMap(const QwtLinearColorMap& map) { scaleColorsBox->setChecked(map.mode() == QwtLinearColorMap::ScaledColors); QwtArray <double> colors = map.colorStops(); int rows = (int)colors.size(); table->setRowCount(rows); table->blockSignals(true); QwtDoubleInterval range = QwtDoubleInterval(min_val, max_val); for (int i = 0; i < rows; i++){ DoubleSpinBox *sb = new DoubleSpinBox(); sb->setLocale(d_locale); sb->setDecimals(d_precision); sb->setValue(min_val + colors[i] * range.width()); if (i == 0) sb->setRange(min_val, min_val); else if (i == rows -1) sb->setRange(max_val, max_val); else sb->setRange(min_val, max_val); connect(sb, SIGNAL(valueChanged(double)), this, SLOT(updateColorMap())); connect(sb, SIGNAL(activated(DoubleSpinBox *)), this, SLOT(spinBoxActivated(DoubleSpinBox *))); table->setCellWidget(i, 0, sb); QColor c = QColor(map.rgb(QwtDoubleInterval(0, 1), colors[i])); QTableWidgetItem *it = new QTableWidgetItem(c.name()); // Avoid compiler warning //#ifdef Q_CC_MSVC it->setFlags(it->flags() & (~Qt::ItemIsEditable)); //#else // it->setFlags(!Qt::ItemIsEditable); //#endif it->setBackground(QBrush(c)); it->setForeground(QBrush(c)); table->setItem(i, 1, it); } table->blockSignals(false); color_map = map; }
/*! Draw circles \param painter Painter \param canvasRect Contents rect of the canvas in painter coordinates \param pole Position of the pole in painter coordinates \param radialMap Maps radius values into painter coordinates. \param values Radial values, indicating the distances from the pole */ void QwtPolarGrid::drawCircles( QPainter *painter, const QwtDoubleRect &canvasRect, const QwtDoublePoint &pole, const QwtScaleMap &radialMap, const QwtValueList &values ) const { for ( int i = 0; i < int( values.size() ); i++ ) { const double val = values[i]; const GridData &gridData = d_data->gridData[QwtPolar::Radius]; bool skipLine = false; if ( testDisplayFlag( SmartScaleDraw ) ) { const AxisData &axis = d_data->axisData[QwtPolar::AxisAzimuth]; if ( axis.isVisible && axis.scaleDraw->hasComponent( QwtAbstractScaleDraw::Backbone ) ) { #if QWT_VERSION < 0x050200 if ( isClose( val, gridData.scaleDiv.hBound() ) ) #else if ( isClose( val, gridData.scaleDiv.upperBound() ) ) #endif skipLine = true; } } #if QWT_VERSION < 0x050200 if ( isClose( val, gridData.scaleDiv.lBound() ) ) #else if ( isClose( val, gridData.scaleDiv.lowerBound() ) ) #endif skipLine = true; if ( !skipLine ) { const double radius = radialMap.transform( val ); QwtDoubleRect outerRect( 0, 0, 2 * radius, 2 * radius ); outerRect.moveCenter( pole ); #if QT_VERSION < 0x040000 QwtPainter::drawEllipse( painter, outerRect.toRect() ); #else if ( testDisplayFlag( ClipGridLines ) ) { /* Qt4 is horrible slow, when painting primitives, with coordinates far outside the visible area. We need to clip. */ const QwtArray<QwtDoubleInterval> angles = QwtClipper::clipCircle( canvasRect, pole, radius ); for ( int i = 0; i < angles.size(); i++ ) { const QwtDoubleInterval intv = angles[i]; if ( intv.minValue() == 0 && intv.maxValue() == 2 * M_PI ) QwtPainter::drawEllipse( painter, outerRect.toRect() ); else { const double from = intv.minValue() / M_PI * 180; const double to = intv.maxValue() / M_PI * 180; double span = to - from; if ( span < 0.0 ) span += 360.0; const QwtMetricsMap &mm = QwtPainter::metricsMap(); const QRect r = outerRect.toRect(); painter->drawArc( mm.layoutToDevice( r, painter ), qRound( from * 16 ), qRound( span * 16 ) ); } } } else { QwtPainter::drawEllipse( painter, outerRect.toRect() ); } #endif } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void StatsGenODFWidget::on_m_CalculateODFBtn_clicked() { int err = 0; QwtArray<float> e1s; QwtArray<float> e2s; QwtArray<float> e3s; QwtArray<float> weights; QwtArray<float> sigmas; QwtArray<float> odf; SGODFTableModel* tableModel = NULL; if(weightSpreadGroupBox->isChecked() ) { tableModel = m_ODFTableModel; } else { tableModel = m_OdfBulkTableModel; } e1s = tableModel->getData(SGODFTableModel::Euler1); e2s = tableModel->getData(SGODFTableModel::Euler2); e3s = tableModel->getData(SGODFTableModel::Euler3); weights = tableModel->getData(SGODFTableModel::Weight); sigmas = tableModel->getData(SGODFTableModel::Sigma); // Convert from Degrees to Radians for(int i = 0; i < e1s.size(); i++) { e1s[i] = e1s[i] * M_PI / 180.0; e2s[i] = e2s[i] * M_PI / 180.0; e3s[i] = e3s[i] * M_PI / 180.0; } size_t numEntries = e1s.size(); int imageSize = pfImageSize->value(); int lamberSize = pfLambertSize->value(); int numColors = 16; int npoints = pfSamplePoints->value(); QVector<size_t> dims(1, 3); FloatArrayType::Pointer eulers = FloatArrayType::CreateArray(npoints, dims, "Eulers"); PoleFigureConfiguration_t config; QVector<UInt8ArrayType::Pointer> figures; if ( Ebsd::CrystalStructure::Cubic_High == m_CrystalStructure) { // We now need to resize all the arrays here to make sure they are all allocated odf.resize(CubicOps::k_OdfSize); Texture::CalculateCubicODFData(e1s.data(), e2s.data(), e3s.data(), weights.data(), sigmas.data(), true, odf.data(), numEntries); err = StatsGen::GenCubicODFPlotData(odf.data(), eulers->getPointer(0), npoints); CubicOps ops; config.eulers = eulers.get(); config.imageDim = imageSize; config.lambertDim = lamberSize; config.numColors = numColors; figures = ops.generatePoleFigure(config); } else if ( Ebsd::CrystalStructure::Hexagonal_High == m_CrystalStructure) { // We now need to resize all the arrays here to make sure they are all allocated odf.resize(HexagonalOps::k_OdfSize); Texture::CalculateHexODFData(e1s.data(), e2s.data(), e3s.data(), weights.data(), sigmas.data(), true, odf.data(), numEntries); err = StatsGen::GenHexODFPlotData(odf.data(), eulers->getPointer(0), npoints); HexagonalOps ops; config.eulers = eulers.get(); config.imageDim = imageSize; config.lambertDim = lamberSize; config.numColors = numColors; figures = ops.generatePoleFigure(config); } else if ( Ebsd::CrystalStructure::OrthoRhombic == m_CrystalStructure) { // // We now need to resize all the arrays here to make sure they are all allocated odf.resize(OrthoRhombicOps::k_OdfSize); Texture::CalculateOrthoRhombicODFData(e1s.data(), e2s.data(), e3s.data(), weights.data(), sigmas.data(), true, odf.data(), numEntries); err = StatsGen::GenOrthoRhombicODFPlotData(odf.data(), eulers->getPointer(0), npoints); OrthoRhombicOps ops; config.eulers = eulers.get(); config.imageDim = imageSize; config.lambertDim = lamberSize; config.numColors = numColors; figures = ops.generatePoleFigure(config); } if (err == 1) { //TODO: Present Error Message return; } QImage image = PoleFigureImageUtilities::Create3ImagePoleFigure(figures[0].get(), figures[1].get(), figures[2].get(), config, imageLayout->currentIndex()); m_PoleFigureLabel->setPixmap(QPixmap::fromImage(image)); // Enable the MDF tab if (m_MDFWidget != NULL) { m_MDFWidget->setEnabled(true); m_MDFWidget->updateMDFPlot(odf); } }
void QgsHistogramWidget::drawHistogram() { if ( !mVectorLayer || mSourceFieldExp.isEmpty() ) return; QApplication::setOverrideCursor( Qt::WaitCursor ); if ( mValues.empty() ) { bool ok; mValues = mVectorLayer->getDoubleValues( mSourceFieldExp, ok ); if ( ! ok ) { QApplication::restoreOverrideCursor(); return; } qSort( mValues.begin(), mValues.end() ); mHistogram.setValues( mValues ); mBinsSpinBox->blockSignals( true ); mBinsSpinBox->setValue( qMax( mHistogram.optimalNumberBins(), 30 ) ); mBinsSpinBox->blockSignals( false ); mStats.setStatistics( QgsStatisticalSummary::StDev ); mStats.calculate( mValues ); } // clear plot mpPlot->detachItems(); //ensure all children get removed mpPlot->setAutoDelete( true ); // Set axis titles mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr( "Value" ) ); mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr( "Count" ) ); mpPlot->setAxisAutoScale( QwtPlot::yLeft ); mpPlot->setAxisAutoScale( QwtPlot::xBottom ); // add a grid QwtPlotGrid * grid = new QwtPlotGrid(); grid->enableX( false ); grid->setPen( mGridPen ); grid->attach( mpPlot ); // make colors list mHistoColors.clear(); foreach ( QgsRendererRangeV2 range, mRanges ) { mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black ); } //draw histogram #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 QwtPlotHistogram * plotHistogram = 0; plotHistogram = createPlotHistogram( mRanges.count() > 0 ? mRanges.at( 0 ).label() : QString(), mRanges.count() > 0 ? QBrush( mHistoColors.at( 0 ) ) : mBrush, mRanges.count() > 0 ? Qt::NoPen : mPen ); #else HistogramItem *plotHistogramItem = 0; plotHistogramItem = createHistoItem( mRanges.count() > 0 ? mRanges.at( 0 ).label() : QString(), mRanges.count() > 0 ? QBrush( mHistoColors.at( 0 ) ) : mBrush, mRanges.count() > 0 ? Qt::NoPen : mPen ); #endif #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 QVector<QwtIntervalSample> dataHisto; #else // we safely assume that QT>=4.0 (min version is 4.7), therefore QwtArray is a QVector, so don't set size here QwtArray<QwtDoubleInterval> intervalsHisto; QwtArray<double> valuesHisto; #endif int bins = mBinsSpinBox->value(); QList<double> edges = mHistogram.binEdges( bins ); QList<int> counts = mHistogram.counts( bins ); int rangeIndex = 0; int lastValue = 0; for ( int bin = 0; bin < bins; ++bin ) { int binValue = counts.at( bin ); //current bin crosses two graduated ranges, so we split between //two histogram items if ( rangeIndex < mRanges.count() - 1 && edges.at( bin ) > mRanges.at( rangeIndex ).upperValue() ) { rangeIndex++; #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 plotHistogram->setSamples( dataHisto ); plotHistogram->attach( mpPlot ); plotHistogram = createPlotHistogram( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) ); dataHisto.clear(); dataHisto << QwtIntervalSample( lastValue, mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) ); #else plotHistogramItem->setData( QwtIntervalData( intervalsHisto, valuesHisto ) ); plotHistogramItem->attach( mpPlot ); plotHistogramItem = createHistoItem( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) ); intervalsHisto.clear(); valuesHisto.clear(); intervalsHisto.append( QwtDoubleInterval( mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) ) ); valuesHisto.append( lastValue ); #endif } double upperEdge = mRanges.count() > 0 ? qMin( edges.at( bin + 1 ), mRanges.at( rangeIndex ).upperValue() ) : edges.at( bin + 1 ); #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge ); #else intervalsHisto.append( QwtDoubleInterval( edges.at( bin ), upperEdge ) ); valuesHisto.append( double( binValue ) ); #endif lastValue = binValue; } #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 plotHistogram->setSamples( dataHisto ); plotHistogram->attach( mpPlot ); #else plotHistogramItem->setData( QwtIntervalData( intervalsHisto, valuesHisto ) ); plotHistogramItem->attach( mpPlot ); #endif mRangeMarkers.clear(); foreach ( QgsRendererRangeV2 range, mRanges ) { QwtPlotMarker* rangeMarker = new QwtPlotMarker(); rangeMarker->attach( mpPlot ); rangeMarker->setLineStyle( QwtPlotMarker::VLine ); rangeMarker->setXValue( range.upperValue() ); rangeMarker->setLabel( QString::number( range.upperValue() ) ); rangeMarker->setLabelOrientation( Qt::Vertical ); rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop ); rangeMarker->show(); mRangeMarkers << rangeMarker; }
void 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 PfPvPlot::setData(RideItem *_rideItem) { rideItem = _rideItem; RideFile *ride = rideItem->ride; if (ride) { setTitle(ride->startTime().toString(GC_DATETIME_FORMAT)); // quickly erase old data curve->setVisible(false); // handle zone stuff refreshZoneItems(); // 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; 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; dataSet.insert(std::make_pair<double, double>(aepf, cpv)); tot_cad += p1->cad; tot_cad_points++; } } if (tot_cad_points == 0) { setTitle("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; } setCAD(tot_cad / tot_cad_points); curve->setData(cpvArray, aepfArray); // now show the data (zone shading would already be visible) curve->setVisible(true); } } else {