27#include <QGestureEvent>
32#include "moc_qgsplotcanvas.cpp"
34using namespace Qt::StringLiterals;
37 : QGraphicsView( parent )
39 setObjectName( u
"PlotCanvas"_s );
40 mScene =
new QGraphicsScene(
this );
43 setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
44 setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
45 setMouseTracking(
true );
46 viewport()->setMouseTracking(
true );
48 setFocusPolicy( Qt::StrongFocus );
50 setRenderHints( QPainter::Antialiasing );
79 qDeleteAll( mScene->items() );
81 mScene->deleteLater();
99 mTool->populateContextMenuWithEvent( &menu,
event );
104 if ( !menu.isEmpty() )
105 menu.exec(
event->globalPos() );
112 mTool->keyPressEvent(
event );
114 if ( mTool &&
event->isAccepted() )
117 if (
event->key() == Qt::Key_Space && !
event->isAutoRepeat() )
119 if ( !(
event->modifiers() & Qt::ControlModifier ) )
137 mTool->keyReleaseEvent(
event );
140 if ( !mTool || !
event->isAccepted() )
141 QGraphicsView::keyReleaseEvent(
event );
148 auto me = std::make_unique<QgsPlotMouseEvent>(
this,
event );
149 mTool->plotDoubleClickEvent( me.get() );
150 event->setAccepted( me->isAccepted() );
153 if ( !mTool || !
event->isAccepted() )
154 QGraphicsView::mouseDoubleClickEvent(
event );
161 auto me = std::make_unique<QgsPlotMouseEvent>(
this,
event );
162 mTool->plotPressEvent( me.get() );
163 event->setAccepted( me->isAccepted() );
166 if ( !mTool || !
event->isAccepted() )
168 if (
event->button() == Qt::MiddleButton )
171 setTool( mMidMouseButtonPanTool );
176 auto me = std::make_unique<QgsPlotMouseEvent>(
this,
event );
177 showContextMenu( me.get() );
183 QGraphicsView::mousePressEvent(
event );
192 auto me = std::make_unique<QgsPlotMouseEvent>(
this,
event );
193 mTool->plotReleaseEvent( me.get() );
194 event->setAccepted( me->isAccepted() );
197 if ( !mTool || !
event->isAccepted() )
198 QGraphicsView::mouseReleaseEvent(
event );
203 QGraphicsView::resizeEvent( e );
210 mTool->wheelEvent(
event );
213 if ( !mTool || !
event->isAccepted() )
224 auto me = std::make_unique<QgsPlotMouseEvent>(
this,
event );
225 mTool->plotMoveEvent( me.get() );
226 event->setAccepted( me->isAccepted() );
229 if ( !mTool || !
event->isAccepted() )
230 QGraphicsView::mouseMoveEvent(
event );
253 if ( mTool && mTool ==
tool )
257 setCursor( Qt::ArrowCursor );
304 if (
event->type() == QEvent::ToolTip && mTool && mTool->canvasToolTipEvent( qgis::down_cast<QHelpEvent *>(
event ) ) )
308 return QGraphicsView::viewportEvent(
event );
317 if ( e->type() == QEvent::Gesture )
322 return mTool->gestureEvent(
static_cast<QGestureEvent *
>( e ) );
327 return QGraphicsView::event( e );
@ ShowContextMenu
Show a context menu when right-clicking with the tool.
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 mouse event which is the result of a user interaction with a QgsPlotCanvas.
Point geometry type, with support for z-dimension and m-values.