// MyPlot2D::MyPlot2D(QWidget *parent, const char *name) MyPlot2D::MyPlot2D( QWidget *parent ): QwtPlot(parent) { setAutoReplot( false ); setTitle( "Comparison of WATER FIT against Measurements" ); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setBorderRadius( 10 ); setCanvas( canvas ); setCanvasBackground( QColor( "LightGray" ) ); // 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, "Distance from CAX (cm)" ); setAxisTitle( QwtPlot::yLeft, "Relative Output Factor" ); // setAxisTitle( QwtPlot::yRight, "Phase [deg]" ); // setAxisMaxMajor( QwtPlot::xBottom, 6 ); // setAxisMaxMinor( QwtPlot::xBottom, 9 ); // setAxisScaleEngine( QwtPlot::xBottom, new QwtLogScaleEngine ); setAutoReplot( true ); }
BarChart::BarChart( QWidget *parent ): QwtPlot( parent ) { const struct { const char *distro; const int hits; QColor color; } pageHits[] = { { "Arch", 1114, QColor( "DodgerBlue" ) }, { "Debian", 1373, QColor( "#d70751" ) }, { "Fedora", 1638, QColor( "SteelBlue" ) }, { "Mageia", 1395, QColor( "Indigo" ) }, { "Mint", 3874, QColor( 183, 255, 183 ) }, { "openSuSE", 1532, QColor( 115, 186, 37 ) }, { "Puppy", 1059, QColor( "LightSkyBlue" ) }, { "Ubuntu", 2391, QColor( "FireBrick" ) } }; setAutoFillBackground( true ); setPalette( QColor( "Linen" ) ); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setLineWidth( 2 ); canvas->setFrameStyle( QFrame::Box | QFrame::Sunken ); canvas->setBorderRadius( 10 ); QPalette canvasPalette( QColor( "Plum" ) ); canvasPalette.setColor( QPalette::Foreground, QColor( "Indigo" ) ); canvas->setPalette( canvasPalette ); setCanvas( canvas ); setTitle( "DistroWatch Page Hit Ranking, April 2012" ); d_barChartItem = new DistroChartItem(); QVector< double > samples; for ( uint i = 0; i < sizeof( pageHits ) / sizeof( pageHits[ 0 ] ); i++ ) { d_distros += pageHits[ i ].distro; samples += pageHits[ i ].hits; d_barChartItem->addDistro( pageHits[ i ].distro, pageHits[ i ].color ); } d_barChartItem->setSamples( samples ); d_barChartItem->attach( this ); insertLegend( new QwtLegend() ); setOrientation( 0 ); setAutoReplot( false ); }
void SAChartNormalSetWidget::onBorderRadiusChanged(double v) { if(ui->chart) { QWidget* w = ui->chart->canvas(); QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(w); if(canvas) { canvas->setBorderRadius(v); ui->chart->replot(); } } }
TVPlot::TVPlot( QWidget *parent ): QwtPlot( parent ) { setTitle( "Watching TV during a weekend" ); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setPalette( Qt::gray ); canvas->setBorderRadius( 10 ); setCanvas( canvas ); plotLayout()->setAlignCanvasToScales( true ); setAxisTitle( QwtPlot::yLeft, "Number of People" ); setAxisTitle( QwtPlot::xBottom, "Number of Hours" ); QwtLegend *legend = new QwtLegend; legend->setDefaultItemMode( QwtLegendData::Checkable ); insertLegend( legend, QwtPlot::RightLegend ); populate(); connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ), SLOT( showItem( const QVariant &, bool ) ) ); replot(); // creating the legend items QwtPlotItemList items = itemList( QwtPlotItem::Rtti_PlotHistogram ); for ( int i = 0; i < items.size(); i++ ) { if ( i == 0 ) { const QVariant itemInfo = itemToInfo( items[i] ); QwtLegendLabel *legendLabel = qobject_cast<QwtLegendLabel *>( legend->legendWidget( itemInfo ) ); if ( legendLabel ) legendLabel->setChecked( true ); items[i]->setVisible( true ); } else { items[i]->setVisible( false ); } } setAutoReplot( true ); }
FrameNumberVisualizator::FrameNumberVisualizator(int duree,int dataFreq,int min, int max, QWidget *parent): QWidget(parent), duree_de_visualisation(duree), frequency(dataFreq) { QHBoxLayout * mainLayout = new QHBoxLayout; this->setLayout(mainLayout); plot = new QwtPlot(); mainLayout->addWidget(plot,5); //Axis plot->enableAxis(QwtPlot::xBottom,false); plot->setAxisScale( QwtPlot::xBottom, 0.0, duree_de_visualisation ); plot->setAxisScale( QwtPlot::yLeft, 0, 1000 ); // canvas QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setLineWidth( 1 ); canvas->setFrameStyle( QFrame::Box | QFrame::Plain ); canvas->setBorderRadius( 15 ); QPalette canvasPalette( Qt::white ); canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) ); canvas->setPalette( canvasPalette ); plot->setCanvas( canvas ); curve = new QwtPlotCurve("frame"); curve->setRenderHint( QwtPlotItem::RenderAntialiased ); curve->setLegendAttribute( QwtPlotCurve::LegendShowLine, true ); curve->setPen( Qt::red ); curve->attach( plot ); timerReplot = new QTimer; timerReplot->setInterval(50); connect(timerReplot,SIGNAL(timeout()),plot,SLOT(replot())); timerRescale = new QTimer; timerRescale->setInterval(1000); connect(timerRescale,SIGNAL(timeout()),SLOT(rescale())); }
Plot::Plot( QWidget *parent ): QwtPlot( parent ) { QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setBorderRadius( 10 ); setCanvas( canvas ); #if 0 QwtPlotGrid *grid = new QwtPlotGrid(); grid->setPen( Qt::DotLine ); grid->attach( this ); #endif d_spectrogram = new QwtPlotSpectrogram(); d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count d_spectrogram->setColorMap( new ColorMap() ); d_spectrogram->setData( new RasterData() ); 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->setColorBarEnabled( true ); rightAxis->setColorBarWidth( 40 ); rightAxis->setColorMap( zInterval, new ColorMap() ); setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() ); enableAxis( QwtPlot::yRight ); plotLayout()->setAlignCanvasToScales( true ); setAxisScale( QwtPlot::xBottom, 0.0, 3.0 ); setAxisMaxMinor( QwtPlot::xBottom, 0 ); setAxisScale( QwtPlot::yLeft, 0.0, 3.0 ); setAxisMaxMinor( QwtPlot::yLeft, 0 ); QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( canvas ); magnifier->setAxisEnabled( QwtPlot::yRight, false ); QwtPlotPanner *panner = new QwtPlotPanner( canvas ); panner->setAxisEnabled( QwtPlot::yRight, false ); }
Plot::Plot(QWidget *parent): QwtPlot( parent ) { setAutoFillBackground( true ); setPalette( QPalette( QColor( 165, 193, 228 ) ) ); updateGradient(); setTitle( "График аппроксимации" ); insertLegend( new QwtLegend(), QwtPlot::RightLegend ); // axes setAxisTitle( xBottom, "" ); setAxisScale( xBottom, 0.0, 60.0 ); setAxisTitle( yLeft, "Функция принадлежности -->" ); setAxisScale( yLeft, -0.1, 1.1 ); // canvas QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setLineWidth( 1 ); canvas->setFrameStyle( QFrame::Box | QFrame::Plain ); canvas->setBorderRadius( 15 ); QPalette canvasPalette( Qt::white ); canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) ); canvas->setPalette( canvasPalette ); setCanvas( canvas ); // panning with the left mouse button //( void ) new QwtPlotPanner( canvas ); // zoom in/out with the wheel ( void ) new QwtPlotMagnifier( canvas ); zoom = new QwtPlotZoomer(canvas); zoom->setRubberBandPen(QPen(Qt::red)); clear(); // ...a horizontal line at y = 0... <<<<<<< HEAD
Psd::Psd(QWidget *parent) : QWidget(parent), ui(new Ui::Psd) { ui->setupUi(this); ui->plot->setTitle("原信号:cos(2*PI*40*i)+3*cos(2*PI*100*i)+w(n)"); ui->plot->setAutoFillBackground( true ); ui->plot->insertLegend( new QwtLegend(), QwtPlot::RightLegend ); ui->plot->setAutoReplot( false ); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setLineWidth( 1 ); canvas->setFrameStyle( QFrame::Box | QFrame::Plain ); canvas->setBorderRadius( 15 ); QPalette canvasPalette( Qt::white ); canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) ); canvas->setPalette( canvasPalette ); ui->plot->setCanvas( canvas ); ( void ) new QwtPlotPanner( canvas ); ( void ) new QwtPlotMagnifier( canvas ); cSin->setRenderHint( QwtPlotItem::RenderAntialiased ); cSin->setLegendAttribute( QwtPlotCurve::LegendShowLine, false ); cSin->setPen( Qt::red ); cSin->attach( ui->plot ); QwtPlotMarker *mY = new QwtPlotMarker(); mY->setLabelAlignment( Qt::AlignRight | Qt::AlignTop ); mY->setLineStyle( QwtPlotMarker::HLine ); mY->setYValue( 0.0 ); mY->attach( ui->plot ); init(); pf(); populate(); }
CpuPlot::CpuPlot( QWidget *parent ): QwtPlot( parent ), dataCount( 0 ) { setAutoReplot( false ); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setBorderRadius( 10 ); setCanvas( canvas ); plotLayout()->setAlignCanvasToScales( true ); QwtLegend *legend = new QwtLegend; legend->setDefaultItemMode( QwtLegendData::Checkable ); insertLegend( legend, QwtPlot::RightLegend ); setAxisTitle( QwtPlot::xBottom, "System Uptime [h:m:s]" ); setAxisScaleDraw( QwtPlot::xBottom, new TimeScaleDraw( cpuStat.upTime() ) ); setAxisScale( QwtPlot::xBottom, 0, HISTORY ); //setAxisLabelRotation( QwtPlot::xBottom, -50.0 ); setAxisLabelRotation( QwtPlot::xBottom, 0.0 ); setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom ); /* In situations, when there is a label at the most right position of the scale, additional space is needed to display the overlapping part of the label would be taken by reducing the width of scale and canvas. To avoid this "jumping canvas" effect, we add a permanent margin. We don't need to do the same for the left border, because there is enough space for the overlapping label below the left scale. */ QwtScaleWidget *scaleWidget = axisWidget( QwtPlot::xBottom ); const int fmh = QFontMetrics( scaleWidget->font() ).height(); scaleWidget->setMinBorderDist( 0, fmh / 2 ); setAxisTitle( QwtPlot::yLeft, "Cpu Usage [%]" ); setAxisScale( QwtPlot::yLeft, 0, 100 ); //attach方法将元素关联到qwtplot空间上 Background *bg = new Background(); bg->attach( this ); CpuPieMarker *pie = new CpuPieMarker(); pie->attach( this ); CpuCurve *curve; curve = new CpuCurve( "System" ); curve->setColor( Qt::red ); curve->attach( this ); data[System].curve = curve; curve = new CpuCurve( "User" ); curve->setColor( Qt::blue ); curve->setZ( curve->z() - 1 ); curve->attach( this ); data[User].curve = curve; curve = new CpuCurve( "Total" ); curve->setColor( Qt::black ); curve->setZ( curve->z() - 2 ); curve->attach( this ); data[Total].curve = curve; curve = new CpuCurve( "Idle" ); curve->setColor( Qt::darkCyan ); curve->setZ( curve->z() - 3 ); curve->attach( this ); data[Idle].curve = curve; showCurve( data[System].curve, true ); showCurve( data[User].curve, true ); showCurve( data[Total].curve, false ); showCurve( data[Idle].curve, false ); for ( int i = 0; i < HISTORY; i++ ) timeData[HISTORY - 1 - i] = i; ( void )startTimer( 1000 ); // 1 second connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ), SLOT( legendChecked( const QVariant &, bool ) ) ); }
Curve::Curve(int device_port, int ele_max,QColor color, QWidget *parent) : QwtPlot(parent),device_port(device_port),color(color),ele_max(ele_max) { reset(); setObjectName(tr("%1-%2 Real-Eletric").arg(device_port)); setTitle(tr("实时电流")); setAxisTitle(QwtPlot::xBottom,"时间(s)"); setAxisTitle(QwtPlot::yLeft,tr("电流(A)")); setAxisScale(QwtPlot::xBottom,x_min,x_max); setAxisScale(QwtPlot::yLeft,0.0,50.0); QwtPlotCanvas *canvas = new QwtPlotCanvas; canvas->setPalette(QColor("#404040")); canvas->setBorderRadius(10); canvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator); setCanvas(canvas); insertLegend(new QwtLegend(),QwtPlot::RightLegend); QwtPlotZoomer *zoomer = new QwtPlotZoomer(canvas); zoomer->setRubberBandPen(QPen(QColor(Qt::red),1)); zoomer->setTrackerPen(QColor(Qt::red)); zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton,Qt::ControlModifier); zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton); QwtPlotPanner *panner = new QwtPlotPanner(canvas); panner->setMouseButton(Qt::MidButton); panner->setCursor(Qt::OpenHandCursor); panner->setEnabled(true); panner->setAxisEnabled(QwtPlot::yLeft,false); connect(panner,SIGNAL(panned(int,int)),this,SLOT(get_coord(int,int))); new QwtPlotMagnifier(this->canvas()); QwtPlotPicker *m_picker = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::HLineRubberBand , QwtPicker::AlwaysOn, this->canvas() ); m_picker->setTrackerPen(QPen(Qt::red,1)); QFont font; font.setPixelSize(15); m_picker->setTrackerFont(font); d_curve = new QwtPlotCurve(tr("支路%1").arg(device_port)); d_curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,Qt::blue,QPen(Qt::blue),QSize(5,5))); d_curve->setStyle(QwtPlotCurve::Lines); d_curve->setCurveAttribute( QwtPlotCurve::Fitted ); d_curve->setPen(QPen(Qt::magenta)); d_curve->setRenderHint(QwtPlotItem::RenderAntialiased,true); d_curve->attach(this); d_curve_Max = new QwtPlotCurve(tr("最大值")); d_curve_Max->setStyle(QwtPlotCurve::Lines); d_curve_Max->setCurveAttribute(QwtPlotCurve::Fitted); d_curve_Max->setPen(QPen(Qt::red)); d_curve_Max->setRenderHint(QwtPlotItem::RenderAntialiased,true); d_curve_Max->attach(this); }
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(QWidget *parent): QwtPlot( parent ) { setAutoFillBackground( true ); setPalette( QPalette( QColor( 165, 193, 228 ) ) ); updateGradient(); setTitle( "График аппроксимации" ); insertLegend( new QwtLegend(), QwtPlot::RightLegend ); // axes setAxisTitle( xBottom, "" ); setAxisScale( xBottom, 0.0, 10.0 ); setAxisTitle( yLeft, "Функция принадлежности -->" ); setAxisScale( yLeft, 0, 2 ); // canvas QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setLineWidth( 1 ); canvas->setFrameStyle( QFrame::Box | QFrame::Plain ); canvas->setBorderRadius( 15 ); QPalette canvasPalette( Qt::white ); canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) ); canvas->setPalette( canvasPalette ); setCanvas( canvas ); // panning with the left mouse button ( void ) new QwtPlotPanner( canvas ); // zoom in/out with the wheel ( void ) new QwtPlotMagnifier( canvas ); // ...a horizontal line at y = 0... QwtPlotMarker *mY = new QwtPlotMarker(); mY->setLabel( QString::fromLatin1( "y = 0" ) ); mY->setLabelAlignment( Qt::AlignRight | Qt::AlignTop ); mY->setLineStyle( QwtPlotMarker::HLine ); mY->setYValue( 0.0 ); mY->attach( this ); // ...a horizontal line at y = 1... QwtPlotMarker *mY1 = new QwtPlotMarker(); mY1->setLabel( QString::fromLatin1( "y = 1" ) ); mY1->setLabelAlignment( Qt::AlignRight | Qt::AlignTop ); mY1->setLineStyle( QwtPlotMarker::HLine ); mY1->setYValue( 1.0 ); mY1->setLinePen(Qt::black, 1, Qt::DashLine); mY1->attach( this ); // ...a vertical line at x = 0 QwtPlotMarker *mX = new QwtPlotMarker(); mX->setLabel( QString::fromLatin1( "x = 0" ) ); mX->setLabelAlignment( Qt::AlignLeft | Qt::AlignBottom ); mX->setLabelOrientation( Qt::Vertical ); mX->setLineStyle( QwtPlotMarker::VLine ); mX->setLinePen( Qt::black, 0, Qt::DashDotLine ); mX->setXValue( 0 ); mX->attach( this ); // curvePoints = new QwtPlotCurve(); // curvePoints->setStyle( QwtPlotCurve::Dots ); // curvePoints->attach( this ); }
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 ); }
ThreeAxisDataVisualizator::ThreeAxisDataVisualizator(int duree,int dataFreq,int min, int max, int _type, QWidget *parent): QWidget(parent), duree_de_visualisation(duree), frequency(dataFreq), type(_type), min(0), max(0) { curves = QList<QString>(); QString typeStr; if(type==DataType::acc){ typeStr = "accelerometre"; }else if(type==DataType::gyro){ typeStr = "gyroscope"; }else if(type==DataType::euler){ typeStr = "euler"; }else if(type==DataType::qua){ typeStr = "quaternion"; } curves.append(typeStr+" x"); curves.append(typeStr+" y"); curves.append(typeStr+" z"); QHBoxLayout * mainLayout = new QHBoxLayout; this->setLayout(mainLayout); plot = new QwtPlot(); mainLayout->addWidget(plot,5); QWidget * checkBoxGroup = new QWidget(this); mainLayout->addWidget(checkBoxGroup,1); QVBoxLayout * checkBoxGroupLayout = new QVBoxLayout; checkBoxGroup->setLayout(checkBoxGroupLayout); QPushButton * resetScaleButton = new QPushButton; resetScaleButton->setText("reset y scale"); setStyleSheet("QPushButton{" "font-family: Futura;" "color:#4C6BCF;" "font-size: 14px;" "border:2px solid ;" "border-color: #4C6BCF;" "border-radius:5px;" "min-height:60;}"); checkBoxGroupLayout->addWidget(resetScaleButton); checkBoxX = new QCheckBox(curves.at(0),checkBoxGroup); checkBoxGroupLayout->addWidget(checkBoxX); checkBoxY = new QCheckBox(curves.at(1),checkBoxGroup); checkBoxGroupLayout->addWidget(checkBoxY); checkBoxZ = new QCheckBox(curves.at(2),checkBoxGroup); checkBoxGroupLayout->addWidget(checkBoxZ); timeSlider = new QSlider(Qt::Horizontal,checkBoxGroup); checkBoxGroupLayout->addWidget(timeSlider); checkBoxX->setChecked(true); checkBoxY->setChecked(true); checkBoxZ->setChecked(true); QSignalMapper * mapper = new QSignalMapper; mapper->setMapping(checkBoxX,0); mapper->setMapping(checkBoxY,1); mapper->setMapping(checkBoxZ,2); connect(checkBoxX,SIGNAL(stateChanged(int)),mapper,SLOT(map())); connect(checkBoxY,SIGNAL(stateChanged(int)),mapper,SLOT(map())); connect(checkBoxZ,SIGNAL(stateChanged(int)),mapper,SLOT(map())); connect(mapper,SIGNAL(mapped(int)),SLOT(handleCheckBox(int))); // canvas QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setLineWidth( 1 ); canvas->setFrameStyle( QFrame::Box | QFrame::Plain ); canvas->setBorderRadius( 15 ); QPalette canvasPalette( Qt::white ); canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) ); canvas->setPalette( canvasPalette ); plot->setCanvas( canvas ); QwtPlotScaleItem *it1 = new QwtPlotScaleItem(QwtScaleDraw::BottomScale ,0.0); it1->attach(plot); plot->enableAxis(QwtPlot::xBottom,false); plot->setAxisScale( QwtPlot::xBottom, 0.0, duree_de_visualisation ); plot->setAxisScale( QwtPlot::yLeft, min, max ); xCurve = new QwtPlotCurve( curves.at(0)); xCurve->setRenderHint( QwtPlotItem::RenderAntialiased ); xCurve->setLegendAttribute( QwtPlotCurve::LegendShowLine, true ); xCurve->setPen( Qt::red ); xCurve->attach( plot ); yCurve = new QwtPlotCurve(curves.at(1)); yCurve->setRenderHint( QwtPlotItem::RenderAntialiased ); yCurve->setLegendAttribute( QwtPlotCurve::LegendShowLine, true ); yCurve->setPen( Qt::blue ); yCurve->attach( plot ); zCurve = new QwtPlotCurve( curves.at(2)); zCurve->setRenderHint( QwtPlotItem::RenderAntialiased ); zCurve->setLegendAttribute( QwtPlotCurve::LegendShowLine, true ); zCurve->setPen( Qt::green ); zCurve->attach( plot ); timerReplot = new QTimer; timerReplot->setInterval(50); connect(timerReplot,SIGNAL(timeout()),plot,SLOT(replot())); connect(timeSlider,SIGNAL(sliderMoved(int)),SLOT(updateVizualizatorTimeWindow(int))); timerRescale = new QTimer; timerRescale->setInterval(1000); connect(timerRescale,SIGNAL(timeout()),SLOT(rescale())); connect(resetScaleButton,SIGNAL(clicked(bool)),SLOT(resetScale())); setEnabled(false); }
int main(int argc, char *argv[]) { // QGuiApplication a(argc, argv); QApplication a(argc, argv); QwtPlot *plot = new QwtPlot(); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setBorderRadius(10); plot->setCanvas(canvas); plot->setCanvasBackground(QColor("LIGHTGRAY")); plot->enableAxis(QwtPlot::yRight); plot->enableAxis(QwtPlot::xTop); plot->setAxisTitle(QwtPlot::xBottom, "Xline"); plot->setAxisTitle(QwtPlot::xTop, "Xline"); plot->setAxisTitle(QwtPlot::yLeft, "Inline"); plot->setAxisTitle(QwtPlot::yRight, "Inline"); // float minx = srv->getStations().first().x(); // float maxx = srv->getStations().last().x(); plot->setAxisScale( QwtPlot::xBottom,3500,300); // plot->setAxisScale( QwtPlot::xTop,minx,maxx ); // QwtScaleDraw *sd = axisScaleDraw( QwtPlot::yLeft ); // sd->setMinimumExtent( sd->extent( axisWidget( QwtPlot::yLeft )->font() ) ); plot->plotLayout()->setAlignCanvasToScales( true ); QFileDialog custDialog; QStringList names = custDialog.getOpenFileNames(NULL, ("Open Files..."),QString(), ("UKOOA Files (*.p190 *.p90);;All Files (*)")); // handle if the dialog was "Cancelled" if(names.isEmpty()) { return 0; } qSort(names.begin(), names.end()); QVector <QwtPlotCurve *> curves; foreach (QString name, names) { QwtPlotCurve *vCurve = new QwtPlotCurve; if(name.contains(QString( "NS1763")) || name.contains(QString("NS2029"))) { QColor c = Qt::red; vCurve->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, Qt::red,c , QSize( 2, 2 ) ) ); } else { QColor c = Qt::green; vCurve->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, Qt::green,c , QSize( 2, 2 ) ) ); } vCurve->setStyle( QwtPlotCurve::NoCurve ); vCurve->setPen( Qt::gray ); cout << name.toStdString() << endl; QVector<QPointF> curveData; // m_nameLineLable->setText(m_names.at(0)); QFile *ukFile = new QFile(QString(name)); bool rt = ukFile->open(QIODevice::ReadOnly); cout << "return " << rt << endl; qint64 icount = 0; qint64 fileSize = ukFile->size(); char *data = new char[fileSize]; ukFile->read(data,fileSize); QString sData = data; QString shot = "SNS"; while (true) { ukFile->seek(icount); ukFile->read(data,fileSize); sData = data;; if(icount>=fileSize) { break; } auto sPos = sData.indexOf(shot,0,Qt::CaseInsensitive); QString cr = sData.mid(sPos,19); if(cr.contains("\n")) { sPos +=2; } // auto shotNo = sData.mid(sPos+20,sPos+5); QString shotNo = sData.mid(sPos+19,6); int shotNos; if(shotNo.contains("\n") || shotNo.contains("\r")) { shotNo = sData.mid(sPos+19,8); int shift1 = shotNo.indexOf("\r"); int shift = shotNo.indexOf("\n"); // cout << shift1 << " " << shift << endl; QString tmp = shotNo.mid(0,shift1); tmp.append(shotNo.mid(shift+1,3)); shotNos = tmp.toInt(); } else { shotNos = sData.mid(sPos+19,6).toInt(); } float shotYs; sPos = sData.indexOf(shot,0,Qt::CaseInsensitive); cr = sData.mid(sPos,55); if(cr.contains("\n")) { // cout << " cr " << sPos << endl; sPos +=2; } QString shotY = sData.mid(sPos+55,10); // cout << "shotx " << shotX.toStdString() << endl; if(shotY.contains("\n") || shotY.contains("\r")) { shotY = sData.mid(sPos+55,12); int shift1 = shotY.indexOf("\r"); int shift = shotY.indexOf("\n"); // cout << shift1 << " " << shift << endl; QString tmp = shotY.mid(0,shift1); tmp.append(shotY.mid(shift+1,12)); shotYs = tmp.toFloat(); } else { shotYs = shotY.toFloat(); } float shotXs; sPos = sData.indexOf(shot,0,Qt::CaseInsensitive); cr = sData.mid(sPos,46); if(cr.contains("\n")) { // cout << " cr " << sPos << endl; sPos +=2; } QString shotX = sData.mid(sPos+46,10); // cout << "shotx " << shotX.toStdString() << endl; if(shotX.contains("\n") || shotX.contains("\r")) { shotX = sData.mid(sPos+46,12); int shift1 = shotX.indexOf("\r"); int shift = shotX.indexOf("\n"); // cout << shift1 << " " << shift << endl; QString tmp = shotX.mid(0,shift1); tmp.append(shotX.mid(shift+1,12)); shotXs = tmp.toFloat(); } else { shotXs = shotX.toFloat(); } icount +=sPos+1; // cout << shotNos << endl; float shotXt = shotXs - 757551.46; float shotYt = shotYs - 978769.0; float shotYr = shotYt * cosf(13.661f * M_PI/180.0f) + shotXt * sinf(13.661f * M_PI/180.0f); int shotYy = 981 + shotYr/25.0; float shotXr = shotXt * cosf(13.661f * M_PI/180.0f) - shotYt * sinf(13.661f * M_PI/180.0f); int shotXx = 2570 - shotXr/25.0; // if(shotXx>0 && shotYy>0) // { QPointF shotPoint(shotXx,shotYy); curveData.append(shotPoint); // cout << " shot " << shotNos << " " << shotXs << " " << shotYs << " " << shotXx << " " << shotYy << endl; // } } vCurve->setSamples(curveData); curves.append(vCurve); ukFile->close(); }