Beispiel #1
0
void IncrementalPlot::appendData(double *x, double *y, int size) {
	if (d_data == NULL) d_data = new CurveData;

	if (d_curve == NULL) {
		d_curve = new QwtPlotCurve("Data");
		d_curve->setStyle(QwtPlotCurve::NoCurve);
		d_curve->setPaintAttribute(QwtPlotCurve::FilterPoints, true);
		const QColor &c = Qt::white;
		QwtSymbol *symbol = new QwtSymbol(QwtSymbol::Ellipse);
		symbol->setBrush(QBrush(c));
		symbol->setPen(QPen(c));
		symbol->setSize(QSize(6, 6));
		d_curve->setSymbol(symbol);
		d_curve->attach(this);
	}

	d_data->append(x, y, size);
	d_curve->setRawSamples(d_data->x(), d_data->y(), d_data->count());
#ifdef __GNUC__
#warning better use QwtData
#endif

	const bool cacheMode = qobject_cast<QwtPlotCanvas *>(canvas())->testPaintAttribute(QwtPlotCanvas::BackingStore);

#if QT_VERSION >= 0x040000 && defined(Q_WS_X11)
  // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent
  // works on X11. This has an tremendous effect on the performance..

	canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
#endif

	QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>(canvas());
	plotCanvas->setPaintAttribute(QwtPlotCanvas::BackingStore, false);
	QPainter painter;
	QwtScaleMap xMap = plotCanvas->plot()->canvasMap(d_curve->xAxis());
	QwtScaleMap yMap = plotCanvas->plot()->canvasMap(d_curve->yAxis());
	d_curve->drawSeries(&painter, xMap, yMap, (d_curve->paintRect(xMap, yMap)), d_curve->dataSize() - size, d_curve->dataSize() -1);
	plotCanvas->setPaintAttribute(QwtPlotCanvas::BackingStore, cacheMode);

#if QT_VERSION >= 0x040000 && defined(Q_WS_X11)
	canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false);
#endif
}
Beispiel #2
0
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);
}
Beispiel #3
0
// Move the selected point
void CanvasPicker::move( const QPoint &pos )
{
    if ( !d_selectedCurve )
        return;

    QVector<double> xData( d_selectedCurve->dataSize() );
    QVector<double> yData( d_selectedCurve->dataSize() );

    for ( int i = 0;
        i < static_cast<int>( d_selectedCurve->dataSize() ); i++ )
    {
        if ( i == d_selectedPoint )
        {
            xData[i] = plot()->invTransform(
                d_selectedCurve->xAxis(), pos.x() );
            yData[i] = plot()->invTransform(
                d_selectedCurve->yAxis(), pos.y() );
        }
        else
        {
            const QPointF sample = d_selectedCurve->sample( i );
            xData[i] = sample.x();
            yData[i] = sample.y();
        }
    }
    d_selectedCurve->setSamples( xData, yData );

    /*
       Enable QwtPlotCanvas::ImmediatePaint, so that the canvas has been
       updated before we paint the cursor on it.
     */
    QwtPlotCanvas *plotCanvas = 
        qobject_cast<QwtPlotCanvas *>( plot()->canvas() );

    plotCanvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, true );
    plot()->replot();
    plotCanvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, false );

    showCursor( true );
}
/*!
   Update the axes scales

   \param intervals Scale intervals
*/
void QwtPlotRescaler::updateScales(
    QwtInterval intervals[QwtPlot::axisCnt] ) const
{
    if ( d_data->inReplot >= 5 )
    {
        return;
    }

    QwtPlot *plt = const_cast<QwtPlot *>( plot() );

    const bool doReplot = plt->autoReplot();
    plt->setAutoReplot( false );

    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        if ( axis == referenceAxis() || aspectRatio( axis ) > 0.0 )
        {
            double v1 = intervals[axis].minValue();
            double v2 = intervals[axis].maxValue();

            if ( !plt->axisScaleDiv( axis ).isIncreasing() )
                qSwap( v1, v2 );

            if ( d_data->inReplot >= 1 )
                d_data->axisData[axis].scaleDiv = plt->axisScaleDiv( axis );

            if ( d_data->inReplot >= 2 )
            {
                QList<double> ticks[QwtScaleDiv::NTickTypes];
                for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
                    ticks[i] = d_data->axisData[axis].scaleDiv.ticks( i );

                plt->setAxisScaleDiv( axis, QwtScaleDiv( v1, v2, ticks ) );
            }
            else
            {
                plt->setAxisScale( axis, v1, v2 );
            }
        }
    }

    QwtPlotCanvas *canvas = qobject_cast<QwtPlotCanvas *>( plt->canvas() );

    bool immediatePaint = false;
    if ( canvas )
    {
        immediatePaint = canvas->testPaintAttribute( QwtPlotCanvas::ImmediatePaint );
        canvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, false );
    }

    plt->setAutoReplot( doReplot );

    d_data->inReplot++;
    plt->replot();
    d_data->inReplot--;

    if ( canvas && immediatePaint )
    {
        canvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, true );
    }
}
Beispiel #5
0
Plot::Plot(int width, int height, QWidget *parent, const char *)
: QwtPlot(parent)
{
	setAutoReplot (false);

	marker_key = 0;
	curve_key = 0;

	minTickLength = 5;
	majTickLength = 9;

	setGeometry(QRect(0, 0, width, height));
	setAxisTitle(QwtPlot::yLeft, tr("Y Axis Title"));
	setAxisTitle(QwtPlot::xBottom, tr("X Axis Title"));
	//due to the plot layout updates, we must always have a non empty title
	setAxisTitle(QwtPlot::yRight, tr(" "));
	setAxisTitle(QwtPlot::xTop, tr(" "));

	// grid
	d_grid = new Grid();
	d_grid->attach(this);

	//custom scale
	for (int i= 0; i<QwtPlot::axisCnt; i++) {
		QwtScaleWidget *scale = (QwtScaleWidget *) axisWidget(i);
		if (scale) {
			scale->setMargin(0);

			//the axis title color must be initialized...
			QwtText title = scale->title();
			title.setColor(Qt::black);
			scale->setTitle(title);

            //...same for axis color
            QPalette pal = scale->palette();
            pal.setColor(QPalette::Foreground, QColor(Qt::black));
            scale->setPalette(pal);

			ScaleDraw *sd = new ScaleDraw(this);
			sd->setTickLength(QwtScaleDiv::MinorTick, minTickLength);
			sd->setTickLength(QwtScaleDiv::MediumTick, minTickLength);
			sd->setTickLength(QwtScaleDiv::MajorTick, majTickLength);

			setAxisScaleDraw (i, sd);
			setAxisScaleEngine (i, new ScaleEngine());
		}
	}

	QwtPlotLayout *pLayout = plotLayout();
	pLayout->setCanvasMargin(0);
	pLayout->setAlignCanvasToScales (true);

	QwtPlotCanvas* plCanvas = canvas();
	plCanvas->setFocusPolicy(Qt::StrongFocus);
	plCanvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator);
	//plCanvas->setFocus();
	plCanvas->setFrameShadow(QwtPlot::Plain);
	plCanvas->setCursor(Qt::arrowCursor);
	plCanvas->setLineWidth(0);
	plCanvas->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
	plCanvas->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);

    QColor background = QColor(Qt::white);
    background.setAlpha(255);

	QPalette palette;
    palette.setColor(QPalette::Window, background);
    setPalette(palette);

	setCanvasBackground (background);
	setFocusPolicy(Qt::StrongFocus);
	//setFocusProxy(plCanvas);
	setFrameShape(QFrame::Box);
	setLineWidth(0);
}
Beispiel #6
0
Plot::Plot(QWidget *parent):
  QwtPlot(parent),
  d_origin(0),
  d_grid(0),
  d_marker(0),
  mStopped(true),
  mAxisSyncRequired(false),
  mColorMode(0),
  mTimeWindow(10.0),
  mAlignMode(RIGHT)
{
  setAutoReplot(false);

  // The backing store is important, when working with widget
  // overlays ( f.e rubberbands for zooming ). 
  // Here we don't have them and the internal 
  // backing store of QWidget is good enough.

  QwtPlotCanvas* plotCanvas = qobject_cast<QwtPlotCanvas*>(canvas());

  plotCanvas->setPaintAttribute(QwtPlotCanvas::BackingStore, false);


#if defined(Q_WS_X11)
  // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent
  // works on X11. This has a nice effect on the performance.

  plotCanvas->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);

  // Disabling the backing store of Qt improves the performance
  // for the direct painter even more, but the canvas becomes
  // a native window of the window system, receiving paint events
  // for resize and expose operations. Those might be expensive
  // when there are many points and the backing store of
  // the canvas is disabled. So in this application
  // we better don't both backing stores.

  if ( plotCanvas->testPaintAttribute( QwtPlotCanvas::BackingStore ) )
  {
    plotCanvas->setAttribute(Qt::WA_PaintOnScreen, true);
    plotCanvas->setAttribute(Qt::WA_NoSystemBackground, true);
  }

#endif



  plotLayout()->setAlignCanvasToScales(true);

  setAxisAutoScale(QwtPlot::xBottom, false);
  setAxisAutoScale(QwtPlot::yLeft, false);

  setAxisTitle(QwtPlot::xBottom, "Time [s]");
  setAxisScale(QwtPlot::xBottom, 0, 10);
  setAxisScale(QwtPlot::yLeft, -4.0, 4.0);

  setAxisScaleDraw(QwtPlot::xBottom, new MyScaleDraw);

  initBackground();

  QwtPlotZoomer* zoomer = new MyZoomer(this);
  zoomer->setMousePattern(QwtEventPattern::QwtEventPattern::MouseSelect1, Qt::LeftButton, Qt::ShiftModifier);

  // disable MouseSelect3 action of the zoomer
  zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::NoButton);

  MyPanner *panner = new MyPanner(this);

  // zoom in/out with the wheel
  mMagnifier = new MyMagnifier(this);
  mMagnifier->setMouseButton(Qt::MiddleButton);

  const QColor c(Qt::darkBlue);
  zoomer->setRubberBandPen(c);
  zoomer->setTrackerPen(c);

  this->setMinimumHeight(200);
}
Beispiel #7
0
void Plot::setSettings( const Settings &s )
{
    if ( d_timerId >= 0 )
        killTimer( d_timerId );

    d_timerId = startTimer( s.updateInterval );

    d_grid->setPen( s.grid.pen );
    d_grid->setVisible( s.grid.pen.style() != Qt::NoPen );

    CircularBuffer *buffer = static_cast<CircularBuffer *>( d_curve->data() );
    if ( s.curve.numPoints != buffer->size() ||
            s.curve.functionType != d_settings.curve.functionType )
    {
        switch( s.curve.functionType )
        {
            case Settings::Wave:
                buffer->setFunction( wave );
                break;
            case Settings::Noise:
                buffer->setFunction( noise );
                break;
            default:
                buffer->setFunction( NULL );
        }

        buffer->fill( d_interval, s.curve.numPoints );
    }

    d_curve->setPen( s.curve.pen );
    d_curve->setBrush( s.curve.brush );

    d_curve->setPaintAttribute( QwtPlotCurve::ClipPolygons,
        s.curve.paintAttributes & QwtPlotCurve::ClipPolygons );
    d_curve->setPaintAttribute( QwtPlotCurve::FilterPoints,
        s.curve.paintAttributes & QwtPlotCurve::FilterPoints );

    d_curve->setRenderHint( QwtPlotItem::RenderAntialiased,
        s.curve.renderHint & QwtPlotItem::RenderAntialiased );

#ifndef QWT_NO_OPENGL
    if ( s.canvas.openGL )
    {
        QwtPlotGLCanvas *plotCanvas = qobject_cast<QwtPlotGLCanvas *>( canvas() );
        if ( plotCanvas == NULL )
        {
            plotCanvas = new GLCanvas();
            plotCanvas->setPalette( QColor( "khaki" ) );

            setCanvas( plotCanvas );
        }
    }
    else
#endif
    {
        QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>( canvas() );
        if ( plotCanvas == NULL )
        {
            plotCanvas = new QwtPlotCanvas();
            plotCanvas->setFrameStyle( QFrame::Box | QFrame::Plain );
            plotCanvas->setLineWidth( 1 );
            plotCanvas->setPalette( Qt::white );

            setCanvas( plotCanvas );
        }

        plotCanvas->setAttribute( Qt::WA_PaintOnScreen, s.canvas.paintOnScreen );

        plotCanvas->setPaintAttribute(
            QwtPlotCanvas::BackingStore, s.canvas.useBackingStore );
        plotCanvas->setPaintAttribute(
            QwtPlotCanvas::ImmediatePaint, s.canvas.immediatePaint );
    }

    QwtPainter::setPolylineSplitting( s.curve.lineSplitting );

    d_settings = s;
}