DataPlot::DataPlot(QWidget *parent, TelemetryStateReceiver* collector, OdometryStateReceiver* odometryReceiver,QMap<QString, QStringList> *list) : QwtPlot(parent), d_interval(0), d_timerId(-1) { node=collector; odom_receiver=odometryReceiver; connect_status=false; QObject::connect( node, SIGNAL( parameterReceived( )), this, SLOT( onParameterReceived( ))); data_count=0; posicionBuffer=PLOT_SIZE; colors_list <<"red"<<"blue"<<"green"<<"black"<<"yellow"<<"magenta"<<"cyan"<<"gray"<<"darkCyan"<<"darkMagenta"<<"darkYellow"<<"darkGray"<<"darkRed"<<"darkBlue"<<"darkGreen"<<"lightGray" <<"red"<<"blue"<<"green"<<"black"<<"yellow"<<"magenta"<<"cyan"<<"gray"<<"darkCyan"<<"darkMagenta"<<"darkYellow"<<"darkGray"<<"darkRed"<<"darkBlue"<<"darkGreen"<<"lightGray" <<"red"<<"blue"<<"green"<<"black"<<"yellow"<<"magenta"<<"cyan"<<"gray"<<"darkCyan"<<"darkMagenta"<<"darkYellow"<<"darkGray"<<"darkRed"<<"darkBlue"<<"darkGreen"<<"lightGray" <<"red"<<"blue"<<"green"<<"black"<<"yellow"<<"magenta"<<"cyan"<<"gray"<<"darkCyan"<<"darkMagenta"<<"darkYellow"<<"darkGray"<<"darkRed"<<"darkBlue"<<"darkGreen"<<"lightGray"; iterator_colors=0; is_stop_pressed=false; alignScales(); setAutoReplot(false); parameters_list = setCurveLabels(*list); current_min_limit=0; current_max_limit=0; QwtPlotZoomer* zoomer = new MyZoomer(canvas()); QwtPlotPanner *panner = new QwtPlotPanner(canvas()); panner->setAxisEnabled(QwtPlot::yRight, true); panner->setMouseButton(Qt::MidButton); // Avoid jumping when labels with more/less digits // appear/disappear when scrolling vertically const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font()); QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft); sd->setMinimumExtent( fm.width("100.00") ); const QColor c(Qt::darkBlue); zoomer->setRubberBandPen(c); zoomer->setTrackerPen(c); setGridPlot(); initTimeData(); #if 0 // Insert zero line at y = 0 QwtPlotMarker *mY = new QwtPlotMarker(); mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop); mY->setLineStyle(QwtPlotMarker::HLine); mY->setYValue(0.0); mY->attach(this); #endif initAxisX(); initAxisY(); initCurves(); setTimerInterval(1000);// 1 second = 1000 }
/*! Change the number format for the major scale of a selected axis \param axis axis index \param f format \param prec precision */ void Plot::setAxisLabelFormat(int axis, char f, int prec) { if (axisValid(axis)) { ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); sd->setLabelFormat(f, prec); } }
int Plot::axisLabelFormat(int axis) { if (axisValid(axis)){ ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); return sd->labelNumericFormat(); } return 0; }
Plot::Plot( QWidget *parent ): QwtPlot( parent ), d_formatType( 0 ), d_alpha(255) { d_spectrogram = new QwtPlotSpectrogram(); d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache ); QList<double> contourLevels; for ( double level = 0.5; level < 10.0; level += 1.0 ) contourLevels += level; d_spectrogram->setContourLevels( contourLevels ); d_spectrogram->setData( new SpectrogramData() ); d_spectrogram->attach( this ); const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis ); // A color bar on the right axis QwtScaleWidget *rightAxis = axisWidget( QwtPlot::yRight ); rightAxis->setTitle( "Intensity" ); rightAxis->setColorBarEnabled( true ); setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() ); enableAxis( QwtPlot::yRight ); plotLayout()->setAlignCanvasToScales( true ); setColorMap( Plot::RGBMap ); // LeftButton for the zooming // MidButton for the panning // RightButton: zoom out by 1 // Ctrl+RighButton: zoom out to full size QwtPlotZoomer* zoomer = new MyZoomer( canvas() ); zoomer->setMousePattern( QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier ); zoomer->setMousePattern( QwtEventPattern::MouseSelect3, Qt::RightButton ); QwtPlotPanner *panner = new QwtPlotPanner( canvas() ); panner->setAxisEnabled( QwtPlot::yRight, false ); panner->setMouseButton( Qt::MidButton ); // Avoid jumping when labels with more/less digits // appear/disappear when scrolling vertically const QFontMetrics fm( axisWidget( QwtPlot::yLeft )->font() ); QwtScaleDraw *sd = axisScaleDraw( QwtPlot::yLeft ); sd->setMinimumExtent( fm.width( "100.00" ) ); const QColor c( Qt::darkBlue ); zoomer->setRubberBandPen( c ); zoomer->setTrackerPen( c ); }
void Plot::drawItems (QPainter *painter, const QRect &rect, const QwtScaleMap map[axisCnt], const QwtPlotPrintFilter &pfilter) const { painter->save(); painter->setRenderHint(QPainter::Antialiasing); for (int i=0; i<QwtPlot::axisCnt; i++){ if (!axisEnabled(i)) continue; drawBreak(painter, rect, map[i], i); } painter->restore(); for (int i=0; i<QwtPlot::axisCnt; i++){ if (!axisEnabled(i)) continue; const ScaleEngine *sc_engine = (const ScaleEngine *)axisScaleEngine(i); /*const QwtScaleEngine *qwtsc_engine=axisScaleEngine(i); const ScaleEngine *sc_engine =dynamic_cast<const ScaleEngine*>(qwtsc_engine); if(sc_engine!=NULL) { */ if (!sc_engine->hasBreak()) continue; QwtScaleMap m = map[i]; int lb = m.transform(sc_engine->axisBreakLeft()); int rb = m.transform(sc_engine->axisBreakRight()); int start = lb, end = rb; if (sc_engine->testAttribute(QwtScaleEngine::Inverted)){ end = lb; start = rb; } QRegion cr(rect); if (i == QwtPlot::xBottom || i == QwtPlot::xTop) painter->setClipRegion(cr.subtracted(QRegion(start, rect.y(), abs(end - start), rect.height())), Qt::IntersectClip); else if (i == QwtPlot::yLeft || i == QwtPlot::yRight) painter->setClipRegion(cr.subtracted(QRegion(rect.x(), end, rect.width(), abs(end - start))), Qt::IntersectClip); //} } QwtPlot::drawItems(painter, rect, map, pfilter); for (int i=0; i<QwtPlot::axisCnt; i++){ if (!axisEnabled(i)) continue; const ScaleDraw *sd = (const ScaleDraw *) axisScaleDraw (i); int majorTicksType = sd->majorTicksStyle(); int minorTicksType = sd->minorTicksStyle(); bool min = (minorTicksType == ScaleDraw::In || minorTicksType == ScaleDraw::Both); bool maj = (majorTicksType == ScaleDraw::In || majorTicksType == ScaleDraw::Both); if (min || maj) drawInwardTicks(painter, rect, map[i], i, min, maj); } }
/** @return the number format for the major scale labels of a specified axis @param axis :: axis index @retval f format character @retval prec precision */ void Plot::axisLabelFormat(int axis, char &f, int &prec) const { if (axisValid(axis)){ const ScaleDraw *sd = (const ScaleDraw *)axisScaleDraw (axis); sd->labelFormat(f, prec); } else {//for a bad call we return the default values f = 'g'; prec = 4; } }
PlotZoz::PlotZoz(QWidget *) { // Прозрачность полотна QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setFrameStyle(QFrame::NoFrame); canvas->setPaintAttribute(QwtPlotCanvas::BackingStore, false); canvas->setPaintAttribute(QwtPlotCanvas::Opaque, false); canvas->setAttribute(Qt::WA_OpaquePaintEvent, false); canvas->setAutoFillBackground( false ); setCanvas(canvas); plotLayout()->setAlignCanvasToScales(true); // Отключаем щкалы деления for (int i=0; i<QwtPlot::axisCnt; i++) { axisScaleDraw(i)->enableComponent(QwtScaleDraw::Ticks, false); axisScaleDraw(i)->enableComponent(QwtScaleDraw::Backbone, false); } pltSpectrogram = new PlotSpectr(); pltRasterData = new PlotRasterData(); pltGrid = new QwtPlotGrid; pltGrid->enableXMin(true); // разрешаем отображение линий сетки, соответствующих вспомогательным делениям нижней шкалы pltGrid->enableYMin(true); // разрешаем отображение линий сетки, соответствующих вспомогательным делениям нижней шкалы pltGrid->setMajorPen(QPen(Qt::gray,0,Qt::DotLine)); // черный для основных делений pltGrid->setMinorPen(QPen(Qt::gray,0,Qt::DotLine)); // серый для вспомогательных pltGrid->attach(this); setAxisMaxMajor(0,20); setAxisMaxMinor(0,0); setAxisMaxMajor(1,20); setAxisMaxMinor(1,0); setAxisMaxMajor(2,20); setAxisMaxMinor(2,0); setAxisMaxMajor(3,20); setAxisMaxMinor(3,0); canvas->setCursor(Qt::ArrowCursor); setMouseTracking(true); for (int i=0; i<QwtPlot::axisCnt; i++) axisWidget(i)->setMouseTracking(true); }
int Plot::axisLabelPrecision(int axis) { if (axisValid(axis)) { ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); return sd->labelNumericPrecision(); } //for a bad call we return the default values return 4; }
Spectrogramplot::Spectrogramplot(int numDataPoints, int numRows, QWidget *parent) :QwtPlot(parent) ,nData_(numDataPoints) ,nRows_(numRows) { spectrogram_ = new QwtPlotSpectrogram(); spectrogram_->setRenderThreadCount(0); // set system specific thread count data_ = new WaterfallData(nData_, nRows_); spectrogram_->attach(this); setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine); setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine); axisScaleEngine(QwtPlot::xBottom)->setAttribute(QwtScaleEngine::Floating,true); axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Floating,true); spectrogram_->setColorMap(new ColorMap()); spectrogram_->setData(data_); setXAxisRange(0, nData_); setYAxisRange(0, nRows_); setZAxisScale(-1,1); // LeftButton for the zooming // MidButton for the panning // RightButton: zoom out by 1 // Ctrl+RighButton: zoom out to full size zoomer_ = new MyZoomer(qobject_cast<QwtPlotCanvas*>(canvas())); zoomer_->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton); zoomer_->setMousePattern(QwtEventPattern::MouseSelect2, Qt::LeftButton, Qt::ControlModifier); panner_ = new QwtPlotPanner(canvas()); panner_->setAxisEnabled(QwtPlot::yRight, false); panner_->setMouseButton(Qt::RightButton); magnifier_ = new QwtPlotMagnifier(canvas()); magnifier_->setMouseButton(Qt::NoButton); // Avoid jumping when labels with more/less digits // appear/disappear when scrolling vertically const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font()); QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft); sd->setMinimumExtent( fm.width("100.00") ); const QColor c(Qt::darkBlue); zoomer_->setRubberBandPen(c); zoomer_->setTrackerPen(c); }
void BarChart::setOrientation( int orientation ) { QwtPlot::Axis axis1, axis2; if ( orientation == 0 ) { axis1 = QwtPlot::xBottom; axis2 = QwtPlot::yLeft; d_barChartItem->setOrientation( Qt::Vertical ); } else { axis1 = QwtPlot::yLeft; axis2 = QwtPlot::xBottom; d_barChartItem->setOrientation( Qt::Horizontal ); } //设置坐标轴的min max和step setAxisScale( axis1, 0, d_barChartItem->dataSize() - 1, 1.0 ); setAxisAutoScale( axis2 ); QwtScaleDraw *scaleDraw1 = axisScaleDraw( axis1 ); scaleDraw1->enableComponent( QwtScaleDraw::Backbone, false ); scaleDraw1->enableComponent( QwtScaleDraw::Ticks, false ); QwtScaleDraw *scaleDraw2 = axisScaleDraw( axis2 ); scaleDraw2->enableComponent( QwtScaleDraw::Backbone, true ); scaleDraw2->enableComponent( QwtScaleDraw::Ticks, true ); plotLayout()->setAlignCanvasToScale( axis1, true ); plotLayout()->setAlignCanvasToScale( axis2, false ); plotLayout()->setCanvasMargin( 0 ); updateCanvasMargins(); replot(); }
QValueList <int> Plot::getMinorTicksType() { QValueList <int> minorTicksType; for (int axis=0; axis<QwtPlot::axisCnt; axis++) { if (axisEnabled(axis)) { ScaleDraw *sd = (ScaleDraw *) axisScaleDraw (axis); minorTicksType << sd->minorTicksStyle(); } else minorTicksType << ScaleDraw::Out; } return minorTicksType; }
/** * Przypisuje obiekt danych do spektrogramu. * * Dane mogą zawierać zarówno typowy spektrogram, czyli dla każdej ramki * jej widmo, lub też "spektrogram cech", gdzie dla każdej ramki tablica * wartości zawiera cechy tej ramki. * * @param data obiekt danych */ void SpectrogramPlot::setSpectrogramData(const QwtRasterData& data) { // skala osi czasu DurationScaleDraw* durSD = (DurationScaleDraw*)axisScaleDraw(xBottom); SimpleBirdSettings settings; durSD->setFrameLength(settings.getFrameLength()); durSD->setFrameOverlap(settings.getOverlap()); // przypisanie danych do spektrogramu spectrogram->setData(data); // skalowanie osi intensywności QwtScaleWidget *rightAxis = axisWidget(yRight); rightAxis->setColorMap(data.range(), spectrogram->colorMap()); }
// // Set a plain canvas frame and align the scales to it // void DataPlot::alignScales() { canvas()->setFrameStyle(QFrame::Box | QFrame::Plain ); canvas()->setLineWidth(1); for ( int i = 0; i < QwtPlot::axisCnt; i++ ) { QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(i); if ( scaleWidget ) scaleWidget->setMargin(0); QwtScaleDraw *scaleDraw = (QwtScaleDraw *)axisScaleDraw(i); if ( scaleDraw ) scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false); } }
void XYZPlot::alignScales() { // The code below shows how to align the scales to // the canvas frame, but is also a good example demonstrating // why the spreaded API needs polishing. canvas()->setFrameStyle(QFrame::Box | QFrame::Plain); canvas()->setLineWidth(1); for (int i = 0; i < QwtPlot::axisCnt; i++) { QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(i); if (scaleWidget) scaleWidget->setMargin(0); QwtScaleDraw *scaleDraw = (QwtScaleDraw *)axisScaleDraw(i); if (scaleDraw) scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false); } }
// // Set a plain canvas frame and align the scales to it // void Plotter::alignScales() { // The code below shows how to align the scales to // the canvas frame, but is also a good example demonstrating // why the spreaded API needs polishing. for ( int i = 0; i < QwtPlot::axisCnt; i++ ) { QwtScaleWidget *scaleWidget = axisWidget( i ); if ( scaleWidget ) scaleWidget->setMargin( 0 ); QwtScaleDraw *scaleDraw = axisScaleDraw( i ); if ( scaleDraw ) scaleDraw->enableComponent( QwtAbstractScaleDraw::Backbone, false ); } plotLayout()->setAlignCanvasToScales( true ); }
void Plot::drawItems (QPainter *painter, const QRect &rect, const QwtArray< QwtScaleMap > &map, const QwtPlotPrintFilter &pfilter) const { QwtPlot::drawItems(painter, rect, map, pfilter); for (int i=0; i<QwtPlot::axisCnt; i++) { if (!axisEnabled(i)) continue; ScaleDraw *sd = (ScaleDraw *) axisScaleDraw (i); int majorTicksType = sd->majorTicksStyle(); int minorTicksType = sd->minorTicksStyle(); bool min = (minorTicksType == ScaleDraw::In || minorTicksType == ScaleDraw::Both); bool maj = (majorTicksType == ScaleDraw::In || majorTicksType == ScaleDraw::Both); if (min || maj) drawInwardTicks(painter, rect, map[i], i, min, maj); } }
int Plot::axisLabelFormat(int axis) { if (axisValid(axis)) { int prec; char format; ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); sd->labelFormat(format, prec); if (format == 'g') return Automatic; else if (format == 'e') return Scientific; else if (format == 'f') return Decimal; else return Superscripts; } return 0; }
void Plot::setMinorTicksType(int axis, int type) { ScaleDraw *sd = (ScaleDraw *)axisScaleDraw (axis); if (sd) sd->setMinorTicksStyle((ScaleDraw::TicksStyle)type); }
void OneCurvePlot::setYAxisLabelRotation(double degrees) { axisScaleDraw(yLeft)->setLabelRotation(degrees); }
bool SaxsviewImage::yTickLabelsVisible() const { const QwtScaleDraw *scale = axisScaleDraw(QwtPlot::yLeft); return scale->hasComponent(QwtAbstractScaleDraw::Labels); }
Plot::Plot(QWidget *parent): QwtPlot(parent) { setTitle("Interactive Plot"); setCanvasColor(Qt::darkCyan); QwtPlotGrid *grid = new QwtPlotGrid; grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine)); grid->attach(this); // axes setAxisScale(QwtPlot::xBottom, 0.0, 100.0); setAxisScale(QwtPlot::yLeft, 0.0, 100.0); // Avoid jumping when label with 3 digits // appear/disappear when scrolling vertically QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft); sd->setMinimumExtent( sd->extent(axisWidget(QwtPlot::yLeft)->font())); plotLayout()->setAlignCanvasToScales(true); insertCurve(Qt::Vertical, Qt::blue, 30.0); insertCurve(Qt::Vertical, Qt::magenta, 70.0); insertCurve(Qt::Horizontal, Qt::yellow, 30.0); insertCurve(Qt::Horizontal, Qt::white, 70.0); replot(); // ------------------------------------ // We add a color bar to the left axis // ------------------------------------ QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(yLeft); scaleWidget->setMargin(10); // area for the color bar d_colorBar = new ColorBar(Qt::Vertical, scaleWidget); d_colorBar->setRange(Qt::red, Qt::darkBlue); d_colorBar->setFocusPolicy(Qt::TabFocus); connect(d_colorBar, SIGNAL(selected(const QColor &)), SLOT(setCanvasColor(const QColor &))); // we need the resize events, to lay out the color bar scaleWidget->installEventFilter(this); // ------------------------------------ // We add a wheel to the canvas // ------------------------------------ d_wheel = new QwtWheel(canvas()); d_wheel->setOrientation(Qt::Vertical); d_wheel->setRange(-100, 100); d_wheel->setValue(0.0); d_wheel->setMass(0.2); d_wheel->setTotalAngle(4 * 360.0); connect(d_wheel, SIGNAL(valueChanged(double)), SLOT(scrollLeftAxis(double))); // we need the resize events, to lay out the wheel canvas()->installEventFilter(this); d_colorBar->setWhatsThis( "Selecting a color will change the background of the plot."); scaleWidget->setWhatsThis( "Selecting a value at the scale will insert a new curve."); d_wheel->setWhatsThis( "With the wheel you can move the visible area."); axisWidget(xBottom)->setWhatsThis( "Selecting a value at the scale will insert a new curve."); }
QColor SaxsviewImage::tickLabelFontColor() const { const SaxsviewScaleDraw *draw; draw = dynamic_cast<const SaxsviewScaleDraw*>(axisScaleDraw(QwtPlot::xBottom)); return draw ? draw->labelColor() : QColor(); }
Plot::Plot(QWidget *parent): QwtPlot(parent) { d_spectrogram = new QwtPlotSpectrogram(); QwtLinearColorMap colorMap(Qt::darkCyan, Qt::red); colorMap.addColorStop(0.1, Qt::cyan); colorMap.addColorStop(0.6, Qt::green); colorMap.addColorStop(0.95, Qt::yellow); d_spectrogram->setColorMap(colorMap); d_spectrogram->setData(SpectrogramData()); d_spectrogram->attach(this); QwtValueList contourLevels; for ( double level = 0.5; level < 10.0; level += 1.0 ) contourLevels += level; d_spectrogram->setContourLevels(contourLevels); QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight); rightAxis->setTitle("Intensity"); rightAxis->setColorBarEnabled(true); rightAxis->setColorMap(d_spectrogram->data().range(), d_spectrogram->colorMap()); setAxisScale(QwtPlot::yRight, d_spectrogram->data().range().minValue(), d_spectrogram->data().range().maxValue() ); enableAxis(QwtPlot::yRight); plotLayout()->setAlignCanvasToScales(true); replot(); // LeftButton for the zooming // MidButton for the panning // RightButton: zoom out by 1 // Ctrl+RighButton: zoom out to full size QwtPlotZoomer* zoomer = new QwtPlotZoomer(canvas()); #if QT_VERSION < 0x040000 zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlButton); #else zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier); #endif zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton); QwtPlotPanner *panner = new QwtPlotPanner(canvas()); panner->setAxisEnabled(QwtPlot::yRight, false); panner->setMouseButton(Qt::MidButton); // Avoid jumping when labels with more/less digits // appear/disappear when scrolling vertically const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font()); QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft); sd->setMinimumExtent( fm.width("100.00") ); const QColor c(Qt::darkBlue); zoomer->setRubberBandPen(c); zoomer->setTrackerPen(c); }
void SaxsviewImage::setYTickLabelsVisible(bool on) { QwtScaleDraw *scale = axisScaleDraw(QwtPlot::yLeft); scale->enableComponent(QwtAbstractScaleDraw::Labels, on); updateLayout(); }