PlotZoz::PlotZoz(QWidget *) { // Прозрачность полотна QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setFrameStyle(QFrame::NoFrame); canvas->setPaintAttribute(QwtPlotCanvas::BackingStore, false); canvas->setPaintAttribute(QwtPlotCanvas::Opaque, false); canvas->setAttribute(Qt::WA_OpaquePaintEvent, false); canvas->setAutoFillBackground( false ); setCanvas(canvas); plotLayout()->setAlignCanvasToScales(true); // Отключаем щкалы деления for (int i=0; i<QwtPlot::axisCnt; i++) { axisScaleDraw(i)->enableComponent(QwtScaleDraw::Ticks, false); axisScaleDraw(i)->enableComponent(QwtScaleDraw::Backbone, false); } pltSpectrogram = new PlotSpectr(); pltRasterData = new PlotRasterData(); pltGrid = new QwtPlotGrid; pltGrid->enableXMin(true); // разрешаем отображение линий сетки, соответствующих вспомогательным делениям нижней шкалы pltGrid->enableYMin(true); // разрешаем отображение линий сетки, соответствующих вспомогательным делениям нижней шкалы pltGrid->setMajorPen(QPen(Qt::gray,0,Qt::DotLine)); // черный для основных делений pltGrid->setMinorPen(QPen(Qt::gray,0,Qt::DotLine)); // серый для вспомогательных pltGrid->attach(this); setAxisMaxMajor(0,20); setAxisMaxMinor(0,0); setAxisMaxMajor(1,20); setAxisMaxMinor(1,0); setAxisMaxMajor(2,20); setAxisMaxMinor(2,0); setAxisMaxMajor(3,20); setAxisMaxMinor(3,0); canvas->setCursor(Qt::ArrowCursor); setMouseTracking(true); for (int i=0; i<QwtPlot::axisCnt; i++) axisWidget(i)->setMouseTracking(true); }
void Plot::applyAxisSettings( int axis, const Settings &settings ) { QwtDateScaleEngine *scaleEngine = static_cast<QwtDateScaleEngine *>( axisScaleEngine( axis ) ); scaleEngine->setMaxWeeks( settings.maxWeeks ); setAxisMaxMinor( axis, settings.maxMinorSteps ); setAxisMaxMajor( axis, settings.maxMajorSteps ); setAxisScale( axis, QwtDate::toDouble( settings.startDateTime ), QwtDate::toDouble( settings.endDateTime ) ); }
void Plot::initCanvas() { setGeometry(100,100,800,600); setTitle(tr("Title")); setCanvasBackground(QBrush(QColor("white"))); setCanvasLineWidth(1); // 画布边缘宽度 // enableAxis(0,false); /* * axisId: * y_leff: 0 * y_right: 1 * x_buttom: 2 * x_top: 4 */ setAxisTitle(2, tr("wave number")); setAxisTitle(0, tr("DOP")); setAxisMaxMajor(0, 10); // 主刻度的个数 setAxisMaxMinor(0, 10); // 辅助刻度的分裂数目 insertLegend(new QwtLegend(),QwtPlot::RightLegend); }
//--------------------------------------------------------------------------- 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 ) { 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 ) { 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 ); }
int QwtPlotWidget::interpret(const char *command, double *x, double *y) { if(command == NULL) return -1; line = command; if (isCommand("setCurveData(")) { if(x == NULL) return -1; if(y == NULL) return -1; int c,count; sscanf(command,"setCurveData(%d,%d",&c,&count); if(c<0 || c>=nCurves) return -1; if(curves[c] != NULL) curves[c]->setData(x,y,count); } else if(isCommand("replot(")) { replot(); } else if(isCommand("setTitle(")) { QString text; if(getText(command,text) != 0) return -1; setTitle(text); } else if(isCommand("setCanvasBackground(")) { int r,g,b; sscanf(command,"setCanvasBackground(%d,%d,%d",&r,&g,&b); setCanvasBackground(QColor(r,g,b)); } else if(isCommand("enableOutline(")) { int val; sscanf(command,"enableOutline(%d",&val); if( val == 0 || val == 1 ) { //xx enableOutline(val); //xx setOutlineStyle(Qwt::Rect ); } else { //xx enableOutline( 1 ); //xx setOutlineStyle(Qwt::Cross ); } } else if(isCommand("setOutlinePen(")) { int r,g,b; sscanf(command,"setOutlinePen(%d,%d,%d",&r,&g,&b); //xx setOutlinePen(QColor(r,g,b)); } else if(isCommand("setAutoLegend(")) { int val; sscanf(command,"setAutoLegend(%d",&val); //xx setAutoLegend(val); autolegend = val; } else if(isCommand("enableLegend(")) { int val; sscanf(command,"enableLegend(%d",&val); enablelegend = val; } else if(isCommand("setLegendPos(")) { int val; sscanf(command,"setLegendPos(%d",&val); if(opt.arg_debug) printf("SetLegendPos begin\n");; if(legend == NULL) legend = new QwtLegend(); if(opt.arg_debug) printf("SetLegendPos 1\n");; legend->setItemMode(QwtLegend::ClickableItem); if(opt.arg_debug) printf("SetLegendPos 2\n");; switch(val) { case PV::LeftLegend: insertLegend(legend, QwtPlot::LeftLegend); break; case PV::RightLegend: insertLegend(legend, QwtPlot::RightLegend); break; case PV::TopLegend: insertLegend(legend, QwtPlot::TopLegend); break; default: insertLegend(legend, QwtPlot::BottomLegend); break; } if(opt.arg_debug) printf("SetLegendPos end\n");; } else if(isCommand("setLegendFrameStyle(")) { int val; sscanf(command,"setLegendFrameStyle(%d",&val); legendframestyle = val; if(legend != NULL) legend->setFrameStyle(legendframestyle); } else if(isCommand("enableGridXMin(")) { grid.enableXMin(true); } else if(isCommand("setGridMajPen(")) { int r,g,b,style; sscanf(command,"setGridMajPen(%d,%d,%d,%d",&r,&g,&b,&style); grid.setMajPen(QPen(QColor(r,g,b),0,(Qt::PenStyle) style)); } else if(isCommand("setGridMinPen(")) { int r,g,b,style; sscanf(command,"setGridMinPen(%d,%d,%d,%d",&r,&g,&b,&style); grid.setMinPen(QPen(QColor(r,g,b),0,(Qt::PenStyle) style)); } else if(isCommand("enableAxis(")) { int pos; sscanf(command,"enableAxis(%d",&pos); enableAxis(pos); } else if(isCommand("setAxisTitle(")) { int pos; QString text; sscanf(command,"setAxisTitle(%d",&pos); if(getText(command,text) != 0) return -1; setAxisTitle(pos,text); } else if(isCommand("setAxisOptions(")) { int pos,val; sscanf(command,"setAxisOptions(%d,%d",&pos,&val); //xx setAxisOptions(pos,val); } else if(isCommand("setAxisMaxMajor(")) { int pos,val; sscanf(command,"setAxisMaxMajor(%d,%d",&pos,&val); setAxisMaxMajor(pos,val); } else if(isCommand("setAxisMaxMinor(")) { int pos,val; sscanf(command,"setAxisMaxMinor(%d,%d",&pos,&val); setAxisMaxMinor(pos,val); } else if(isCommand("insertCurve(")) { int pos; QString text; sscanf(command,"insertCurve(%d",&pos); if(getText(command,text) != 0) return -1; if(pos<0 || pos>=nCurves) return -1; //xx removeCurve( curves[pos] ); //xx curves[pos] = insertCurve(text); if(curves[pos] != NULL) delete curves[pos]; if(opt.arg_debug) printf("new QwtPlotCurve(%s)\n",(const char *) text.toUtf8()); curves[pos] = new QwtPlotCurve(text); curves[pos]->attach(this); if(legend != NULL) { QWidget *w = legend->find(curves[pos]); if(w != NULL) { if(opt.arg_debug) printf("setChecked(%d)\n",autolegend); ((QwtLegendItem *)w)->setChecked(autolegend); } } replot(); //if(autolegend && legend != NULL) curves[pos]->updateLegend(legend); } else if(isCommand("removeCurve(")) { int pos; sscanf(command,"removeCurve(%d",&pos); if(pos<0 || pos>=nCurves) return -1; //xx removeCurve( curves[pos] ); if(curves[pos] != NULL) curves[pos]->detach(); if(curves[pos] != NULL) delete curves[pos]; curves[pos] = NULL; } else if(isCommand("setCurvePen(")) { int pos,r,g,b,width,style; sscanf(command,"setCurvePen(%d,%d,%d,%d,%d,%d",&pos,&r,&g,&b,&width,&style); if(pos<0 || pos>=nCurves) return -1; //xx setCurvePen(curves[pos],QPen(QColor(r,g,b),width,(Qt::PenStyle) style)); QPen pen(QColor(r,g,b)); pen.setWidth(width); pen.setStyle((Qt::PenStyle) style); if(curves[pos] != NULL) curves[pos]->setPen(pen); } else if(isCommand("setCurveSymbol(")) { int pos,symbol,r1,g1,b1,r2,g2,b2,w,h; sscanf(command,"setCurveSymbol(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&pos,&symbol, &r1,&g1,&b1,&r2,&g2,&b2,&w,&h); if(pos<0 || pos>=nCurves) return -1; //xx setCurveSymbol(curves[pos], QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h))); if(curves[pos] != NULL) curves[pos]->setSymbol(QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h))); } else if(isCommand("setCurveYAxis(")) { int pos,pos2; sscanf(command,"setCurveYAxis(%d,%d",&pos,&pos2); if(pos<0 || pos>=nCurves) return -1; //xx setCurveYAxis(curves[pos],pos2); rl2013 if(curves[pos] != NULL) curves[pos]->setYAxis(pos2); } else if(isCommand("insertMarker(")) { int pos; sscanf(command,"insertMarker(%d",&pos); if(pos<0 || pos>=nMarker) return -1; //xx marker[pos] = insertMarker(); if(marker[pos] != NULL) delete marker[pos]; marker[pos] = new QwtPlotMarker(); marker[pos]->attach(this); } else if(isCommand("setMarkerLineStyle(")) { int pos,style; sscanf(command,"setMarkerLineStyle(%d,%d",&pos,&style); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerLineStyle(marker[pos],(QwtMarker::LineStyle) style); if(marker[pos] != NULL) marker[pos]->setLineStyle((QwtPlotMarker::LineStyle) style); } else if(isCommand("setMarkerPos(")) { int pos; float x,y; sscanf(command,"setMarkerPos(%d,%f,%f",&pos,&x,&y); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerPos(marker[pos],x,y); if(marker[pos] != NULL) marker[pos]->setValue(x,y); } else if(isCommand("setMarkerLabelAlign(")) { int pos,align; sscanf(command,"setMarkerLabelAlign(%d,%d",&pos,&align); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerLabelAlign(marker[pos],align); if(marker[pos] != NULL) marker[pos]->setLabelAlignment((Qt::Alignment) align); } else if(isCommand("setMarkerLabel(")) { int pos; QString text; sscanf( command, "setMarkerLabel(%d",&pos ); if(getText(command, text) != 0 ) return -1; //xx setMarkerLabel(marker[pos], text ); if(marker[pos] != NULL) marker[pos]->setLabel(text); } else if(isCommand("setMarkerPen(")) { int pos,r,g,b,style; sscanf(command,"setMarkerPen(%d,%d,%d,%d,%d",&pos,&r,&g,&b,&style); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerPen(marker[pos],QPen(QColor(r,g,b),0,(Qt::PenStyle) style)); if(marker[pos] != NULL) marker[pos]->setLinePen(QPen(QColor(r,g,b))); } else if(isCommand("setMarkerFont(")) { int pos,size,style; QString family; sscanf(command,"setMarkerFont(%d,%d,%d",&pos,&size,&style); if(pos<0 || pos>=nMarker) return -1; if(getText(command,family) != 0) return -1; //xx setMarkerFont(marker[pos],QFont(family,size,style)); } else if(isCommand("setMarkerSymbol(")) { int pos,symbol,r1,g1,b1,r2,g2,b2,w,h; sscanf(command,"setMarkerSymbol(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &pos,&symbol,&r1,&g1,&b1,&r2,&g2,&b2,&w,&h); if(pos<0 || pos>=nMarker) return -1; //xx setMarkerSymbol(marker[pos], QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h))); if(marker[pos] != NULL) marker[pos]->setSymbol(QwtSymbol((QwtSymbol::Style) symbol, QColor(r1,g1,b1), QColor(r2,g2,b2), QSize(w,h))); } else if(isCommand("insertLineMarker(")) { int pos,pos2; QString text; sscanf(command,"insertLineMarker(%d,%d",&pos,&pos2); if(getText(command,text) != 0) return -1; if(pos<0 || pos>=nMarker) return -1; //xx marker[pos] = insertLineMarker(text, pos2); if(marker[pos] != NULL) delete marker[pos]; marker[pos] = new QwtPlotMarker(); marker[pos]->attach(this); if(marker[pos] != NULL) marker[pos]->setLabel(text); } else if( isCommand("setAxisScaleDraw(")) { int pos; QString qtext; char text[1024]; sscanf( command, "setAxisScaleDraw(%d",&pos ); if( getText(command, qtext) != 0 ) return -1; if(qtext.length() < ((int) sizeof(text) -1)) { strcpy(text,qtext.toUtf8()); } else { strcpy(text,"text too long"); } if(opt.arg_debug) printf("setAxisScaleDraw(%s)\n",text); setAxisScaleDraw( pos, new UserScaleDraw( text )); } else if( isCommand("setAxisScale(")) { int pos; float min,max,step; sscanf( command, "setAxisScale(%d,%f,%f,%f",&pos ,&min, &max, &step); if(opt.arg_debug) printf("setAxisScale(%d,%f,%f,%f)\n",pos,min,max,step); setAxisScale(pos,min,max,step); } else { return -1; } return 0; }