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); }
/*! \brief Draw a set of points of a curve. When observing an measurement while it is running, new points have to be added to an existing curve. drawCurve can be used to display them avoiding a complete redraw of the canvas. Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); will result in faster painting, if the paint engine of the canvas widget supports this feature. \param from Index of the first point to be painted \param to Index of the last point to be painted. If to < 0 the curve will be painted to its last point. \sa drawCurve(), drawSymbols() */ void QwtPlotCurve::draw(int from, int to) const { if ( !plot() ) return; QwtPlotCanvas *canvas = plot()->canvas(); #if QT_VERSION >= 0x040000 #if 0 if ( canvas->paintEngine()->type() == QPaintEngine::OpenGL ) { /* OpenGL alway repaint the complete widget. So for this operation OpenGL is one of the slowest environments. */ canvas->repaint(); return; } #endif if ( !canvas->testAttribute(Qt::WA_WState_InPaintEvent) && !canvas->testAttribute(Qt::WA_PaintOutsidePaintEvent) ) { /* We save curve and range in helper and call repaint. The helper filters the Paint event, to repeat the QwtPlotCurve::draw, but now from inside the paint event. */ QwtPlotCurvePaintHelper helper(this, from, to); canvas->installEventFilter(&helper); const bool noSystemBackground = canvas->testAttribute(Qt::WA_NoSystemBackground); canvas->setAttribute(Qt::WA_NoSystemBackground, true); canvas->repaint(); canvas->setAttribute(Qt::WA_NoSystemBackground, noSystemBackground); return; } #endif const QwtScaleMap xMap = plot()->canvasMap(xAxis()); const QwtScaleMap yMap = plot()->canvasMap(yAxis()); if ( canvas->testPaintAttribute(QwtPlotCanvas::PaintCached) && canvas->paintCache() && !canvas->paintCache()->isNull() ) { QPainter cachePainter((QPixmap *)canvas->paintCache()); cachePainter.translate(-canvas->contentsRect().x(), -canvas->contentsRect().y()); draw(&cachePainter, xMap, yMap, from, to); } #if QT_VERSION >= 0x040000 if ( canvas->testAttribute(Qt::WA_WState_InPaintEvent) ) { QPainter painter(canvas); painter.setClipping(true); painter.setClipRect(canvas->contentsRect()); draw(&painter, xMap, yMap, from, to); } else #endif { QPainter *painter = d_data->guardedPainter.begin(canvas); draw(painter, xMap, yMap, from, to); } }
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); }
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; }