28#include <QGestureEvent> 
   31  : QGraphicsView( parent )
 
   33  setObjectName( QStringLiteral( 
"PlotCanvas" ) );
 
   34  mScene = 
new QGraphicsScene( 
this );
 
   37  setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 
   38  setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 
   39  setMouseTracking( 
true );
 
   40  viewport()->setMouseTracking( 
true );
 
   42  setFocusPolicy( Qt::StrongFocus );
 
   44  setRenderHints( QPainter::Antialiasing );
 
 
   73  qDeleteAll( mScene->items() );
 
   75  mScene->deleteLater();
 
 
   95    mTool->populateContextMenuWithEvent( &menu, 
event );
 
  100  if ( !menu.isEmpty() )
 
  101    menu.exec( 
event->globalPos() );
 
  108    mTool->keyPressEvent( 
event );
 
  110  if ( mTool && 
event->isAccepted() )
 
  113  if ( 
event->key() == Qt::Key_Space && ! 
event->isAutoRepeat() )
 
  115    if ( !( 
event->modifiers() & Qt::ControlModifier ) )
 
 
  133    mTool->keyReleaseEvent( 
event );
 
  136  if ( !mTool || !
event->isAccepted() )
 
  137    QGraphicsView::keyReleaseEvent( 
event );
 
 
  145    mTool->plotDoubleClickEvent( me.get() );
 
  146    event->setAccepted( me->isAccepted() );
 
  149  if ( !mTool || !
event->isAccepted() )
 
  150    QGraphicsView::mouseDoubleClickEvent( 
event );
 
 
  158    mTool->plotPressEvent( me.get() );
 
  159    event->setAccepted( me->isAccepted() );
 
  162  if ( !mTool || !
event->isAccepted() )
 
  164    if ( 
event->button() == Qt::MiddleButton )
 
  167      setTool( mMidMouseButtonPanTool );
 
  173      showContextMenu( me.get() );
 
  179      QGraphicsView::mousePressEvent( 
event );
 
 
  189    mTool->plotReleaseEvent( me.get() );
 
  190    event->setAccepted( me->isAccepted() );
 
  193  if ( !mTool || !
event->isAccepted() )
 
  194    QGraphicsView::mouseReleaseEvent( 
event );
 
 
  199  QGraphicsView::resizeEvent( e );
 
 
  206    mTool->wheelEvent( 
event );
 
  209  if ( !mTool || !
event->isAccepted() )
 
 
  221    mTool->plotMoveEvent( me.get() );
 
  222    event->setAccepted( me->isAccepted() );
 
  225  if ( !mTool || !
event->isAccepted() )
 
  226    QGraphicsView::mouseMoveEvent( 
event );
 
 
  249  if ( mTool && mTool == 
tool )
 
  253    setCursor( Qt::ArrowCursor );
 
 
  304  if ( 
event->type() == QEvent::ToolTip && mTool && mTool->canvasToolTipEvent( qgis::down_cast<QHelpEvent *>( 
event ) ) )
 
  308  return QGraphicsView::viewportEvent( 
event );
 
 
  318  if ( e->type() == QEvent::Gesture )
 
  323      return mTool->gestureEvent( 
static_cast<QGestureEvent *
>( e ) );
 
  328  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.