void ScrollZoomer::rescale() { QwtScaleWidget *xScale = plot()->axisWidget( xAxis() ); QwtScaleWidget *yScale = plot()->axisWidget( yAxis() ); if ( zoomRectIndex() <= 0 ) { if ( d_inZoom ) { xScale->setMinBorderDist( 0, 0 ); yScale->setMinBorderDist( 0, 0 ); QwtPlotLayout *layout = plot()->plotLayout(); for ( int axis = 0; axis < QwtAxis::PosCount; axis++ ) layout->setAlignCanvasToScale( axis, d_alignCanvasToScales ); d_inZoom = false; } } else { if ( !d_inZoom ) { /* We set a minimum border distance. Otherwise the canvas size changes when scrolling, between situations where the major ticks are at the canvas borders (requiring extra space for the label) and situations where all labels can be painted below/top or left/right of the canvas. */ int start, end; xScale->getBorderDistHint( start, end ); xScale->setMinBorderDist( start, end ); yScale->getBorderDistHint( start, end ); yScale->setMinBorderDist( start, end ); QwtPlotLayout *layout = plot()->plotLayout(); for ( int axis = 0; axis < QwtAxis::PosCount; axis++ ) { d_alignCanvasToScales[axis] = layout->alignCanvasToScale( axis ); } layout->setAlignCanvasToScales( false ); d_inZoom = true; } } QwtPlotZoomer::rescale(); updateScrollBars(); }
void ScrollZoomer::rescale() { QwtScaleWidget *xScale = plot()->axisWidget(xAxis()); QwtScaleWidget *yScale = plot()->axisWidget(yAxis()); if ( zoomRectIndex() <= 0 ) { if ( d_inZoom ) { xScale->setMinBorderDist(0, 0); yScale->setMinBorderDist(0, 0); d_inZoom = false; } } else { if ( !d_inZoom ) { /* We set a minimum border distance. Otherwise the canvas size changes when scrolling, between situations where the major ticks are at the canvas borders (requiring extra space for the label) and situations where all labels can be painted below/top or left/right of the canvas. */ int start, end; xScale->getBorderDistHint(start, end); xScale->setMinBorderDist(start, end); yScale->getBorderDistHint(start, end); yScale->setMinBorderDist(start, end); d_inZoom = false; } } QwtPlotZoomer::rescale(); updateScrollBars(); }
// Init X axis. void DataPlot::initAxisX() { //QwtText xTitle("System Uptime [h:m:s]"); //xTitle.setFont(QFont("Ubuntu", 10)); //setAxisTitle(QwtPlot::xBottom, xTitle); setAxisScaleDraw(QwtPlot::xBottom,new TimeScaleDraw(upTime())); setAxisScale(QwtPlot::xBottom, 0, PLOT_SIZE ); setAxisLabelRotation(QwtPlot::xBottom, -50.0); setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom); QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom); const int fmh = QFontMetrics(scaleWidget->font()).height(); scaleWidget->setMinBorderDist(0, fmh / 2); }
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 ) ) ); }
//--------------------------------------------------------------------------- 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(); }
AmpPlot::AmpPlot(QwtPlot *plot) { //TODO // _picker = new QwtPicker(canvas()); // _picker->setStateMachine(new QwtPickerDragRectMachine()); // _picker->setTrackerMode(QwtPicker::ActiveOnly); // _picker->setRubberBand(QwtPicker::RectRubberBand); _plot = plot; _panner = new QwtPlotPanner(_plot->canvas()); //Panning with the mouse _panner->setOrientations(Qt::Horizontal); //connect(_panner, SIGNAL(moved(int,int)), this, SLOT(pannerMoved(int,int))); _magnifier = new QwtPlotMagnifier(_plot->canvas()); //Zooming with the wheel _plot->canvas()->setBorderRadius(5); _plot->setCanvasBackground(Qt::white); _plot->plotLayout()->setAlignCanvasToScales(true); QwtLegend *legend = new QwtLegend; _plot->insertLegend(legend,QwtPlot::RightLegend); legend->setItemMode(QwtLegend::CheckableItem); connect(_plot,SIGNAL(legendChecked(QwtPlotItem*,bool)),SLOT(showCurve(QwtPlotItem*,bool))); _xMax = DEFAULT_X_MAX; _yMax = DEFAULT_Y_MAX; _plot->setAxisTitle(QwtPlot::xBottom, "ms"); _plot->setAxisScale(QwtPlot::xBottom,0,_xMax); QwtScaleWidget *scaleWidget = _plot->axisWidget(QwtPlot::xBottom); const int fmh = QFontMetrics(scaleWidget->font()).height(); scaleWidget->setMinBorderDist(0, fmh*2); _plot->setAxisTitle(QwtPlot::yLeft,"mA"); _plot->setAxisAutoScale(QwtPlot::yLeft, true); _dataCurve = new QwtPlotCurve("mA"); _dataCurve->attach(_plot); _dataCurve->setRenderHint(QwtPlotItem::RenderAntialiased); _dataCurve->setVisible(_plot); _meanCurve = new QwtPlotCurve("avg mean"); _meanCurve->attach(_plot); _meanCurve->setRenderHint(QwtPlotItem::RenderAntialiased); _meanCurve->setPen(QPen(Qt::red)); _maxCurve = new QwtPlotCurve("max"); _maxCurve->attach(_plot); _maxCurve->setRenderHint(QwtPlotItem::RenderAntialiased); _maxCurve->setPen(QPen(Qt::darkMagenta)); _currentMeanCurve = new QwtPlotCurve("mean"); _currentMeanCurve->attach(_plot); _currentMeanCurve->setRenderHint(QwtPlotItem::RenderAntialiased); _currentMeanCurve->setPen(QPen(Qt::blue)); showCurve(_dataCurve, true); showCurve(_meanCurve, false); showCurve(_maxCurve, false); showCurve(_currentMeanCurve, true); _time = new QTime(); _time->start(); _meanData.append(0.0); _meanTime.append(0.0); _meanData.append(0.0); _meanTime.append(0.0); _maxData.append(0.0); _maxTime.append(0.0); _maxData.append(0.0); _maxTime.append(0.0); _pauseTime = 0; _dataSource = NULL; _loadedCurve = NULL; }
QwtGrapher::QwtGrapher(QWidget* parent): QwtPlot(parent) { m_values = new TwoDArray<double>(3,100); plotLayout()->setAlignCanvasToScales(true); QwtLegend *legend = new QwtLegend; legend->setItemMode(QwtLegend::CheckableItem); insertLegend(legend, QwtPlot::RightLegend); setAxisTitle(QwtPlot::xBottom, " FitnessCases"); /*setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(cpuStat.upTime())); setAxisScale(QwtPlot::xBottom, 0, HISTORY); setAxisLabelRotation(QwtPlot::xBottom, -50.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, "Ouput") ; //setAxisScale(QwtPlot::yLeft, 0, 100); // Background *bg = new Background(); //bg->attach(this); /*CpuPieMarker *pie = new CpuPieMarker(); pie->attach(this); */ QwtPlotCurve *curve; curve = new QwtPlotCurve("Best"); curve->setPen(QColor(Qt::green)); curve->attach(this); m_curves[0] = curve; curve = new QwtPlotCurve("Average"); curve->setPen(QColor(Qt::blue)); curve->setZ(curve->z() - 1); curve->attach(this); m_curves[1] = curve; curve = new QwtPlotCurve("Worst"); curve->setPen(QColor(Qt::black)); curve->setZ(curve->z() - 2); curve->attach(this); m_curves[2] = curve; showCurve(m_curves[0], true); showCurve(m_curves[1], true); showCurve(m_curves[2], true); connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), SLOT(showCurve(QwtPlotItem *, bool))); }