20#include "moc_qgsplotcanvas.cpp"
29#include <QGestureEvent>
32 : QGraphicsView( parent )
34 setObjectName( QStringLiteral(
"PlotCanvas" ) );
35 mScene =
new QGraphicsScene(
this );
38 setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
39 setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
40 setMouseTracking(
true );
41 viewport()->setMouseTracking(
true );
43 setFocusPolicy( Qt::StrongFocus );
45 setRenderHints( QPainter::Antialiasing );
74 qDeleteAll( mScene->items() );
76 mScene->deleteLater();
96 mTool->populateContextMenuWithEvent( &menu,
event );
101 if ( !menu.isEmpty() )
102 menu.exec(
event->globalPos() );
109 mTool->keyPressEvent(
event );
111 if ( mTool &&
event->isAccepted() )
114 if (
event->key() == Qt::Key_Space && !
event->isAutoRepeat() )
116 if ( !(
event->modifiers() & Qt::ControlModifier ) )
134 mTool->keyReleaseEvent(
event );
137 if ( !mTool || !
event->isAccepted() )
138 QGraphicsView::keyReleaseEvent(
event );
146 mTool->plotDoubleClickEvent( me.get() );
147 event->setAccepted( me->isAccepted() );
150 if ( !mTool || !
event->isAccepted() )
151 QGraphicsView::mouseDoubleClickEvent(
event );
159 mTool->plotPressEvent( me.get() );
160 event->setAccepted( me->isAccepted() );
163 if ( !mTool || !
event->isAccepted() )
165 if (
event->button() == Qt::MiddleButton )
168 setTool( mMidMouseButtonPanTool );
174 showContextMenu( me.get() );
180 QGraphicsView::mousePressEvent(
event );
190 mTool->plotReleaseEvent( me.get() );
191 event->setAccepted( me->isAccepted() );
194 if ( !mTool || !
event->isAccepted() )
195 QGraphicsView::mouseReleaseEvent(
event );
200 QGraphicsView::resizeEvent( e );
207 mTool->wheelEvent(
event );
210 if ( !mTool || !
event->isAccepted() )
222 mTool->plotMoveEvent( me.get() );
223 event->setAccepted( me->isAccepted() );
226 if ( !mTool || !
event->isAccepted() )
227 QGraphicsView::mouseMoveEvent(
event );
250 if ( mTool && mTool ==
tool )
254 setCursor( Qt::ArrowCursor );
305 if (
event->type() == QEvent::ToolTip && mTool && mTool->canvasToolTipEvent( qgis::down_cast<QHelpEvent *>(
event ) ) )
309 return QGraphicsView::viewportEvent(
event );
319 if ( e->type() == QEvent::Gesture )
324 return mTool->gestureEvent(
static_cast<QGestureEvent *
>( e ) );
329 return QGraphicsView::event( e );
@ ShowContextMenu
Show a context menu when right-clicking with the tool.
This class represents a coordinate reference system (CRS).
bool event(QEvent *e) override
void setTool(QgsPlotTool *tool)
Sets the interactive tool currently being used on the canvas.
virtual void cancelJobs()
Cancel any rendering job, in a blocking way.
QgsPlotCanvas(QWidget *parent=nullptr)
Constructor for QgsPlotCanvas, with the specified parent widget.
virtual void refresh()
Updates and redraws the plot.
virtual void zoomToRect(const QRectF &rect)
Zooms the plot to the specified rect in canvas units.
void keyPressEvent(QKeyEvent *e) override
virtual void panContentsBy(double dx, double dy)
Pans the plot contents by dx, dy in canvas units.
void mousePressEvent(QMouseEvent *e) override
void toolChanged(QgsPlotTool *newTool)
Emitted when the plot tool is changed.
virtual QgsPointXY toCanvasCoordinates(const QgsPoint &point) const
Converts a point in map coordinates to the associated canvas point.
~QgsPlotCanvas() override
void keyReleaseEvent(QKeyEvent *e) override
QgsPlotTool * tool()
Returns the currently active tool.
void mouseDoubleClickEvent(QMouseEvent *e) override
void contextMenuAboutToShow(QMenu *menu, QgsPlotMouseEvent *event)
Emitted before the canvas context menu will be shown.
void mouseReleaseEvent(QMouseEvent *e) override
void unsetTool(QgsPlotTool *tool)
Unset the current tool.
void wheelEvent(QWheelEvent *e) override
void mouseMoveEvent(QMouseEvent *e) override
void resizeEvent(QResizeEvent *e) override
void willBeDeleted()
Emitted in the destructor when the canvas is about to be deleted, but is still in a perfectly valid s...
virtual void scalePlot(double factor)
Scales the plot by a specified scale factor.
virtual QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system (CRS) for map coordinates used by the canvas.
virtual void wheelZoom(QWheelEvent *event)
Zoom plot from a mouse wheel event.
virtual QgsPoint toMapCoordinates(const QgsPointXY &point) const
Converts a point on the canvas to the associated map coordinate.
bool viewportEvent(QEvent *event) override
virtual QgsPointXY snapToPlot(QPoint point)
Snap a canvas point to the plot.
virtual void centerPlotOn(double x, double y)
Centers the plot on the plot point corresponding to x, y in canvas units.
A QgsPlotMouseEvent is the result of a user interaction with the mouse on a QgsPlotCanvas.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.