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(); }
Variog_multiplot:: Variog_multiplot( const std::vector<Discrete_function>& df_vec, const QStringList& titles, QWidget *parent, const char *name ) : QwtPlot(parent) { if (name) setObjectName(name); //this->setWindowFlags( Qt::SubWindow|Qt::MSWindowsFixedSizeDialogHint); //------------ // configure the plotting area //use a light gray for the grid QwtPlotGrid * grid = new QwtPlotGrid(); grid->enableX(true); grid->setPen( QPen( QColor(150,150,150), 0, Qt::DotLine ) ); grid->attach(this); // configure the plot axis this->axisScaleEngine(QwtPlot::xBottom)->setReference(0); this->axisScaleEngine(QwtPlot::yLeft)->setReference(0); this->axisScaleEngine(QwtPlot::xBottom)->setMargins(0,0.5); this->axisScaleEngine(QwtPlot::yLeft)->setMargins(0,0.5); this->axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating | QwtScaleEngine::IncludeReference); this->axisScaleEngine(QwtPlot::yLeft)->setAttributes(QwtScaleEngine::Floating | QwtScaleEngine::IncludeReference); QFont axis_font = this->axisFont( QwtPlot::xBottom ); axis_font.setPointSize( 7 ); QwtText title("distance"); title.setFont(axis_font); this->setAxisTitle( QwtPlot::xBottom,title); //------------- this->setWindowTitle( "All Plots" ); typedef enum QwtSymbol::Style QwtStyleEnum; typedef enum Qt::PenStyle QtPenStyleEnum; unsigned int dot_styles[8] = { QwtSymbol::Ellipse, QwtSymbol::Rect, QwtSymbol::Diamond, QwtSymbol::DTriangle, QwtSymbol::UTriangle, QwtSymbol::RTriangle, QwtSymbol::Cross, QwtSymbol::XCross }; unsigned int line_styles[5] = {Qt::SolidLine, Qt::DashLine, Qt::DotLine, Qt::DashDotLine, Qt::DashDotDotLine }; /* if( !title.isEmpty() ) { QFont title_font; title_font.setPointSize( 8 ); this->setTitle( title ); this->setTitleFont( title_font ); this->setCaption( title ); } */ const float ymargin = 1.05; const float xmargin = 1.06; float ymax = -9e99; float ymin = 9e99; float xmax = -9e99; for( unsigned int plot_id = 0; plot_id < df_vec.size() ; plot_id++ ) { std::vector<double> x_vals = df_vec[plot_id].x_values(); std::vector<double> y_vals = df_vec[plot_id].y_values(); double* x = new double[x_vals.size()]; double* y = new double[x_vals.size()]; int actual_size = 0; for( int i=0 ; i < x_vals.size() ; i++ ) { if( GsTL::equals( x_vals[i], df_vec[plot_id].no_data_value(), 0.001 ) || GsTL::equals( y_vals[i], df_vec[plot_id].no_data_value(), 0.001 ) ) continue; x[actual_size] = x_vals[i]; y[actual_size] = y_vals[i]; actual_size++; } if( actual_size > 0 ) { float current_ymax = *(std::max_element( y, y+actual_size )); float current_ymin = *(std::min_element( y, y+actual_size )); float current_xmax = *(std::max_element( x, x+actual_size )); ymax = std::max(ymax, current_ymax ); ymin = std::min(ymin, current_ymin ); xmax = std::max(xmax, current_xmax ); } QwtPlotCurve * curve_id = new QwtPlotCurve(titles[plot_id]); curve_id->attach(this); curve_id->setData( x, y, actual_size ); QwtSymbol symbol; // The following line uses an awful cast from int to enum !! // Awful, but it will stay until I find a more elegant way of looping // through all the qwt styles. symbol.setStyle( static_cast<QwtStyleEnum>(dot_styles[plot_id%8]) ); symbol.setPen( QPen(Qt::black, 1 ) ); symbol.setSize(6); curve_id->setSymbol(symbol); curve_id->setStyle(QwtPlotCurve::Lines); curve_id->setPen( QPen(Qt::darkGray, 0, static_cast<QtPenStyleEnum>(line_styles[plot_id%5]) ) ); delete [] x; delete [] y; } if( ymax == 0 && ymin == 0 ) this->setAxisAutoScale( QwtPlot::yLeft ); else this->setAxisScale( QwtPlot::yLeft, ymin*(2-ymargin), ymax*ymargin ); if( xmax > 0 ) { this->setAxisScale( QwtPlot::xBottom, 0, xmax*xmargin ); } QwtLegend * legend = new QwtLegend(); this->insertLegend(legend); this->replot(); }
Plot::Plot( QWidget *parent ): QwtPlot( parent) { setPalette( Qt::black ); // we want to have the axis scales like a frame around the // canvas plotLayout()->setAlignCanvasToScales( true ); for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) axisWidget( axis )->setMargin( 0 ); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setAutoFillBackground( false ); canvas->setFrameStyle( QFrame::NoFrame ); setCanvas( canvas ); setAxisScale( QwtPlot::yLeft, 0.0, 10.0 ); // a title QwtText title( "Picker Demo" ); title.setColor( Qt::white ); title.setRenderFlags( Qt::AlignHCenter | Qt::AlignTop ); QFont font; font.setBold( true ); title.setFont( font ); QwtPlotTextLabel *titleItem = new QwtPlotTextLabel(); titleItem->setText( title ); titleItem->attach( this ); #if 1 // section //QColor c( "PaleVioletRed" ); QwtPlotZoneItem* zone = new QwtPlotZoneItem(); zone->setPen( Qt::darkGray ); zone->setBrush( QColor( "#834358" ) ); zone->setOrientation( Qt::Horizontal ); zone->setInterval( 3.8, 5.7 ); zone->attach( this ); #else // grid QwtPlotGrid *grid = new QwtPlotGrid(); grid->setMajorPen( Qt::white, 0, Qt::DotLine ); grid->setMinorPen( Qt::gray, 0 , Qt::DotLine ); grid->attach( this ); #endif // curves QPolygonF points1; points1 << QPointF( 0.2, 4.4 ) << QPointF( 1.2, 3.0 ) << QPointF( 2.7, 4.5 ) << QPointF( 3.5, 6.8 ) << QPointF( 4.7, 7.9 ) << QPointF( 5.8, 7.1 ); insertCurve( "Curve 1", "DarkOrange", points1 ); QPolygonF points2; points2 << QPointF( 0.4, 8.7 ) << QPointF( 1.4, 7.8 ) << QPointF( 2.3, 5.5 ) << QPointF( 3.3, 4.1 ) << QPointF( 4.4, 5.2 ) << QPointF( 5.6, 5.7 ); insertCurve( "Curve 2", "DodgerBlue", points2 ); CurveTracker* tracker = new CurveTracker( this->canvas() ); // for the demo we want the tracker to be active without // having to click on the canvas tracker->setStateMachine( new QwtPickerTrackerMachine() ); tracker->setRubberBandPen( QPen( "MediumOrchid" ) ); }
void QgsHistogramWidget::drawHistogram() { // clear plot mpPlot->detachItems(); //ensure all children get removed mpPlot->setAutoDelete( true ); // Set axis titles if ( !mXAxisTitle.isEmpty() ) mpPlot->setAxisTitle( QwtPlot::xBottom, mXAxisTitle ); if ( !mYAxisTitle.isEmpty() ) mpPlot->setAxisTitle( QwtPlot::yLeft, mYAxisTitle ); mpPlot->setAxisFont( QwtPlot::xBottom, this->font() ); mpPlot->setAxisFont( QwtPlot::yLeft, this->font() ); QFont titleFont = this->font(); titleFont.setBold( true ); QwtText xAxisText = mpPlot->axisTitle( QwtPlot::xBottom ); xAxisText.setFont( titleFont ); mpPlot->setAxisTitle( QwtPlot::xBottom, xAxisText ); QwtText yAxisText = mpPlot->axisTitle( QwtPlot::yLeft ); yAxisText.setFont( titleFont ); mpPlot->setAxisTitle( QwtPlot::yLeft, yAxisText ); 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(); Q_FOREACH ( const QgsRendererRange &range, mRanges ) { mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black ); } //draw histogram QwtPlotHistogram *plotHistogram = nullptr; plotHistogram = createPlotHistogram( !mRanges.isEmpty() ? mRanges.at( 0 ).label() : QString(), !mRanges.isEmpty() ? QBrush( mHistoColors.at( 0 ) ) : mBrush, !mRanges.isEmpty() ? Qt::NoPen : mPen ); QVector<QwtIntervalSample> dataHisto; 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++; 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 ) ); } double upperEdge = !mRanges.isEmpty() ? qMin( edges.at( bin + 1 ), mRanges.at( rangeIndex ).upperValue() ) : edges.at( bin + 1 ); dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge ); lastValue = binValue; } plotHistogram->setSamples( dataHisto ); plotHistogram->attach( mpPlot ); mRangeMarkers.clear(); Q_FOREACH ( const QgsRendererRange &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; }
GraphikSV::GraphikSV(QWidget *parent) : QMainWindow(parent), ui(new Ui::GraphikSV) { ui->setupUi(this); QString b1,b2,b3,b4,b5,b6; qDebug()<<IDD; QSqlQuery queryQ; QString e1111 = (QString("SELECT \"Button1\", \"Button2\", \"Button3\", \"Button4\", \"Button5\"," " \"Button6\" FROM \"ResultTest\" where \"StudentId\" = '%1' AND \"Hand\" = '%2'").arg(IDD).arg(1)); queryQ.exec(e1111); while (queryQ.next()) { b1=queryQ.value(0).toString(); b2=queryQ.value(1).toString(); b3=queryQ.value(2).toString(); b4=queryQ.value(3).toString(); b5=queryQ.value(4).toString(); b6=queryQ.value(5).toString(); } ui->Qwt_Widget->detachItems(QwtPlotItem::Rtti_PlotItem,true); ui->Qwt_Widget->setTitle( "График результатов по ведущей руке" ); ui->Qwt_Widget->setCanvasBackground( Qt::white ); // Параметры осей координат ui->Qwt_Widget->setAxisTitle(QwtPlot::yLeft, "Количество кликов"); ui->Qwt_Widget->setAxisTitle(QwtPlot::xBottom, "Время, сек"); QwtPlotPicker *d_picker = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft, // ассоциация с осями QwtPlotPicker::CrossRubberBand, // стиль перпендикулярных линий QwtPicker::ActiveOnly, // включение/выключение ui->Qwt_Widget->canvas() ); // ассоциация с полем // Цвет перпендикулярных линий d_picker->setRubberBandPen( QColor( Qt::red ) ); // цвет координат положения указателя d_picker->setTrackerPen( QColor( Qt::black ) ); // непосредственное включение вышеописанных функций d_picker->setStateMachine( new QwtPickerDragPointMachine() ); ui->Qwt_Widget->setAxisScale(QwtPlot::xBottom, 5, 30, 5); ui->Qwt_Widget->setAxisScale(QwtPlot::yLeft, 0, 48, 8); QwtPlotGrid *grid = new QwtPlotGrid(); grid->setMajorPen(QPen( Qt::gray, 2 )); // цвет линий и толщина grid->attach( ui->Qwt_Widget ); curve = new QwtPlotCurve(); curve->setPen( Qt::green, 6 ); // цвет и толщина кривой // Маркеры кривой // #include <qwt_symbol.h> QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) ); curve->setSymbol( symbol ); // Добавить точки на ранее созданную кривую // Значения точек записываются в массив, затем считываются // из этого массива points << QPointF(5, b1.toInt())<<QPointF(10, b2.toInt())<<QPointF(15, b3.toInt())<<QPointF(20, b4.toInt())<<QPointF(25, b5.toInt())<<QPointF(30, b6.toInt()); // for (int i = 0; i < 5; i++) { // points << QPointF( 1.0 * i, 1.0 * i); // произвольное заполнение // } curve->setSamples( points ); // ассоциировать набор точек с кривой curve->attach( ui->Qwt_Widget ); // отобразить кривую на графике points.clear(); }
Plot::Plot(QWidget *parent):QwtPlot( parent ) { setAutoReplot( false ); setTitle( "FFT" ); 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, "Frequency [kHz]" ); setAxisTitle( QwtPlot::yLeft, "Amplitude " ); //setAxisTitle( QwtPlot::yRight, "Phase [deg]" ); setAxisMaxMajor( QwtPlot::xBottom, 6 ); setAxisMaxMinor( QwtPlot::xBottom, 9 ); //setAxisScale(QwtPlot::xBottom,0.01,100); //setAxisScaleEngine( QwtPlot::xBottom, ScaleEngine_Lin_X ); // setAxisScaleEngine(QwtPlot::xBottom, new QwtLogScaleEngine ); // curves d_curve1 = new QwtPlotCurve( "Amplitude Ch1" ); d_curve1->setRenderHint( QwtPlotItem::RenderAntialiased ); d_curve1->setPen( Qt::red ); d_curve1->setLegendAttribute( QwtPlotCurve::LegendShowLine ); d_curve1->setYAxis( QwtPlot::yLeft ); d_curve1->attach( this ); m_Channel2=true; if(m_Channel2){ d_curve2 = new QwtPlotCurve( "Amplitude Ch2 " ); d_curve2->setRenderHint( QwtPlotItem::RenderAntialiased ); d_curve2->setPen( Qt::magenta ); d_curve2->setLegendAttribute( QwtPlotCurve::LegendShowLine ); d_curve2->setYAxis( QwtPlot::yLeft ); d_curve2->attach( this ); } d_average = new QwtPlotCurve( "Average Ch1" ); d_average->setRenderHint( QwtPlotItem::RenderAntialiased ); d_average->setPen( Qt::white ); d_average->setLegendAttribute( QwtPlotCurve::LegendShowLine ); d_average->setYAxis( QwtPlot::yLeft ); d_average->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 ); if(m_Channel2){ /* d_marker2 = new QwtPlotMarker(); d_marker2->setValue( 0.0, 0.0 ); d_marker2->setLineStyle( QwtPlotMarker::VLine ); d_marker2->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom ); d_marker2->setLinePen( Qt::gray, 0, Qt::DashDotLine ); d_marker2->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 ); }
//--------------------------------------------------------------------------- Plot::Plot( size_t streamPos, size_t Type, size_t Group, QWidget *parent ) : QwtPlot( parent ), m_streamPos( streamPos ), m_type( Type ), m_group( Group ) { setAutoReplot( false ); QwtPlotCanvas* canvas = dynamic_cast<QwtPlotCanvas*>( this->canvas() ); if ( canvas ) { canvas->setFrameStyle( QFrame::Plain | QFrame::Panel ); canvas->setLineWidth( 1 ); #if 1 canvas->setPalette( QColor("Cornsilk") ); #endif } setAxisMaxMajor( QwtPlot::yLeft, 0 ); setAxisMaxMinor( QwtPlot::yLeft, 0 ); setAxisScaleDraw( QwtPlot::yLeft, new PlotScaleDrawY() ); enableAxis( QwtPlot::xBottom, false ); // something invalid setAxisScale( QwtPlot::xBottom, -1, 0 ); setAxisScale( QwtPlot::yLeft, -1, 0 ); // Plot grid QwtPlotGrid *grid = new QwtPlotGrid(); grid->enableXMin( true ); grid->enableYMin( true ); grid->setMajorPen( Qt::darkGray, 0, Qt::DotLine ); grid->setMinorPen( Qt::gray, 0 , Qt::DotLine ); grid->attach( this ); m_cursor = new PlotCursor( canvas ); m_cursor->setPosition( 0 ); // curves for( unsigned j = 0; j < PerStreamType[m_type].PerGroup[m_group].Count; ++j ) { QwtPlotCurve* curve = new QwtPlotCurve( PerStreamType[m_type].PerItem[PerStreamType[m_type].PerGroup[m_group].Start + j].Name ); curve->setPen( curveColor( j ) ); curve->setRenderHint( QwtPlotItem::RenderAntialiased ); curve->setZ( curve->z() - j ); //Invert data order (e.g. MAX before MIN) curve->attach( this ); m_curves += curve; } // visual helpers if ( m_type == Type_Video ) switch (m_group) { case Group_Y : Plot_AddHLine( this, 16, 61, 89, 171); Plot_AddHLine( this, 235, 220, 20, 60); break; case Group_U : case Group_V : Plot_AddHLine( this, 16, 61, 89, 171); Plot_AddHLine( this, 240, 220, 20, 60); break; case Group_Sat : Plot_AddHLine( this, 88, 255, 0, 255); Plot_AddHLine( this, 118, 220, 20, 60); break; default : ; } PlotPicker* picker = new PlotPicker( canvas, &PerStreamType[m_type], m_group, &m_curves ); connect( picker, SIGNAL( moved( const QPointF& ) ), SLOT( onPickerMoved( const QPointF& ) ) ); connect( picker, SIGNAL( selected( const QPointF& ) ), SLOT( onPickerMoved( const QPointF& ) ) ); connect( axisWidget( QwtPlot::xBottom ), SIGNAL( scaleDivChanged() ), SLOT( onXScaleChanged() ) ); // legend m_legend = new PlotLegend(); connect( this, SIGNAL( legendDataChanged( const QVariant &, const QList<QwtLegendData> & ) ), m_legend, SLOT( updateLegend( const QVariant &, const QList<QwtLegendData> & ) ) ); updateLegend(); }
Plot::Plot(QWidget *parent): QwtPlot(parent), d_paintedPoints(0), d_interval(0.0, 10.0), d_timerId(-1) { d_directPainter = new QwtPlotDirectPainter(); setAutoReplot(false); // The backing store is important, when working with widget // overlays ( f.e rubberbands for zooming ). // Here we don't have them and the internal // backing store of QWidget is good enough. canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false); #if defined(Q_WS_X11) // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent // works on X11. This has a nice effect on the performance. canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); // Disabling the backing store of Qt improves the performance // for the direct painter even more, but the canvas becomes // a native window of the window system, receiving paint events // for resize and expose operations. Those might be expensive // when there are many points and the backing store of // the canvas is disabled. So in this application // we better don't both backing stores. if ( canvas()->testPaintAttribute( QwtPlotCanvas::BackingStore ) ) { canvas()->setAttribute(Qt::WA_PaintOnScreen, true); canvas()->setAttribute(Qt::WA_NoSystemBackground, true); } #endif initGradient(); plotLayout()->setAlignCanvasToScales(true); setAxisTitle(QwtPlot::xBottom, "Time [s]"); setAxisScale(QwtPlot::xBottom, d_interval.minValue(), d_interval.maxValue()); setAxisScale(QwtPlot::yLeft, -200.0, 200.0); QwtPlotGrid *grid = new QwtPlotGrid(); grid->setPen(QPen(Qt::gray, 0.0, Qt::DotLine)); grid->enableX(true); grid->enableXMin(true); grid->enableY(true); grid->enableYMin(false); grid->attach(this); d_origin = new QwtPlotMarker(); d_origin->setLineStyle(QwtPlotMarker::Cross); d_origin->setValue(d_interval.minValue() + d_interval.width() / 2.0, 0.0); d_origin->setLinePen(QPen(Qt::gray, 0.0, Qt::DashLine)); d_origin->attach(this); d_curve = new QwtPlotCurve(); d_curve->setStyle(QwtPlotCurve::Lines); d_curve->setPen(QPen(Qt::green)); #if 1 d_curve->setRenderHint(QwtPlotItem::RenderAntialiased, true); #endif #if 1 d_curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false); #endif d_curve->setData(new CurveData()); d_curve->attach(this); }
chooseCyclesForm::chooseCyclesForm(model* mainModelGiven, bool showAlreadyPrecalcedCycles){ // open log file log.open("chooseCyclesForm.log"); log << "constructor call" << std::endl; FFTSignal = NULL; justDeletedMaker = NULL; // attach ui form setupUi(this); mainModel = mainModelGiven; peakSignal = mainModel->givePeakSignal(); // ask to evaluate peak signal //askMainModelToEvaluate(); // and take it //peakSignal = mainModel->givePeakSignal(); // peak signal plot qwtPlot_peakSignal->setAutoReplot(false); qwtPlot_peakSignal->setCanvasBackground(QColor(Qt::darkBlue)); qwtPlot_peakSignal->setTitle("peak signal"); qwtPlot_peakSignal->setAxisTitle(QwtPlot::xBottom, "FFT cycles"); qwtPlot_peakSignal->setAxisTitle(QwtPlot::yLeft, "Amplitude"); QwtLegend *legend = new QwtLegend; qwtPlot_peakSignal->insertLegend(legend, QwtPlot::BottomLegend); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(qwtPlot_peakSignal); peakSignalCurve1 = new QwtPlotCurve("Gidrophone 0 peakSignal"); peakSignalCurve1->setPen(QPen(Qt::cyan)); peakSignalCurve1->attach(qwtPlot_peakSignal); peakSignalCurve2 = new QwtPlotCurve("Gidrophone 0 peakSignal"); peakSignalCurve2->setPen(QPen(Qt::yellow)); peakSignalCurve2->attach(qwtPlot_peakSignal); showPeakSignal1(0); showPeakSignal2(0); qwtPlot_peakSignal->setAutoReplot(true); // end of peak signal plot //FFTSignal qwtPlot_FFTCycle->setAutoReplot(false); qwtPlot_FFTCycle->setCanvasBackground(QColor(Qt::darkBlue)); qwtPlot_FFTCycle->setTitle("FFT signal"); qwtPlot_FFTCycle->setAxisTitle(QwtPlot::xBottom, "FFT beans"); qwtPlot_FFTCycle->setAxisTitle(QwtPlot::yLeft, "Amplitude"); /* qwtPlot_FFTCycle->setAxisTitle(QwtPlot::xTop, "FFT beans"); QwtInterval interval = qwtPlot_FFTCycle->axisInterval(QwtPlot::xBottom); double left = interval.minValue(); double right = interval.maxValue(); qwtPlot_FFTCycle->setAxisScale(QwtPlot::xTop, left, right); */ QwtLegend *legendFFTSignal = new QwtLegend; qwtPlot_FFTCycle->insertLegend(legendFFTSignal, QwtPlot::BottomLegend); QwtPlotGrid *gridFFTSignal = new QwtPlotGrid; gridFFTSignal->enableXMin(true); gridFFTSignal->setMajPen(QPen(Qt::white, 0, Qt::DotLine)); gridFFTSignal->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); gridFFTSignal->attach(qwtPlot_FFTCycle); FFTSignalCurve1 = new QwtPlotCurve("Gidrophone 0 peakSignal"); FFTSignalCurve1->setPen(QPen(Qt::cyan)); FFTSignalCurve1->attach(qwtPlot_FFTCycle); FFTSignalCurve2 = new QwtPlotCurve("Gidrophone 0 peakSignal"); FFTSignalCurve2->setPen(QPen(Qt::yellow)); FFTSignalCurve2->attach(qwtPlot_FFTCycle); qwtPlot_FFTCycle->setAutoReplot(true); // end of FFT signal plot // zoomer and picker and smth else // recreare zoomer each time we get new data in the plot reCreateZoomer(); reCreateZoomer2nd(); // end of zoomer and picker and smth else // toolbar QToolBar *toolBar = new QToolBar(this); // zoom button btnZoom = new QToolButton(toolBar); btnZoom->setText("Zoom"); btnZoom->setIcon(QIcon(zoom_xpm)); btnZoom->setCheckable(true); btnZoom->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); toolBar->addWidget(btnZoom); connect(btnZoom, SIGNAL(toggled(bool)), SLOT(enableZoomMode(bool))); // end of zoom button // zoom button 2nd toolButton_zoom2nd->setText("Zoom"); toolButton_zoom2nd->setIcon(QIcon(zoom_xpm)); toolButton_zoom2nd->setCheckable(true); toolButton_zoom2nd->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); connect(toolButton_zoom2nd, SIGNAL(toggled(bool)), SLOT(enableZoomMode2nd(bool))); // end of zoom button 2nd // marker peakSignalMarker = new QwtPlotMarker(); peakSignalMarker->setValue(0.0, 0.0); peakSignalMarker->setLineStyle(QwtPlotMarker::VLine); peakSignalMarker->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom); peakSignalMarker->setLinePen(QPen(Qt::green, 0, Qt::DashDotLine)); peakSignalMarker->attach(qwtPlot_peakSignal); // end of marker // marker list listOfMarkers = new markerList(listWidget_FFTCycles, qwtPlot_peakSignal, peakSignalMarker); // end of marker list // spin boxes spinBox_gidrophone1->setMinimum(0); spinBox_gidrophone1->setMaximum(peakSignal->sizex() - 1); spinBox_gidrophone2->setMinimum(0); spinBox_gidrophone2->setMaximum(peakSignal->sizex() - 1); connect(spinBox_gidrophone1, SIGNAL( valueChanged(int) ), this, SLOT( showPeakSignal1(int) ) ); connect(spinBox_gidrophone2, SIGNAL( valueChanged(int) ), this, SLOT( showPeakSignal2(int) ) ); // end of spin boxes // spin boxes 2 spinBox_FFTGidrophone1->setMinimum(0); spinBox_FFTGidrophone1->setMaximum(0); spinBox_FFTGidrophone2->setMinimum(0); spinBox_FFTGidrophone2->setMaximum(0); connect(spinBox_FFTGidrophone1, SIGNAL( valueChanged(int) ), this, SLOT( showFFTSignal1(int) ) ); connect(spinBox_FFTGidrophone2, SIGNAL( valueChanged(int) ), this, SLOT( showFFTSignal2(int) ) ); // end of spin boxes 2 // evaluate button // (defined in ui form) //connect( pushButton_evaluate, SIGNAL( clicked() ), this, SLOT( evaluatePeakSignal() ) ); // end of evaluate button // signal picker // (defined in function reCreateZoomer()) connect(peakSignalPicker, SIGNAL(moved(const QPoint &)), this, SLOT(showCurrentMarker(const QPoint &))); connect(peakSignalPicker, SIGNAL(appended(const QPoint &)), this, SLOT(showCurrentMarker(const QPoint &))); // end of signal picker connect(pushButton_addFFTCycle, SIGNAL( clicked() ), listOfMarkers, SLOT( addMarker() ) ); connect(pushButton_removeCycle, SIGNAL( clicked() ), listOfMarkers, SLOT( removeMarker() ) ); connect(pushButton_FFTCycleShiftLeft, SIGNAL( clicked() ), listOfMarkers, SLOT( shiftCurrentMarkerLeft() ) ); connect(pushButton_FFTCycleShiftRight, SIGNAL( clicked() ), listOfMarkers, SLOT( shiftCurrentMarkerRight() ) ); connect(pushButton_calibrate, SIGNAL( clicked() ), this, SLOT( proceedCalibrate() ) ); //connect(listWidget_FFTCycles, SIGNAL( currentItemChanged( QListWidgetItem*, QListWidgetItem* ) ), this, SLOT( chooseCycleItem( QListWidgetItem*, QListWidgetItem* ) ) ); connect(listWidget_FFTCycles, SIGNAL( itemActivated( QListWidgetItem* ) ), listOfMarkers, SLOT( markerSelected( QListWidgetItem* ) ) ); if(showAlreadyPrecalcedCycles){ std::vector<double>* sourceFrequencies = mainModel->giveFrequencies(); std::vector<int>* alreadyPrecalcedCycles = mainModel->giveCycles(); int alreadyPrecalcedCyclesAmount = alreadyPrecalcedCycles->size(); for(int i = 0; i < alreadyPrecalcedCyclesAmount; i++){ listOfMarkers->addPrecalcedMarker((*alreadyPrecalcedCycles)[i], (*sourceFrequencies)[i]); } } }
Plot::Plot(QWidget *parent): QwtPlot(parent), d_paintedPoints0(0), d_paintedPoints1(0), d_interval(0.0, 25.0), d_timerId(-1) { d_directPainter0 = new QwtPlotDirectPainter(); setAutoReplot(false); canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false); #if defined(Q_WS_X11) canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); if ( canvas()->testPaintAttribute( QwtPlotCanvas::BackingStore ) ) { canvas()->setAttribute(Qt::WA_PaintOnScreen, true); canvas()->setAttribute(Qt::WA_NoSystemBackground, true); } #endif initGradient(); plotLayout()->setAlignCanvasToScales(true); setAxisTitle(QwtPlot::xBottom, "Time [s]"); setAxisScale(QwtPlot::xBottom, d_interval.minValue(), d_interval.maxValue()); setAxisScale(QwtPlot::yLeft, 0, 10.0); QwtPlotGrid *grid = new QwtPlotGrid(); grid->setPen(QPen(Qt::green, 0.0, Qt::DotLine)); grid->enableX(true); grid->enableXMin(true); grid->enableY(true); grid->enableYMin(false); grid->attach(this); d_origin = new QwtPlotMarker(); d_origin->setLineStyle(QwtPlotMarker::Cross); d_origin->setValue(d_interval.minValue() + d_interval.width() / 2.0, 0.0); d_origin->setLinePen(QPen(Qt::red, 0.0, Qt::DashLine)); d_origin->attach(this); d_curve0 = new QwtPlotCurve(); d_curve0->setStyle(QwtPlotCurve::Lines); d_curve0->setPen(QPen(Qt::green,3)); #if 1 d_curve0->setRenderHint(QwtPlotItem::RenderAntialiased, true); #endif #if 1 d_curve0->setPaintAttribute(QwtPlotCurve::ClipPolygons, false); #endif d_curve0->setData(new CurveData()); d_curve0->attach(this); d_curve1 = new QwtPlotCurve(); d_curve1->setStyle(QwtPlotCurve::Lines); d_curve1->setPen(QPen(Qt::red,3)); #if 1 d_curve1->setRenderHint(QwtPlotItem::RenderAntialiased, true); #endif #if 1 d_curve1->setPaintAttribute(QwtPlotCurve::ClipPolygons, false); #endif d_curve1->setData(new CurveData()); d_curve1->attach(this); }
ProcessDialog::ProcessDialog (QWidget *parent) : QDialog (parent) { setupUi (this); writeThread = new DThread; saver = new DSaver; aCurve = new DCurve; config = new DConfig; fprintf (stderr, "Objects initialized.\n"); zone_length = config->measure_num; zone_length_spin->setValue (zone_length); start_x = 0; // zone_length = 50; // start_x = 0; // end_x = zone_length; // ############## STANDART WIDGETS INITIALIZATION ############ //zone_length_spin->setValue (static_cast<int>(aCurve->zone_length)); // zone_length_spin->setValue (50); // QString scale_temp = QString::number (aCurve->maxX/zone_length, 'g', 4); // scale_value_label->setText (scale_temp); saver->set_file_name ("default.dat"); running = false; indicator_label->setText ("<font color=red> <b> NOT RUNNING </b> </font>"); tabWidget->setTabText (0, "Diagram"); tabWidget->setTabText (1, "Scheme"); /* Connections */ connect (aCurve, SIGNAL ( pack_accepted () ), plot, SLOT ( replot() )); connect (aCurve, SIGNAL ( pack_accepted () ), this, SLOT (graph_next_frame()) ); connect (writeThread, SIGNAL ( text_data (DPack *) ), this, SLOT ( process_pack (DPack *) )); connect (writeThread, SIGNAL ( chart_data (DPack *) ), aCurve, SLOT ( accept_data_pack (DPack *) )); connect (writeThread, SIGNAL ( save_data (DPack *) ), saver, SLOT (accept_data_pack (DPack *) )); connect (writeThread, SIGNAL ( done()), this, SLOT ( done())); connect (this, SIGNAL (rejected()), writeThread, SLOT (stop_thread())); // test routine // connect (this, SIGNAL (test_data_pack (DPack *)), this, SLOT ( process_pack (DPack *) )); // connect (this, SIGNAL (test_data_pack (DPack *)), aCurve, SLOT ( accept_data_pack (DPack *) )); // connect (this, SIGNAL (test_data_pack (DPack *)), saver, SLOT ( accept_data_pack (DPack *) )); /* Properties */ connect (channel1_box, SIGNAL (clicked()), this, SLOT (channel1_box_clicked())); connect (channel2_box, SIGNAL (clicked()), this, SLOT (channel2_box_clicked())); connect (channel3_box, SIGNAL (clicked()), this, SLOT (channel3_box_clicked())); connect (channel4_box, SIGNAL (clicked()), this, SLOT (channel4_box_clicked())); connect (channel5_box, SIGNAL (clicked()), this, SLOT (channel5_box_clicked())); connect (channel6_box, SIGNAL (clicked()), this, SLOT (channel6_box_clicked())); connect (zone_length_spin, SIGNAL (valueChanged (int)), this, SLOT (graph_update (int))); connect (this, SIGNAL (closed()), this, SLOT (renew())); fprintf (stderr, "Connections established,\n"); // ################### QwtPlot initialization ######################## for (int a = 0; a < 6; a ++) { QPen pen = QPen (config->colors[a]); pen.setWidth(2); aCurve->channel_curve[a]->setPen (pen); aCurve->channel_curve[a]->attach (plot); } aCurve->setMaxX (config->measure_num); aCurve->setStepX (config->chart_mod); fprintf (stderr, "ProcessDialog: stepx = config->chart_mod = %d.\n", config->chart_mod); QwtPlotGrid *grid = new QwtPlotGrid; grid->setMajPen (QPen (Qt::gray, 0, Qt::DotLine)); grid->attach (plot); plot->setTitle ("Graphics diagram"); plot->setCanvasBackground (Qt::white); plot->setAxisTitle (0,"Signal, V"); plot->setAxisTitle (2,"Measure, num"); // plot->setAxisScale (2, start_x, end_x, zone_length/10); plot->setAxisScale (2, 0, config->measure_num, config->measure_num/10); //graph_update(zone_length); // ##################### TABLE INITIALIZATION ##################### row = -1; display_table->setColumnCount (6); display_table->setRowCount(config->measure_num); for (int i = 0; i < 6; i++) { display_table->setColumnWidth (i, 40); } // ########### CHANNEL GROUP ###################### QString temp = tr("<font color='%1'>%2</font>"); QString text = "Ch1"; channel1_label->setText (temp.arg (config->colors[0].name(), text)); temp = tr("<font color='%1'>%2</font>"); text = "Ch2"; channel2_label->setText (temp.arg (config->colors[1].name(), text)); temp = tr("<font color='%1'>%2</font>"); text = "Ch3"; channel3_label->setText (temp.arg (config->colors[2].name(), text)); temp = tr("<font color='%1'>%2</font>"); text = "Ch4"; channel4_label->setText (temp.arg (config->colors[3].name(), text)); temp = tr("<font color='%1'>%2</font>"); text = "Ch5"; channel5_label->setText (temp.arg (config->colors[4].name(), text)); temp = tr("<font color='%1'>%2</font>"); text = "Ch6"; channel6_label->setText (temp.arg (config->colors[5].name(), text)); fprintf (stderr, "ProcessDialog object created\n"); }
QmitkHistogramWidget::QmitkHistogramWidget(QWidget * parent, bool showreport) : QDialog(parent) , m_Plot(NULL) , m_Textedit(NULL) , m_Marker(NULL) , m_Picker(NULL) , m_Zoomer(NULL) , m_Histogram(NULL) { QBoxLayout *layout = new QVBoxLayout(this); //***histogram*** QGroupBox *hgroupbox = new QGroupBox("", this); hgroupbox->setMinimumSize(900, 400); m_Plot = new QwtPlot(hgroupbox); m_Plot->setCanvasBackground(QColor(Qt::white)); m_Plot->setTitle("Histogram"); QwtText text = m_Plot->titleLabel()->text(); text.setFont(QFont("Helvetica", 12, QFont::Normal)); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->enableYMin(true); grid->setMajorPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinorPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(m_Plot); layout->addWidget(hgroupbox); layout->setSpacing(20); if (showreport == true) { //***report*** QGroupBox *rgroupbox = new QGroupBox("", this); rgroupbox->setMinimumSize(900, 400); QLabel *label = new QLabel("Gray Value Analysis", rgroupbox); label->setAlignment(Qt::AlignHCenter); label->setFont(QFont("Helvetica", 14, QFont::Bold)); m_Textedit = new QTextEdit(rgroupbox); m_Textedit->setFont(QFont("Helvetica", 12, QFont::Normal)); m_Textedit->setReadOnly(true); layout->addWidget(rgroupbox); } m_Picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::NoRubberBand, QwtPicker::AlwaysOn, m_Plot->canvas()); // the m_PickerMachine pointer is managed by the m_Picker instance m_Picker->setStateMachine(new QwtPickerClickPointMachine()); connect(m_Picker, SIGNAL(selected(const QwtDoublePoint &)), SLOT(OnSelect(const QwtDoublePoint &))); }
ChartView::ChartView( QWidget * parent ) : QwtPlot( parent ) { // void setupPalette() { QPalette pal = palette(); QLinearGradient gradient; gradient.setCoordinateMode( QGradient::StretchToDeviceMode ); // gradient.setColorAt( 0.0, QColor( 0xcf, 0xcf, 0xc4 ) ); // pastel gray // gradient.setColorAt( 1.0, QColor( 0xae, 0xc6, 0xcf ) ); // pastel blue gradient.setColorAt( 0.0, QColor( 0xc1, 0xff, 0xc1 ) ); // darkseagreen gradient.setColorAt( 1.0, QColor( 0xb4, 0xee, 0xb4 ) ); // darkseagreen 2 pal.setBrush( QPalette::Window, QBrush( gradient ) ); // QPalette::WindowText is used for the curve color // pal.setColor( QPalette::WindowText, Qt::green ); setPalette( pal ); } this->enableAxis( QwtPlot::yLeft, true ); this->enableAxis( QwtPlot::xBottom, true ); QwtPlotGrid *grid = new QwtPlotGrid(); grid->setPen( Qt::gray, 0.0, Qt::DotLine ); grid->enableX( true ); grid->enableXMin( true ); grid->enableY( true ); grid->enableYMin( false ); grid->attach( this ); this->axisScaleEngine( QwtPlot::yLeft )->setAttribute( QwtScaleEngine::Floating, true ); this->axisScaleEngine( QwtPlot::xBottom )->setAttribute( QwtScaleEngine::Floating, true ); auto zoomer = new adplot::Zoomer( QwtPlot::xBottom, QwtPlot::yLeft, this->canvas() ); // Shift+LeftButton: zoom out to full size // Double click: zoom out by 1 zoomer->setMousePattern( QwtEventPattern::MouseSelect2, Qt::LeftButton, Qt::ShiftModifier ); const QColor c( Qt::darkBlue ); zoomer->setRubberBandPen( c ); zoomer->setTrackerPen( c ); zoomer->autoYScaleHock( [&]( QRectF& rc ){ yScaleHock( rc ); } ); zoomer->autoYScale( true ); if ( auto panner = new QwtPlotPanner( canvas() ) ) { panner->setAxisEnabled( QwtPlot::yRight, false ); panner->setMouseButton( Qt::MidButton ); } if ( auto picker = new QwtPlotPicker( canvas() ) ) { picker->setMousePattern( QwtEventPattern::MouseSelect1, Qt::RightButton ); picker->setStateMachine( new QwtPickerDragRectMachine() ); picker->setRubberBand( QwtPicker::RectRubberBand ); picker->setRubberBandPen( QColor(Qt::red) ); picker->setTrackerPen( QColor( Qt::blue ) ); connect( picker, static_cast< void(QwtPlotPicker::*)(const QRectF&) >(&QwtPlotPicker::selected), this, &ChartView::selected ); picker->setEnabled( true ); } }
EcgCh::EcgCh(QWidget *parent) : QwtPlot(parent) { setMinimumHeight(10); setMinimumWidth(10); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(this); setAxisTitle(QwtPlot::xBottom, "Czas [mm:ss.ms]"); setAxisTitle(QwtPlot::yLeft, "Amplituda [mV]"); signalCurve = new QwtPlotCurve("signal"); signalCurve->setYAxis(QwtPlot::yLeft); signalCurve->attach(this); peaksCurve = new QwtPlotCurve("r-peaks"); peaksCurve->setYAxis(QwtPlot::yLeft); peaksCurve->setStyle(QwtPlotCurve::NoCurve); peaksCurve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,QColor(Qt::red), QColor(Qt::red), QSize(6, 6))); peaksCurve->setPen(QPen(Qt::red, 5)); peaksCurve->attach(this); qrsOnSetCurve = new QwtPlotCurve("qrsOnSet"); qrsOnSetCurve->setYAxis(QwtPlot::yLeft); qrsOnSetCurve->setStyle(QwtPlotCurve::NoCurve); qrsOnSetCurve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,QColor(0,255,0), QColor(0,255,0), QSize(6, 6))); qrsOnSetCurve->attach(this); qrsEndSetCurve = new QwtPlotCurve("qrsEndSet"); qrsEndSetCurve->setYAxis(QwtPlot::yLeft); qrsEndSetCurve->setStyle(QwtPlotCurve::NoCurve); qrsEndSetCurve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,QColor(0,150,0), QColor(0,150,0), QSize(6, 6))); qrsEndSetCurve->attach(this); pOnSetCurve = new QwtPlotCurve("pOnSet"); pOnSetCurve->setYAxis(QwtPlot::yLeft); pOnSetCurve->setStyle(QwtPlotCurve::NoCurve); pOnSetCurve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,QColor(0,0,255), QColor(0,0,255), QSize(6, 6))); pOnSetCurve->attach(this); pEndSetCurve = new QwtPlotCurve("pEndSet"); pEndSetCurve->setYAxis(QwtPlot::yLeft); pEndSetCurve->setStyle(QwtPlotCurve::NoCurve); pEndSetCurve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,QColor(0,94,185), QColor(0,94,185), QSize(6, 6))); pEndSetCurve->attach(this); tEndSetCurve = new QwtPlotCurve("tEndSet"); tEndSetCurve->setYAxis(QwtPlot::yLeft); tEndSetCurve->setStyle(QwtPlotCurve::NoCurve); tEndSetCurve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,QColor(116,11,11), QColor(116,11,11), QSize(6, 6))); tEndSetCurve->attach(this); vCurve = new QwtPlotCurve("V"); vCurve->setYAxis(QwtPlot::yLeft); vCurve->setStyle(QwtPlotCurve::NoCurve); vCurve->setSymbol(new QwtSymbol(QwtSymbol::Triangle,QColor(Qt::red), QColor(Qt::red), QSize(6, 6))); vCurve->attach(this); vCurve->setVisible(false); svCurve = new QwtPlotCurve("SV"); svCurve->setYAxis(QwtPlot::yLeft); svCurve->setStyle(QwtPlotCurve::NoCurve); svCurve->setSymbol(new QwtSymbol(QwtSymbol::Star1,QColor(Qt::red), QColor(Qt::red), QSize(6, 6))); svCurve->attach(this); svCurve->setVisible(false); setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(360.0)); replot(); }
void QwtPlotPrintFilter::reset(QwtPlotItem *item) const { if ( d_data->cache == 0 ) return; const PrivateData::Cache &cache = *d_data->cache; switch(item->rtti()) { case QwtPlotItem::Rtti_PlotGrid: { QwtPlotGrid *grid = (QwtPlotGrid *)item; QPen pen = grid->majPen(); pen.setColor(cache.gridColors[0]); grid->setMajPen(pen); pen = grid->minPen(); pen.setColor(cache.gridColors[1]); grid->setMinPen(pen); break; } case QwtPlotItem::Rtti_PlotCurve: { QwtPlotCurve *c = (QwtPlotCurve *)item; QwtSymbol symbol = c->symbol(); if ( cache.curveSymbolPenColors.contains(c) ) { symbol.setPen(cache.curveSymbolPenColors[c]); } if ( cache.curveSymbolBrushColors.contains(c) ) { QBrush brush = symbol.brush(); brush.setColor(cache.curveSymbolBrushColors[c]); symbol.setBrush(brush); } c->setSymbol(symbol); if ( cache.curveColors.contains(c) ) { QPen pen = c->pen(); pen.setColor(cache.curveColors[c]); c->setPen(pen); } break; } case QwtPlotItem::Rtti_PlotMarker: { QwtPlotMarker *m = (QwtPlotMarker *)item; if ( cache.markerFonts.contains(m) ) { QwtText label = m->label(); label.setFont(cache.markerFonts[m]); m->setLabel(label); } if ( cache.markerLabelColors.contains(m) ) { QwtText label = m->label(); label.setColor(cache.markerLabelColors[m]); m->setLabel(label); } if ( cache.markerLineColors.contains(m) ) { QPen pen = m->linePen(); pen.setColor(cache.markerLineColors[m]); m->setLinePen(pen); } QwtSymbol symbol = m->symbol(); if ( cache.markerSymbolPenColors.contains(m) ) { QPen pen = symbol.pen(); pen.setColor(cache.markerSymbolPenColors[m]); symbol.setPen(pen); } if ( cache.markerSymbolBrushColors.contains(m) ) { QBrush brush = symbol.brush(); brush.setColor(cache.markerSymbolBrushColors[m]); symbol.setBrush(brush); } m->setSymbol(symbol); break; } default: break; } }
void 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; }
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."); }
Variog_plot:: Variog_plot( const Discrete_function& df, const Variogram_function_adaptor<Covariance<GsTLPoint> > *model, GsTLVector<double> angle, const std::vector<int>& pairs, const QString& title, bool y_starts_at_zero, QWidget *parent, const char *name) : QwtPlot(parent), pairs_shown_(false), model1_(0), model2_(0) { //this->setWindowFlags( ); setWindowFlags(Qt::SubWindow | Qt::MSWindowsFixedSizeDialogHint); if (name) setObjectName(name); setWindowIcon(QIcon()); //------------ // configure the plotting area //use a light gray for the grid QwtPlotGrid * grid = new QwtPlotGrid(); grid->enableX(true); grid->setPen( QPen( QColor(150,150,150), 0, Qt::DotLine ) ); grid->attach(this); this->axisScaleEngine(QwtPlot::xBottom)->setReference(0); this->axisScaleEngine(QwtPlot::yLeft)->setReference(0); this->axisScaleEngine(QwtPlot::xBottom)->setMargins(0,0.5); this->axisScaleEngine(QwtPlot::yLeft)->setMargins(0,0.5); this->axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating | QwtScaleEngine::IncludeReference); this->axisScaleEngine(QwtPlot::yLeft)->setAttributes(QwtScaleEngine::Floating | QwtScaleEngine::IncludeReference); QFont axis_font = this->axisFont( QwtPlot::xBottom ); axis_font.setPointSize( 7 ); QwtText t("distance"); t.setFont(axis_font); this->setAxisTitle( QwtPlot::xBottom,t); //------------- if( !title.isEmpty() ) { QFont title_font; QwtText T(title); title_font.setPointSize( 8 ); T.setFont(title_font); this->setTitle( T ); this->setWindowTitle( title ); } std::vector<double> x_vals = df.x_values(); std::vector<double> y_vals = df.y_values(); angle_ = angle; double* x = new double[x_vals.size()]; double* y = new double[x_vals.size()]; int actual_size = 0; for( int i=0 ; i < x_vals.size() ; i++ ) { if( GsTL::equals( x_vals[i], df.no_data_value(), 0.001 ) || GsTL::equals( y_vals[i], df.no_data_value(), 0.001 ) ) continue; x[actual_size] = x_vals[i]; y[actual_size] = y_vals[i]; pairs_.push_back( pairs[i] ); pairs_coord_x_.push_back( x_vals[i] ); pairs_coord_y_.push_back( y_vals[i] ); actual_size++; } model1_=model; const float ymargin = 1.05; const float xmargin = 1.06; if( actual_size > 0 ) { float ymax = *(std::max_element( y, y+actual_size )); float ymin = *(std::min_element( y, y+actual_size )); if( ymax == 0 && ymin == 0 ) this->setAxisAutoScale( QwtPlot::yLeft ); else if(ymax>0) this->setAxisScale( QwtPlot::yLeft, 0.0, ymax*ymargin ); else this->setAxisScale( QwtPlot::yLeft, ymin*(2-ymargin), ymax*ymargin ); if( y_starts_at_zero ) this->setAxisScale( QwtPlot::yLeft, 0.0, ymax*ymargin ); float xmax = *(std::max_element( x, x+actual_size )); this->setAxisScale( QwtPlot::xBottom, 0, xmax*xmargin ); } curve1_= new QwtPlotCurve("Discrete Function"); curve1_->setData( x, y, actual_size ); curve2_=new QwtPlotCurve("Model"); curve1_->attach(this); curve2_->attach(this); QwtSymbol symbol; symbol.setStyle(QwtSymbol::XCross); symbol.setPen( QPen(Qt::red, 3 ) ); symbol.setSize(7); curve1_->setSymbol(symbol); curve1_->setStyle(QwtPlotCurve::NoCurve); symbol.setStyle( QwtSymbol::NoSymbol ); symbol.setPen( QPen( Qt::blue, 1 ) ); curve2_->setSymbol(symbol); curve2_->setStyle(QwtPlotCurve::Lines); this->replot(); max_x_ = this->axisScaleDiv( QwtPlot::xBottom )->hBound(); /* QObject::connect( this, SIGNAL(plotMouseReleased(const QMouseEvent& )), this, SLOT(show_pairs_count(const QMouseEvent&)) ); */ delete [] x; delete [] y; }
QgsGradientColorRampDialog::QgsGradientColorRampDialog( const QgsGradientColorRamp &ramp, QWidget *parent ) : QDialog( parent ) , mRamp( ramp ) , mCurrentPlotColorComponent( -1 ) , mCurrentPlotMarkerIndex( 0 ) { setupUi( this ); #ifdef Q_OS_MAC setWindowModality( Qt::WindowModal ); #endif mPositionSpinBox->setShowClearButton( false ); btnColor1->setAllowOpacity( true ); btnColor1->setColorDialogTitle( tr( "Select Ramp Color" ) ); btnColor1->setContext( QStringLiteral( "symbology" ) ); btnColor1->setShowNoColor( true ); btnColor1->setNoColorString( tr( "Transparent" ) ); btnColor2->setAllowOpacity( true ); btnColor2->setColorDialogTitle( tr( "Select Ramp Color" ) ); btnColor2->setContext( QStringLiteral( "symbology" ) ); btnColor2->setShowNoColor( true ); btnColor2->setNoColorString( tr( "Transparent" ) ); updateColorButtons(); connect( btnColor1, &QgsColorButton::colorChanged, this, &QgsGradientColorRampDialog::setColor1 ); connect( btnColor2, &QgsColorButton::colorChanged, this, &QgsGradientColorRampDialog::setColor2 ); // fill type combobox cboType->blockSignals( true ); cboType->addItem( tr( "Discrete" ) ); cboType->addItem( tr( "Continuous" ) ); if ( mRamp.isDiscrete() ) cboType->setCurrentIndex( 0 ); else cboType->setCurrentIndex( 1 ); cboType->blockSignals( false ); if ( mRamp.info().isEmpty() ) btnInformation->setEnabled( false ); mStopEditor->setGradientRamp( mRamp ); connect( mStopEditor, &QgsGradientStopEditor::changed, this, &QgsGradientColorRampDialog::updateRampFromStopEditor ); connect( mColorWidget, &QgsCompoundColorWidget::currentColorChanged, this, &QgsGradientColorRampDialog::colorWidgetChanged ); connect( mDeleteStopButton, &QAbstractButton::clicked, mStopEditor, &QgsGradientStopEditor::deleteSelectedStop ); QgsSettings settings; restoreGeometry( settings.value( QStringLiteral( "Windows/GradientEditor/geometry" ) ).toByteArray() ); // hide the ugly canvas frame mPlot->setFrameStyle( QFrame::NoFrame ); QFrame *plotCanvasFrame = dynamic_cast<QFrame *>( mPlot->canvas() ); if ( plotCanvasFrame ) plotCanvasFrame->setFrameStyle( QFrame::NoFrame ); mPlot->setAxisScale( QwtPlot::yLeft, 0.0, 1.0 ); mPlot->enableAxis( QwtPlot::yLeft, false ); // add a grid QwtPlotGrid *grid = new QwtPlotGrid(); QwtScaleDiv gridDiv( 0.0, 1.0, QList<double>(), QList<double>(), QList<double>() << 0.2 << 0.4 << 0.6 << 0.8 ); grid->setXDiv( gridDiv ); grid->setYDiv( gridDiv ); grid->setPen( QPen( QColor( 0, 0, 0, 50 ) ) ); grid->attach( mPlot ); mLightnessCurve = new QwtPlotCurve(); mLightnessCurve->setTitle( QStringLiteral( "Lightness" ) ); mLightnessCurve->setPen( QPen( QColor( 70, 150, 255 ), 0.0 ) ), mLightnessCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); mLightnessCurve->attach( mPlot ); mHueCurve = new QwtPlotCurve(); mHueCurve->setTitle( QStringLiteral( "Hue" ) ); mHueCurve->setPen( QPen( QColor( 255, 215, 70 ), 0.0 ) ), mHueCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); mHueCurve->attach( mPlot ); mSaturationCurve = new QwtPlotCurve(); mSaturationCurve->setTitle( QStringLiteral( "Saturation" ) ); mSaturationCurve->setPen( QPen( QColor( 255, 70, 150 ), 0.0 ) ), mSaturationCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); mSaturationCurve->attach( mPlot ); mAlphaCurve = new QwtPlotCurve(); mAlphaCurve->setTitle( QStringLiteral( "Opacity" ) ); mAlphaCurve->setPen( QPen( QColor( 50, 50, 50 ), 0.0 ) ), mAlphaCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); mAlphaCurve->attach( mPlot ); mPlotFilter = new QgsGradientPlotEventFilter( mPlot ); connect( mPlotFilter, &QgsGradientPlotEventFilter::mousePress, this, &QgsGradientColorRampDialog::plotMousePress ); connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseRelease, this, &QgsGradientColorRampDialog::plotMouseRelease ); connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseMove, this, &QgsGradientColorRampDialog::plotMouseMove ); mPlotHueCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotHue" ), false ).toBool() ); mPlotLightnessCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotLightness" ), true ).toBool() ); mPlotSaturationCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotSaturation" ), false ).toBool() ); mPlotAlphaCheckbox->setChecked( settings.value( QStringLiteral( "GradientEditor/plotAlpha" ), false ).toBool() ); mHueCurve->setVisible( mPlotHueCheckbox->isChecked() ); mLightnessCurve->setVisible( mPlotLightnessCheckbox->isChecked() ); mSaturationCurve->setVisible( mPlotSaturationCheckbox->isChecked() ); mAlphaCurve->setVisible( mPlotAlphaCheckbox->isChecked() ); connect( mStopEditor, &QgsGradientStopEditor::selectedStopChanged, this, &QgsGradientColorRampDialog::selectedStopChanged ); mStopEditor->selectStop( 0 ); connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsGradientColorRampDialog::showHelp ); }
EigenPlotDlg::EigenPlotDlg(QWidget* parent) : QDialog(parent), mpPlot(NULL), mpCurve(NULL), mpComponentsSpin(NULL) { // Eigen plot mpPlot = new QwtPlot(this); mpPlot->installEventFilter(this); mpPlot->setAutoFillBackground(true); QFont ftAxis = QApplication::font(); ftAxis.setBold(true); ftAxis.setPointSize(10); QwtText bottomText("Number of Components"); bottomText.setFont(ftAxis); mpPlot->setAxisTitle(QwtPlot::xBottom, bottomText); QwtText leftText("Eigen Values"); leftText.setFont(ftAxis); mpPlot->setAxisTitle(QwtPlot::yLeft, leftText); QwtScaleEngine* pLinearScale = mpPlot->axisScaleEngine(QwtPlot::xBottom); pLinearScale->setAttribute(QwtScaleEngine::Floating); QwtLog10ScaleEngine* pLogScale = new QwtLog10ScaleEngine(); pLogScale->setAttribute(QwtScaleEngine::Floating); mpPlot->setAxisScaleEngine(QwtPlot::yLeft, pLogScale); QPalette plotPalette = mpPlot->palette(); plotPalette.setColor(QPalette::Window, Qt::white); mpPlot->setPalette(plotPalette); QwtPlotCanvas* pPlotCanvas = mpPlot->canvas(); pPlotCanvas->setFrameStyle(QFrame::NoFrame); QwtPlotLayout* pPlotLayout = mpPlot->plotLayout(); pPlotLayout->setMargin(5); QwtPlotGrid* pPlotGrid = new QwtPlotGrid(); pPlotGrid->setPen(QPen(Qt::DotLine)); pPlotGrid->attach(mpPlot); mpPlot->replot(); // Number of components QLabel* pComponentsLabel = new QLabel("Number of Components:", this); mpComponentsSpin = new QSpinBox(this); mpComponentsSpin->setFixedWidth(50); mpComponentsSpin->setMinimum(1); QLabel* pDescriptionLabel = new QLabel("To set, left click in the plot or enter a value.", this); pDescriptionLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); pDescriptionLabel->setWordWrap(true); QFont descriptionFont(pDescriptionLabel->font()); descriptionFont.setItalic(true); pDescriptionLabel->setFont(descriptionFont); QHBoxLayout* pComponentsLayout = new QHBoxLayout(); pComponentsLayout->setMargin(0); pComponentsLayout->setSpacing(5); pComponentsLayout->addWidget(pComponentsLabel); pComponentsLayout->addWidget(mpComponentsSpin); pComponentsLayout->addWidget(pDescriptionLabel, 10); // Horizontal line QFrame* pLine = new QFrame(this); pLine->setFrameStyle(QFrame::HLine | QFrame::Sunken); // Buttons QPushButton* pOk = new QPushButton("&OK", this); QPushButton* pCancel = new QPushButton("&Cancel", this); connect(pOk, SIGNAL(clicked()), this, SLOT(accept())); connect(pCancel, SIGNAL(clicked()), this, SLOT(reject())); QHBoxLayout* pButtonLayout = new QHBoxLayout(); pButtonLayout->setMargin(0); pButtonLayout->setSpacing(5); pButtonLayout->addStretch(10); pButtonLayout->addWidget(pOk); pButtonLayout->addWidget(pCancel); // Layout QGridLayout* pGrid = new QGridLayout(this); pGrid->setMargin(10); pGrid->setSpacing(10); pGrid->addWidget(mpPlot, 0, 0); pGrid->addLayout(pComponentsLayout, 1, 0); pGrid->addWidget(pLine, 2, 0); pGrid->addLayout(pButtonLayout, 3, 0); pGrid->setRowStretch(0, 10); // Initialization setWindowTitle("PCA Components"); setModal(true); resize(440, 300); }
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) { // create menu bar and actions createActions(); createMenus(); // initialize FFTW m_main_signal = new DataFft(); m_qpoint_magnitude.resize(m_main_signal->get_fft_size()); setCentralWidget(new QWidget(this)); QVBoxLayout *layout = new QVBoxLayout; layout->setSpacing(5); layout->setMargin(15); //------------qwt plot start--------------------- QString label; label.sprintf( "FFT plot" ); QwtText text(label); m_main_plot = new QwtPlot(text, parent); m_main_plot->setCanvasBackground(QColor( Qt::darkBlue )); m_main_plot->setAxisScale( QwtPlot::xBottom, 0, m_main_signal->get_fft_size() / 2 ); m_main_plot->setAxisTitle( QwtPlot::xBottom, "FFT points [-]" ); m_main_plot->setAxisScale( QwtPlot::yLeft, -250, 2 ); m_main_plot->setAxisTitle( QwtPlot::yLeft, "Sine magnitude [dB]" ); m_main_plot->enableAxis(QwtPlot::yRight,true); m_main_plot->setAxisScale( QwtPlot::yRight, -250, 2 ); m_main_plot->enableAxis(QwtPlot::xTop,true); m_main_plot->setAxisScale( QwtPlot::xTop, 0, m_main_signal->get_fft_size() / 2 ); QwtPlotGrid *grid = new QwtPlotGrid(); grid->setPen( QPen( Qt::green, 0.0, Qt::DotLine ) ); grid->enableX( true ); grid->enableXMin( true ); grid->enableY( true ); grid->enableYMin( false ); grid->attach( m_main_plot ); m_slider_freq = new Slider(this, 2, sineStartValue); m_main_plot->setCanvasBackground( QColor( Qt::white ) ); m_slider_scroll = new Slider(this, 2, 2500); // add curve m_main_curve = new QwtPlotCurve("Main curve"); // connect or copy the data to the curves int iter = 0; for(auto it = m_qpoint_magnitude.begin(); it != m_qpoint_magnitude.end(); it++ , iter++) { *it = QPointF(iter,iter); // initialize 'x' axis } layout->addWidget(m_slider_freq); layout->addWidget(m_slider_scroll); layout->addWidget(m_main_plot); centralWidget()->setLayout(layout); m_main_curve->setSamples(m_qpoint_magnitude); m_main_curve->setPen(QPen(Qt::green)); m_main_curve->attach(m_main_plot); // finally, refresh the plot m_main_plot->replot(); }
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 ); }
//--------------------------------------------------------------------------- void Plots::Plots_Create(PlotType Type) { // Paddings if (paddings[Type]==NULL) { paddings[Type]=new QWidget(this); paddings[Type]->setVisible(false); } // General design of plot QwtPlot* plot = new QwtPlot(this); plot->setVisible(false); plot->setMinimumHeight(1); plot->enableAxis(QwtPlot::xBottom, Type==PlotType_Axis); plot->setAxisMaxMajor(QwtPlot::yLeft, 0); plot->setAxisMaxMinor(QwtPlot::yLeft, 0); plot->setAxisScale(QwtPlot::xBottom, 0, FileInfoData->Videos[0]->x_Max[XAxis_Kind_index]); if (PerPlotGroup[Type].Count>3) plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // Plot grid QwtPlotGrid *grid = new QwtPlotGrid(); grid->enableXMin(true); grid->enableYMin(true); grid->setMajorPen(Qt::darkGray, 0, Qt::DotLine ); grid->setMinorPen(Qt::gray, 0 , Qt::DotLine ); grid->attach(plot); // Plot curves for(unsigned j=0; j<PerPlotGroup[Type].Count; ++j) { plotsCurves[Type][j] = new QwtPlotCurve(PerPlotName[PerPlotGroup[Type].Start+j].Name); QColor c; switch (PerPlotGroup[Type].Count) { case 1 : switch (Type) { case PlotType_YDiff: c=Qt::darkGreen; break; case PlotType_UDiff: c=Qt::darkBlue; break; case PlotType_VDiff: c=Qt::darkRed; break; default: c=Qt::black; } break; case 2 : switch (j) { case 0: c=Qt::darkGreen; break; case 1: c=Qt::darkRed; break; default: c=Qt::black; } break; case 3 : switch (j) { case 0: c=Qt::darkRed; break; case 1: c=Qt::darkBlue; break; case 2: c=Qt::darkGreen; break; default: c=Qt::black; } break; case 5 : switch (j) { case 0: c=Qt::red; break; case 1: c=QColor::fromRgb(0x00, 0x66, 0x00); break; //Qt::green case 2: c=Qt::black; break; case 3: c=Qt::green; break; case 4: c=Qt::red; break; default: c=Qt::black; } break; default: c=Qt::black; } plotsCurves[Type][j]->setPen(c); plotsCurves[Type][j]->setRenderHint(QwtPlotItem::RenderAntialiased); plotsCurves[Type][j]->setZ(plotsCurves[Type][j]->z()-j); //Invert data order (e.g. MAX before MIN) plotsCurves[Type][j]->attach(plot); } // Legends QwtLegend *legend = new QwtLegend(this); legend->setVisible(false); legend->setMinimumHeight(1); legend->setMaxColumns(1); QFont Font=legend->font(); #ifdef _WIN32 Font.setPointSize(6); #else // _WIN32 Font.setPointSize(8); #endif //_WIN32 legend->setFont(Font); connect(plot, SIGNAL(legendDataChanged(const QVariant &, const QList<QwtLegendData> &)), legend, SLOT(updateLegend(const QVariant &, const QList<QwtLegendData> &))); plot->updateLegend(); // Assignment plots[Type]=plot; legends[Type]=legend; // Pickers plotsPickers[Type] = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, plots[Type]->canvas() ); plotsPickers[Type]->setStateMachine( new QwtPickerDragPointMachine () ); plotsPickers[Type]->setRubberBandPen( QColor( Qt::green ) ); plotsPickers[Type]->setTrackerPen( QColor( Qt::white ) ); connect(plotsPickers[Type], SIGNAL(moved(const QPointF&)), SLOT(plot_moved(const QPointF&))); connect(plotsPickers[Type], SIGNAL(selected(const QPointF&)), SLOT(plot_moved(const QPointF&))); // Marker QwtPlotMarker* plotMarker=new QwtPlotMarker; plotMarker->setLineStyle(QwtPlotMarker::VLine); plotMarker->setLinePen(QPen(Qt::magenta, 1)); plotMarker->setXValue(0); plotMarker->attach(plot); plotsMarkers[Type]=plotMarker; }
PlotForm::PlotForm() { m_data[0] = 0; m_data[1] = 0; m_data[2] = 0; m_data_len = 0; x_axis_type = 0; widget.setupUi(this); curve[0].setColor(Qt::yellow); curve[0].attach(widget.qwtPlot); curve[0].setVisible(true); curve[1].setColor(Qt::green); curve[1].attach(widget.qwtPlot); curve[1].setVisible(true); setDataLen(512); noise(); // grid QwtPlotGrid *grid = new QwtPlotGrid(); grid->enableXMin(true); grid->setMajorPen(QPen(Qt::white, 0, Qt::DotLine)); grid->setMinorPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(widget.qwtPlot); //scale widget.qwtPlot->setCanvasBackground(QColor(Qt::black)); QwtPlotPicker *d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, widget.qwtPlot->canvas()); d_picker->setStateMachine(new QwtPickerDragPointMachine()); d_picker->setRubberBandPen(QColor(Qt::green)); d_picker->setRubberBand(QwtPicker::CrossRubberBand); d_picker->setTrackerPen(QColor(Qt::green)); QwtPlotZoomer* zoomer = new QwtPlotZoomer( widget.qwtPlot->canvas() ); zoomer->setRubberBandPen( QColor( Qt::white ) ); zoomer->setTrackerPen( QColor( Qt::white ) ); zoomer->setMousePattern( QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier ); zoomer->setMousePattern( QwtEventPattern::MouseSelect3, Qt::RightButton ); mr_center.setLineStyle(QwtPlotMarker::VLine); mr_center.setLinePen(QPen(Qt::darkRed, 0, Qt::SolidLine)); mr_center.setXValue(840.0); mr_center.attach(widget.qwtPlot); mr_center.setVisible(false); mr_left.setLineStyle(QwtPlotMarker::VLine); mr_left.setLinePen(QPen(Qt::darkRed, 0, Qt::DotLine)); mr_left.setXValue(830.0); mr_left.attach(widget.qwtPlot); mr_left.setVisible(false); mr_right.setLineStyle(QwtPlotMarker::VLine); mr_right.setLinePen(QPen(Qt::darkRed, 0, Qt::DotLine)); mr_right.setXValue(850.0); mr_right.attach(widget.qwtPlot); mr_right.setVisible(false); QwtPlotPanner *panner = new QwtPlotPanner( widget.qwtPlot->canvas() ); panner->setMouseButton( Qt::MidButton ); widget.qwtPlot->plotLayout()->setAlignCanvasToScales(true); dvalidator = new QDoubleValidator(); widget.leMin->setValidator(dvalidator); widget.leMax->setValidator(dvalidator); connect(widget.btnYAxisLog, SIGNAL(clicked(bool)), this, SLOT(setScaleEngineY(bool))); connect(widget.btnAutoScale, SIGNAL(clicked(bool)), this, SLOT(setAutoScale(bool))); connect(widget.btnSave, SIGNAL(clicked()), this, SLOT(save())); connect(widget.btnZoomIn , SIGNAL(clicked()), this, SLOT(zoomIn ())); connect(widget.btnZoomOut, SIGNAL(clicked()), this, SLOT(zoomOut())); // connect(widget.leMin, SIGNAL(valueChanged(double)), this, SLOT(rescale(double))); // connect(widget.leMax, SIGNAL(valueChanged(double)), this, SLOT(rescale(double))); }
void scopePlot::init(QString title) { setup=true; setCentralWidget(wd); connect(ui.offsetWheel, SIGNAL(valueChanged(double)),SLOT(slotOffsetChanged(double ))); connect(ui.rangeWheel, SIGNAL(valueChanged(double)), SLOT(slotRangeChanged(double ))); connect(ui.samplesPushButton, SIGNAL(clicked()), this, SLOT(slotSamplesButtton())); plW=ui.plotWindow; plW->setTitle(title); plW->setCanvasBackground(Qt::darkBlue); curve1->attach(plW); curve2->attach(plW); curve3->attach(plW); curve4->attach(plW); plW->setAxisTitle(QwtPlot::xBottom,xAxisTitle); plW->setAxisScale(QwtPlot::xBottom, 0, 100); plW->setAxisTitle(QwtPlot::yLeft, "Values"); plW->setAxisScale(QwtPlot::yLeft, -1.5, 1.5); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->setMajorPen(QPen(Qt::white, 0, Qt::DotLine)); grid->setMinorPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(plW); QwtText m1("M1"); m1.setColor(QColor(Qt::white)); marker1=new QwtPlotMarker(); marker1->setValue(0.0, 0.0); marker1->setLabel(m1); marker1->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom); marker1->setLinePen(QPen(QColor(200,150,0), 0, Qt::DashDotLine)); marker1->setSymbol( new QwtSymbol(QwtSymbol::Diamond,QColor(Qt::green), QColor(Qt::green), QSize(7,7))); // marker1->hide(); marker1->attach(plW); QwtText m2("M2"); m2.setColor(QColor(Qt::white)); marker2=new QwtPlotMarker(); marker2->setValue(0.0, 0.0); marker2->setLabel(m2); marker2->setLabelAlignment(Qt::AlignLeft | Qt::AlignTop); marker2->setLinePen(QPen(QColor(200,150,0), 0, Qt::DashDotLine)); marker2->setSymbol( new QwtSymbol(QwtSymbol::Diamond,QColor(Qt::yellow), QColor(Qt::yellow), QSize(7,7))); // marker2->hide(); marker2->attach(plW); legend = new QwtLegend; legend->setFrameStyle(QFrame::Box|QFrame::Sunken); legend->setDefaultItemMode(QwtLegendData::Checkable); QPalette pal(legend->palette()); pal.setColor(QPalette::Window,Qt::darkBlue); pal.setColor(QPalette::WindowText,Qt::white); pal.setColor(QPalette::Text,Qt::black); legend->setPalette(pal); plW->insertLegend(legend, QwtPlot::BottomLegend); picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, plW->canvas()); picker->setStateMachine(new QwtPickerDragPointMachine()); picker->setRubberBandPen(QColor(Qt::green)); picker->setRubberBand(QwtPicker::CrossRubberBand); picker->setTrackerPen(QColor(Qt::white)); picker->setEnabled(true); plW->replot(); QwtPlotItemList items = plW->itemList( QwtPlotItem::Rtti_PlotCurve); for ( int i = 0; i < items.size(); i++ ) { const QVariant itemInfo = plW->itemToInfo( items[i] ); QwtLegendLabel *legendLabel =qobject_cast<QwtLegendLabel *>( legend->legendWidget( itemInfo ) ); if (legendLabel ) { legendLabel->setChecked( true ); } items[i]->setVisible( true ); } connect(picker, SIGNAL(moved(const QPointF &)),SLOT(pickerMoved(const QPointF &))); connect(picker, SIGNAL(selected(const QPointF &)), SLOT(pickerSelected(const QPointF &))); connect(legend, SIGNAL(checked(const QVariant &, bool ,int)),SLOT(legendClicked(const QVariant &,bool))); connect(ui.nextButton, SIGNAL(clicked()),SLOT(slotNext())); connect(ui.previousButton, SIGNAL(clicked()),SLOT(slotPrevious())); plW->setAxisTitle(QwtPlot::xBottom,xAxisTitle); xOffset=0; }
void CurveWidget::initialize(bool zoom) { setContentsMargins(2, 2, 2, 2); setMinimumHeight(338); int _width = QApplication::desktop()->availableGeometry().width(); switch (_width) { case 1280: q_width = 493; break; case 1366: q_width = 532; break; default: q_width = 493; break; } setFixedWidth(q_width); plotLayout()->setAlignCanvasToScales( true); setAutoReplot(); //setAxisAutoScale(QwtPlot::yLeft, false); QwtPlotGrid *grid = new QwtPlotGrid(); grid->setPen(QColor(80, 80, 80, 100), 0.5, Qt::SolidLine); grid->enableX(true); grid->enableY(true); grid->attach(this); q_origin = new QwtPlotMarker(); q_origin->setLineStyle( QwtPlotMarker::Cross); q_origin->setLinePen(QColor(100, 100, 100, 100), 1.0, Qt::DashLine ); q_origin->attach(this); setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw()); TimePlotPicker* picker = new TimePlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, canvas()); picker->setStateMachine(new QwtPickerDragPointMachine()); picker->setRubberBandPen(QColor(100, 100, 100, 200)); picker->setTrackerPen(QColor(128, 128, 200, 200)); // zoomer if (zoom) { q_zoomer = new Zoomer(QwtPlot::xBottom, QwtPlot::yLeft, canvas()); q_zoomer->setRubberBand(QwtPicker::RectRubberBand); q_zoomer->setRubberBandPen(QColor(Qt::green)); q_zoomer->setTrackerMode(QwtPicker::ActiveOnly); q_zoomer->setTrackerPen(QColor(Qt::white)); } // scale //setAxisScale( QwtPlot::xBottom, 0, 200 ); //setAxisScale( QwtPlot::yLeft, 400, 800 ); //! curve //srand(QDateTime::currentDateTime().fromMSecsSinceEpoch()); // QVector<QPointF> samples(0); addCurve("Curve 1", QPen(QColor("#0c78a6"), 1), samples); addCurve("Curve 2", QPen(QColor("#5fd43b"), 1), samples); // Legend QwtPlotLegendItem* legendItem = new JLegendItem; legendItem->setMaxColumns(q_curves.count()); legendItem->attach(this); }
//--------------------------------------------------------------------------- JrkPlotDialog::JrkPlotDialog(jrk_variables *indata, jrk_pid_variables *pid_indata, QWidget *parent) : QDialog(parent), ui(new Ui::JrkPlotDialog) { int i; ui->setupUi(this); setLayout(ui->mainLayout); interval(200); history(10); setSamples(); data_ptr = indata; pid_data_ptr = pid_indata; timeData = (double *) malloc(SAMPLES * sizeof(double)); reset(); ui->jrkPlot->setAutoReplot(false); ui->jrkPlot->canvas()->setBorderRadius(0); ui->jrkPlot->plotLayout()->setAlignCanvasToScales(true); ui->jrkPlot->setCanvasBackground(Qt::white); QwtLegend *legend = new QwtLegend; legend->setItemMode(QwtLegend::CheckableItem); ui->jrkPlot->insertLegend(legend, QwtPlot::RightLegend); ui->jrkPlot->setAxisTitle(QwtPlot::xBottom, "Seconds"); ui->jrkPlot->setAxisScale(QwtPlot::xBottom, timeData[0], timeData[SAMPLES - 1]); // ui->jrkPlot->setAxisLabelRotation( QwtPlot::xBottom, -50.0 ); ui->jrkPlot->setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom ); QwtScaleWidget *scaleWidget = ui->jrkPlot->axisWidget(QwtPlot::xBottom); i = QFontMetrics(scaleWidget->font()).height(); scaleWidget->setMinBorderDist(0, i / 2); ui->jrkPlot->setAxisTitle(QwtPlot::yLeft, "%"); ui->jrkPlot->setAxisScale(QwtPlot::yLeft, -100, 100); // picker, panner, zoomer plot_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, ui->jrkPlot->canvas()); #if 0 plot_picker->setStateMachine(new QwtPickerDragPointMachine()); plot_picker->setRubberBandPen(QColor(Qt::black)); plot_picker->setRubberBand(QwtPicker::CrossRubberBand ); #endif plot_picker->setTrackerPen(QColor(Qt::black)); // panning with the left mouse button plot_panner = new QwtPlotPanner(ui->jrkPlot->canvas()); plot_panner->setUpdatesEnabled(true); // zoom in/out with the wheel plot_zoomer = new QwtPlotMagnifier(ui->jrkPlot->canvas()); // grid QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin( true ); grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::black, 0, Qt::DotLine)); grid->attach(ui->jrkPlot); // curves, scale is in % createCurve("Input", Qt::gray, false, 4095); createCurve("Target", Qt::blue, false, 4095); createCurve("Feedback", Qt::darkBlue, false, 4095); createCurve("Scaled feedback", Qt::magenta, false, 4095); createCurve("Error", Qt::red, true, 4095); createCurve("Integral", Qt::darkGreen, false, 1000); createCurve("Derivative", Qt::yellow, false, 1000); createCurve("Duty cycle target", Qt::darkCyan, false, 0600); createCurve("Duty cycle", Qt::darkRed, false, 0600); createCurve("Current", Qt::black, true, 0050); plot_timer = new QTimer(this); plot_timer->setInterval(INTERVAL); connect(plot_timer, SIGNAL(timeout()), this, SLOT(onUpdateGraph())); connect(ui->jrkPlot, SIGNAL(legendChecked(QwtPlotItem *, bool)), SLOT(showCurve(QwtPlotItem *, bool))); #if 0 connect(plot_picker, SIGNAL(moved(const QPoint &)), SLOT(picker_moved(const QPoint &))); connect(plot_picker, SIGNAL(selected(const QPolygon &)), SLOT(picker_selected(const QPolygon &))); #endif connect(this, SIGNAL(finished(int)), this, SLOT(onFinished(int))); // plot_timer->start(); }
void QwtPlotPrintFilter::apply(QwtPlotItem *item) const { PrivateData::Cache &cache = *d_data->cache; switch(item->rtti()) { case QwtPlotItem::Rtti_PlotGrid: { QwtPlotGrid *grid = (QwtPlotGrid *)item; QPen pen = grid->majPen(); cache.gridColors[0] = pen.color(); pen.setColor(color(pen.color(), MajorGrid)); grid->setMajPen(pen); pen = grid->minPen(); cache.gridColors[1] = pen.color(); pen.setColor(color(pen.color(), MinorGrid)); grid->setMinPen(pen); break; } case QwtPlotItem::Rtti_PlotCurve: { QwtPlotCurve *c = (QwtPlotCurve *)item; QwtSymbol symbol = c->symbol(); QPen pen = symbol.pen(); cache.curveSymbolPenColors.insert(c, pen.color()); pen.setColor(color(pen.color(), CurveSymbol)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.curveSymbolBrushColors.insert(c, brush.color()); brush.setColor(color(brush.color(), CurveSymbol)); symbol.setBrush(brush); c->setSymbol(symbol); pen = c->pen(); cache.curveColors.insert(c, pen.color()); pen.setColor(color(pen.color(), Curve)); c->setPen(pen); break; } case QwtPlotItem::Rtti_PlotMarker: { QwtPlotMarker *m = (QwtPlotMarker *)item; QwtText label = m->label(); cache.markerFonts.insert(m, label.font()); label.setFont(font(label.font(), Marker)); cache.markerLabelColors.insert(m, label.color()); label.setColor(color(label.color(), Marker)); m->setLabel(label); QPen pen = m->linePen(); cache.markerLineColors.insert(m, pen.color()); pen.setColor(color(pen.color(), Marker)); m->setLinePen(pen); QwtSymbol symbol = m->symbol(); pen = symbol.pen(); cache.markerSymbolPenColors.insert(m, pen.color()); pen.setColor(color(pen.color(), MarkerSymbol)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.markerSymbolBrushColors.insert(m, brush.color()); brush.setColor(color(brush.color(), MarkerSymbol)); symbol.setBrush(brush); m->setSymbol(symbol); break; } default: break; } }
COscMain::COscMain() : QMainWindow() { m_dev = new CUsbIo(); m_running = false; ui.setupUi( this ); connect( ui.actionQuit, SIGNAL(triggered()), this, SLOT(close()) ); connect( ui.actionRun, SIGNAL(triggered()), this, SLOT(start()) ); connect( ui.actionConnect, SIGNAL(triggered()), this, SLOT(open()) ); COscScaler * scaler = new COscScaler( ui.plot ); scaler->setWheelZoomX( true ); scaler->setWheelZoomY( true ); scaler->setEqualScales( false ); scaler->setSaveScales( false ); QwtPlotGrid * g = new QwtPlotGrid(); g->enableXMin( true ); g->enableYMin( true ); g->setPen( QPen( Qt::gray, 0.0, Qt::DotLine ) ); g->attach( ui.plot ); g = new QwtPlotGrid(); g->enableX( true ); g->enableY( true ); g->setPen( QPen( Qt::gray, 0.0, Qt::SolidLine ) ); g->attach( ui.plot ); connect( this, SIGNAL(sigReplot()), this, SLOT(replot()), Qt::QueuedConnection ); ui.plot->canvas()->setBorderRadius( 10 ); ui.plot->plotLayout()->setAlignCanvasToScales( true ); // Nice background coloration. QPalette pal = ui.plot->canvas()->palette(); QLinearGradient gr( 0.0, 0.0, 1.0, 1.0 ); gr.setCoordinateMode( QGradient::StretchToDeviceMode ); gr.setColorAt( 0.0, QColor( 200, 200, 230 ) ); gr.setColorAt( 1.0, QColor( 230, 230, 250 ) ); pal.setBrush( QPalette::Window, QBrush( gr ) ); ui.plot->canvas()->setPalette( pal ); m_ptsPerSecond = new QSpinBox(); m_ptsPerSecond->setRange( 1, 128 ); m_ptsPerSecond->setPrefix( tr( "Pts/sec" ) ); m_ptsPerSecond->setValue( 50 ); connect( m_ptsPerSecond, SIGNAL(editingFinished()), this, SLOT(settingsChanged()) ); m_seconds = new QSpinBox(); m_seconds->setRange( 1, 600 ); m_seconds->setPrefix( tr( "Seconds" ) ); m_seconds->setValue( 3 ); connect( m_seconds, SIGNAL(editingFinished()), this, SLOT(settingsChanged()) ); m_curvesCnt = new QSpinBox(); m_curvesCnt->setRange( 1, 10 ); m_curvesCnt->setValue( 3 ); m_curvesCnt->setPrefix( tr( "Curves" ) ); connect( m_curvesCnt, SIGNAL(editingFinished()), this, SLOT(curvesCntChanged()) ); ui.sb->addWidget( m_ptsPerSecond ); ui.sb->addWidget( m_seconds ); ui.sb->addWidget( m_curvesCnt ); ui.sb->adjustSize(); open(); curvesCntChanged(); settingsChanged(); /*if ( m_dev->isOpen() ) { m_dev->setTimer( 12000, CUsbIo::T1024 ); m_dev->setTimer( 6000, CUsbIo::T1024 ); m_dev->setTimer( 255, CUsbIo::T1024 ); }*/ }
signalForm::signalForm(dualVector<double>* gidroSignal){ log.open("signalForm.log"); log << "constructor call" << std::endl; setupUi(this); signal = gidroSignal; qwtPlot_signal->setAutoReplot(false); //plot qwtPlot_signal->setCanvasBackground(QColor(Qt::darkBlue)); qwtPlot_signal->setTitle("Signal"); qwtPlot_signal->setAxisTitle(QwtPlot::xBottom, "Time points"); qwtPlot_signal->setAxisTitle(QwtPlot::yLeft, "Amplitude"); //legend QwtLegend *legend = new QwtLegend; qwtPlot_signal->insertLegend(legend, QwtPlot::BottomLegend); //grid QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(qwtPlot_signal); //curve signalCurve = new QwtPlotCurve("Gidrophone 0 signal"); signalCurve->setPen(QPen(Qt::yellow)); signalCurve->attach(qwtPlot_signal); //display signal curve showSignalFromGidrophone(0); // zoomer signalZoomer = new ScrollZoomer( /*QwtPlot::xBottom, QwtPlot::yLeft, */ qwtPlot_signal->canvas()); signalZoomer->setRubberBand(QwtPicker::RectRubberBand); signalZoomer->setRubberBandPen(QColor(Qt::green)); signalZoomer->setTrackerMode(QwtPicker::ActiveOnly); signalZoomer->setTrackerPen(QColor(Qt::white)); // panner signalPanner = new QwtPlotPanner(qwtPlot_signal->canvas()); signalPanner->setMouseButton(Qt::MidButton); // picker signalPicker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, qwtPlot_signal->canvas()); signalPicker->setStateMachine(new QwtPickerDragPointMachine()); signalPicker->setRubberBandPen(QColor(Qt::green)); signalPicker->setRubberBand(QwtPicker::CrossRubberBand); signalPicker->setTrackerPen(QColor(Qt::white)); //setCentralWidget(qwtPlot_signal); // toolbar QToolBar *toolBar = new QToolBar(this); // zoom button QToolButton *btnZoom = new QToolButton(toolBar); btnZoom->setText("Zoom"); btnZoom->setIcon(QIcon(zoom_xpm)); btnZoom->setCheckable(true); btnZoom->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); toolBar->addWidget(btnZoom); connect(btnZoom, SIGNAL(toggled(bool)), SLOT(enableZoomMode(bool))); // adjust spinboxes and connect to showSignalFromGidrophone() spinBox_gidrophonenumber->setMinimum(0); spinBox_gidrophonenumber->setMaximum(signal->sizex() - 1); connect(spinBox_gidrophonenumber, SIGNAL( valueChanged(int) ), this, SLOT( showSignalFromGidrophone(int) ) ); enableZoomMode(false); qwtPlot_signal->setAutoReplot(true); }