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 ); } } }
//--------------------------------------------------------------------------- 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 ); } } }
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."); }
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 ); } } } }