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