QGIS API Documentation  3.6.0-Noosa (5873452)
qgslayoutviewmouseevent.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutviewmouseevent.cpp
3  ---------------------------
4  Date : July 2017
5  Copyright : (C) 2017 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 
18 #include "qgslayoutview.h"
19 #include "qgslayout.h"
20 
21 QgsLayoutViewMouseEvent::QgsLayoutViewMouseEvent( QgsLayoutView *view, QMouseEvent *event, bool snap )
22  : QMouseEvent( event->type(), event->pos(), event->button(), event->buttons(), event->modifiers() )
23  , mView( view )
24 {
25  mLayoutPoint = mView->mapToScene( x(), y() );
26  if ( snap && mView->currentLayout() )
27  {
28  mSnappedPoint = mView->currentLayout()->snapper().snapPoint( mLayoutPoint, mView->transform().m11(), mSnapped );
29  }
30  else
31  {
32  mSnappedPoint = mLayoutPoint;
33  }
34 }
35 
36 void QgsLayoutViewMouseEvent::snapPoint( QGraphicsLineItem *horizontalSnapLine, QGraphicsLineItem *verticalSnapLine, const QList<QgsLayoutItem *> &excludeItems )
37 {
38  if ( mView->currentLayout() )
39  {
40  mSnappedPoint = mView->currentLayout()->snapper().snapPoint( mLayoutPoint, mView->transform().m11(), mSnapped, horizontalSnapLine, verticalSnapLine, &excludeItems );
41  }
42 }
43 
45 {
46  return mLayoutPoint;
47 }
A graphical widget to display and interact with QgsLayouts.
Definition: qgslayoutview.h:49
QgsLayoutSnapper & snapper()
Returns a reference to the layout&#39;s snapper, which stores handles layout snap grids and lines and sna...
Definition: qgslayout.h:406
QgsLayoutViewMouseEvent(QgsLayoutView *view, QMouseEvent *event, bool snap=false)
Constructor for QgsLayoutViewMouseEvent.
void snapPoint(QGraphicsLineItem *horizontalSnapLine=nullptr, QGraphicsLineItem *verticalSnapLine=nullptr, const QList< QgsLayoutItem *> &ignoreItems=QList< QgsLayoutItem * >())
Manually triggers a snap for the mouse event position using the layout&#39;s snapper. ...
QPointF snapPoint(QPointF point, double scaleFactor, bool &snapped, QGraphicsLineItem *horizontalSnapLine=nullptr, QGraphicsLineItem *verticalSnapLine=nullptr, const QList< QgsLayoutItem * > *ignoreItems=nullptr) const
Snaps a layout coordinate point.
QPointF layoutPoint() const
Returns the event point location in layout coordinates.
QgsLayout currentLayout
Definition: qgslayoutview.h:63