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();
94 mTool->populateContextMenuWithEvent( &menu,
event );
99 if ( !menu.isEmpty() )
100 menu.exec(
event->globalPos() );
107 mTool->keyPressEvent(
event );
109 if ( mTool &&
event->isAccepted() )
112 if (
event->key() == Qt::Key_Space && !
event->isAutoRepeat() )
114 if ( !(
event->modifiers() & Qt::ControlModifier ) )
132 mTool->keyReleaseEvent(
event );
135 if ( !mTool || !
event->isAccepted() )
136 QGraphicsView::keyReleaseEvent(
event );
144 mTool->plotDoubleClickEvent( me.get() );
145 event->setAccepted( me->isAccepted() );
148 if ( !mTool || !
event->isAccepted() )
149 QGraphicsView::mouseDoubleClickEvent(
event );
157 mTool->plotPressEvent( me.get() );
158 event->setAccepted( me->isAccepted() );
161 if ( !mTool || !
event->isAccepted() )
163 if (
event->button() == Qt::MiddleButton )
166 setTool( mMidMouseButtonPanTool );
172 showContextMenu( me.get() );
178 QGraphicsView::mousePressEvent(
event );
188 mTool->plotReleaseEvent( me.get() );
189 event->setAccepted( me->isAccepted() );
192 if ( !mTool || !
event->isAccepted() )
193 QGraphicsView::mouseReleaseEvent(
event );
198 QGraphicsView::resizeEvent( e );
205 mTool->wheelEvent(
event );
208 if ( !mTool || !
event->isAccepted() )
220 mTool->plotMoveEvent( me.get() );
221 event->setAccepted( me->isAccepted() );
224 if ( !mTool || !
event->isAccepted() )
225 QGraphicsView::mouseMoveEvent(
event );
248 if ( mTool && mTool ==
tool )
252 setCursor( Qt::ArrowCursor );
299 if (
event->type() == QEvent::ToolTip && mTool && mTool->canvasToolTipEvent( qgis::down_cast<QHelpEvent *>(
event ) ) )
303 return QGraphicsView::viewportEvent(
event );
312 if ( e->type() == QEvent::Gesture )
317 return mTool->gestureEvent(
static_cast<QGestureEvent *
>( e ) );
322 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.