QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgslayoutviewtool.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutviewtool.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#include "qgslayoutviewtool.h"
17
18#include "qgslayoutview.h"
20
21#include "moc_qgslayoutviewtool.cpp"
22
24 : QObject( view )
25 , mView( view )
26 , mToolName( name )
27{
28 connect( mView, &QgsLayoutView::willBeDeleted, this, [this] {
29 mView = nullptr;
30 } );
31}
32
33bool QgsLayoutViewTool::isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) const
34{
35 const int diffX = endViewPoint.x() - startViewPoint.x();
36 const int diffY = endViewPoint.y() - startViewPoint.y();
37 return std::abs( diffX ) >= 2 || std::abs( diffY ) >= 2;
38}
39
41{
42 return mView;
43}
44
46{
47 return mView->currentLayout();
48}
49
50QList<QgsLayoutItem *> QgsLayoutViewTool::ignoredSnapItems() const
51{
52 return QList<QgsLayoutItem *>();
53}
54
56{
57 if ( mView )
58 mView->unsetTool( this );
59}
60
62{
63 return mFlags;
64}
65
70
72{
73 event->ignore();
74}
75
77{
78 event->ignore();
79}
80
82{
83 event->ignore();
84}
85
87{
88 event->ignore();
89}
90
91void QgsLayoutViewTool::wheelEvent( QWheelEvent *event )
92{
93 event->ignore();
94}
95
96void QgsLayoutViewTool::keyPressEvent( QKeyEvent *event )
97{
98 event->ignore();
99}
100
102{
103 event->ignore();
104}
105
107{
108 mAction = action;
109}
110
112{
113 return mAction;
114}
115
116void QgsLayoutViewTool::setCursor( const QCursor &cursor )
117{
118 mCursor = cursor;
119}
120
122{
123 // make action and/or button active
124 if ( mAction )
125 mAction->setChecked( true );
126
127 mView->viewport()->setCursor( mCursor );
128 emit activated();
129}
130
132{
133 if ( mAction )
134 mAction->setChecked( false );
135
136 emit deactivated();
137}
A mouse event which is the result of a user interaction with a QgsLayoutView.
void setCursor(const QCursor &cursor)
Sets a user defined cursor for use when the tool is active.
QgsLayoutView * view() const
Returns the view associated with the tool.
virtual QList< QgsLayoutItem * > ignoredSnapItems() const
Returns a list of items which should be ignored while snapping events for this tool.
virtual void deactivate()
Called when tool is deactivated.
virtual void layoutDoubleClickEvent(QgsLayoutViewMouseEvent *event)
Mouse double-click event for overriding.
QgsLayoutViewTool::Flags flags() const
Returns the current combination of flags set for the tool.
virtual void wheelEvent(QWheelEvent *event)
Mouse wheel event for overriding.
QAction * action()
Returns the action associated with the tool or nullptr if no action is associated.
virtual void keyReleaseEvent(QKeyEvent *event)
Key release event for overriding.
bool isClickAndDrag(QPoint startViewPoint, QPoint endViewPoint) const
Returns true if a mouse press/release operation which started at startViewPoint and ended at endViewP...
void setFlags(QgsLayoutViewTool::Flags flags)
Sets the combination of flags that will be used for the tool.
void setAction(QAction *action)
Associates an action with this tool.
virtual void activate()
Called when tool is set as the currently active layout tool.
QgsLayout * layout() const
Returns the layout associated with the tool.
virtual void layoutMoveEvent(QgsLayoutViewMouseEvent *event)
Mouse move event for overriding.
void activated()
Emitted when the tool is activated.
virtual void layoutPressEvent(QgsLayoutViewMouseEvent *event)
Mouse press event for overriding.
QgsLayoutViewTool(QgsLayoutView *view, const QString &name)
Constructor for QgsLayoutViewTool, taking a layout view and tool name as parameters.
virtual void layoutReleaseEvent(QgsLayoutViewMouseEvent *event)
Mouse release event for overriding.
virtual void keyPressEvent(QKeyEvent *event)
Key press event for overriding.
QFlags< Flag > Flags
void deactivated()
Emitted when the tool is deactivated.
A graphical widget to display and interact with QgsLayouts.
void willBeDeleted()
Emitted in the destructor when the view is about to be deleted, but is still in a perfectly valid sta...
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:50