/** * Tworzy wykres spektrogramu. * * Przygotowuje mapowanie kolorów, skale osi we właściwych jednostkach itp. * * @param parent obiekt rodzica */ SpectrogramPlot::SpectrogramPlot(QWidget* parent): QwtPlot(tr("Wave file not loaded"), parent) { spectrogram = new QwtPlotSpectrogram(); QwtLinearColorMap colorMap(Qt::black, Qt::red); colorMap.addColorStop(0.3, Qt::darkBlue); colorMap.addColorStop(0.4, Qt::blue); colorMap.addColorStop(0.65, Qt::green); colorMap.addColorStop(0.85, Qt::yellow); spectrogram->setColorMap(colorMap); // kolorowa prawa oś QwtScaleWidget *rightAxis = axisWidget(yRight); rightAxis->setTitle(tr("Intensity [dB]")); rightAxis->setColorBarEnabled(true); enableAxis(yRight); spectrogram->attach(this); const QFontMetrics fmRight(rightAxis->font()); int intensityWidth = rightAxis->colorBarWidth() + fmRight.width("888 888"); axisScaleDraw(yRight)->setMinimumExtent(intensityWidth); QwtPlotPanner *panner = new QwtPlotPanner(canvas()); panner->setAxisEnabled(QwtPlot::yRight, false); panner->setMouseButton(Qt::MidButton); // dolna oś setAxisScaleDraw(xBottom, new DurationScaleDraw()); }
void PlotMatrix::alignVAxes( int col, int axis ) { if ( axis != QwtPlot::yLeft && axis != QwtPlot::yRight ) return; double maxExtent = 0; for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plot( row, col ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); QwtScaleDraw *sd = scaleWidget->scaleDraw(); sd->setMinimumExtent( 0.0 ); const double extent = sd->extent( scaleWidget->font() ); if ( extent > maxExtent ) maxExtent = extent; } } for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plot( row, col ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); scaleWidget->scaleDraw()->setMinimumExtent( maxExtent ); } } }
// 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); }
virtual void rescale() { QwtScaleWidget *scaleWidget = plot()->axisWidget(yAxis()); QwtScaleDraw *sd = scaleWidget->scaleDraw(); int minExtent = 0; if ( zoomRectIndex() > 0 ) { // When scrolling in vertical direction // the plot is jumping in horizontal direction // because of the different widths of the labels // So we better use a fixed extent. minExtent = sd->spacing() + sd->maxTickLength() + 1; minExtent += sd->labelSize( scaleWidget->font(), c_rangeMax).width(); } sd->setMinimumExtent(minExtent); ScrollZoomer::rescale(); }
//--------------------------------------------------------------------------- void Plots::alignYAxes() { double maxExtent = 0; for ( size_t streamPos = 0; streamPos < m_fileInfoData->Stats.size(); streamPos++ ) if ( m_fileInfoData->Stats[streamPos] && m_plots[streamPos] ) { size_t type = m_fileInfoData->Stats[streamPos]->Type_Get(); for ( int group = 0; group < PerStreamType[type].CountOfGroups; group++ ) if (m_plots[streamPos][group] && m_plots[streamPos] ) { QwtScaleWidget *scaleWidget = m_plots[streamPos][group]->axisWidget( QwtPlot::yLeft ); QwtScaleDraw* scaleDraw = scaleWidget->scaleDraw(); scaleDraw->setMinimumExtent( 0.0 ); if ( m_plots[streamPos][group] && m_plots[streamPos][group]->isVisibleTo( this ) ) { const double extent = scaleDraw->extent( scaleWidget->font() ); maxExtent = qMax( extent, maxExtent ); } } maxExtent += 3; // margin } for ( size_t streamPos = 0; streamPos < m_fileInfoData->Stats.size(); streamPos++ ) if ( m_fileInfoData->Stats[streamPos] && m_plots[streamPos] ) { size_t type = m_fileInfoData->Stats[streamPos]->Type_Get(); for ( int group = 0; group < PerStreamType[type].CountOfGroups; group++ ) if (m_plots[streamPos][group]) { QwtScaleWidget *scaleWidget = m_plots[streamPos][group]->axisWidget( QwtPlot::yLeft ); scaleWidget->scaleDraw()->setMinimumExtent( maxExtent ); } } }
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(); }
/*! Change color and fonts of a plot \sa apply() */ void QwtPlotPrintFilter::apply(QwtPlot *plot) const { const bool doAutoReplot = plot->autoReplot(); plot->setAutoReplot(false); delete d_data->cache; d_data->cache = new PrivateData::Cache; PrivateData::Cache &cache = *d_data->cache; if ( plot->titleLabel() ) { QPalette palette = plot->titleLabel()->palette(); cache.titleColor = palette.color( QPalette::Active, Palette::Text); palette.setColor(QPalette::Active, Palette::Text, color(cache.titleColor, Title)); plot->titleLabel()->setPalette(palette); cache.titleFont = plot->titleLabel()->font(); plot->titleLabel()->setFont(font(cache.titleFont, Title)); } if ( plot->legend() ) { #if QT_VERSION < 0x040000 QValueList<QWidget *> list = plot->legend()->legendItems(); for ( QValueListIterator<QWidget *> it = list.begin(); it != list.end(); ++it ) #else QList<QWidget *> list = plot->legend()->legendItems(); for ( QList<QWidget*>::iterator it = list.begin(); it != list.end(); ++it ) #endif { QWidget *w = *it; cache.legendFonts.insert(w, w->font()); w->setFont(font(w->font(), Legend)); if ( w->inherits("QwtLegendItem") ) { QwtLegendItem *label = (QwtLegendItem *)w; QwtSymbol symbol = label->symbol(); QPen pen = symbol.pen(); QBrush brush = symbol.brush(); pen.setColor(color(pen.color(), CurveSymbol)); brush.setColor(color(brush.color(), CurveSymbol)); symbol.setPen(pen); symbol.setBrush(brush); label->setSymbol(symbol); pen = label->curvePen(); pen.setColor(color(pen.color(), Curve)); label->setCurvePen(pen); } } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { QwtScaleWidget *scaleWidget = plot->axisWidget(axis); if ( scaleWidget ) { cache.scaleColor[axis] = scaleWidget->palette().color( QPalette::Active, Palette::Foreground); QPalette palette = scaleWidget->palette(); palette.setColor(QPalette::Active, Palette::Foreground, color(cache.scaleColor[axis], AxisScale)); scaleWidget->setPalette(palette); cache.scaleFont[axis] = scaleWidget->font(); scaleWidget->setFont(font(cache.scaleFont[axis], AxisScale)); cache.scaleTitle[axis] = scaleWidget->title(); QwtText scaleTitle = scaleWidget->title(); if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextColor) ) { cache.scaleTitleColor[axis] = scaleTitle.color(); scaleTitle.setColor( color(cache.scaleTitleColor[axis], AxisTitle)); } if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextFont) ) { cache.scaleTitleFont[axis] = scaleTitle.font(); scaleTitle.setFont( font(cache.scaleTitleFont[axis], AxisTitle)); } scaleWidget->setTitle(scaleTitle); int startDist, endDist; scaleWidget->getBorderDistHint(startDist, endDist); scaleWidget->setBorderDist(startDist, endDist); } } if ( hasBackgroundColor(plot) ) { QPalette p = plot->palette(); cache.widgetBackground = plot->palette().color( QPalette::Active, Palette::Background); p.setColor(QPalette::Active, Palette::Background, color(cache.widgetBackground, WidgetBackground)); plot->setPalette(p); } if ( hasBackgroundColor(plot->canvas())) { cache.canvasBackground = plot->canvasBackground(); plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground)); } const QwtPlotItemList& itmList = plot->itemList(); for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it ) { apply(*it); } plot->setAutoReplot(doAutoReplot); }
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; }
void PlotMatrix::alignAxes( int rowOrColumn, int axis ) { if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) { double maxExtent = 0; for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); QwtScaleDraw *sd = scaleWidget->scaleDraw(); sd->setMinimumExtent( 0.0 ); const double extent = sd->extent( scaleWidget->font() ); if ( extent > maxExtent ) maxExtent = extent; } } for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); scaleWidget->scaleDraw()->setMinimumExtent( maxExtent ); } } } else { double maxExtent = 0; for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); QwtScaleDraw *sd = scaleWidget->scaleDraw(); sd->setMinimumExtent( 0.0 ); const double extent = sd->extent( scaleWidget->font() ); if ( extent > maxExtent ) maxExtent = extent; } } for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); scaleWidget->scaleDraw()->setMinimumExtent( maxExtent ); } } } }
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))); }