QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgslayoutviewtool.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutviewtool.h
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 #ifndef QGSLAYOUTVIEWTOOL_H
17 #define QGSLAYOUTVIEWTOOL_H
18 
19 #include "qgis_sip.h"
20 #include "qgis_gui.h"
21 #include <QCursor>
22 #include <QAction>
23 #include <QPointer>
24 
25 class QMouseEvent;
26 class QWheelEvent;
27 class QKeyEvent;
28 class QgsLayoutView;
30 class QgsLayout;
31 class QgsLayoutItem;
32 
33 #ifdef SIP_RUN
34 % ModuleHeaderCode
36 % End
37 #endif
38 
46 class GUI_EXPORT QgsLayoutViewTool : public QObject
47 {
48 
49 #ifdef SIP_RUN
51  if ( dynamic_cast<QgsLayoutViewToolAddItem *>( sipCpp ) != NULL )
52  sipType = sipType_QgsLayoutViewToolAddItem;
53  else
54  sipType = NULL;
55  SIP_END
56 #endif
57 
58  Q_OBJECT
59 
60  public:
61 
63  enum Flag
64  {
65  FlagSnaps = 1 << 1,
66  };
67  Q_DECLARE_FLAGS( Flags, Flag )
68 
69  ~QgsLayoutViewTool() override;
70 
75  QgsLayoutViewTool::Flags flags() const;
76 
80  virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event );
81 
85  virtual void layoutDoubleClickEvent( QgsLayoutViewMouseEvent *event );
86 
94  virtual void layoutPressEvent( QgsLayoutViewMouseEvent *event );
95 
103  virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );
104 
108  virtual void wheelEvent( QWheelEvent *event );
109 
113  virtual void keyPressEvent( QKeyEvent *event );
114 
118  virtual void keyReleaseEvent( QKeyEvent *event );
119 
127  void setAction( QAction *action );
128 
133  QAction *action();
134 
138  void setCursor( const QCursor &cursor );
139 
144  virtual void activate();
145 
150  virtual void deactivate();
151 
155  QString toolName() const { return mToolName; }
156 
161  QgsLayoutView *view() const;
162 
167  QgsLayout *layout() const;
168 
173  virtual QList< QgsLayoutItem * > ignoredSnapItems() const;
174 
175  signals:
176 
180  void activated();
181 
185  void deactivated();
186 
191  void itemFocused( QgsLayoutItem *item );
192 
193  protected:
194 
199  void setFlags( QgsLayoutViewTool::Flags flags );
200 
205  QgsLayoutViewTool( QgsLayoutView *view SIP_TRANSFERTHIS, const QString &name );
206 
213  bool isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) const;
214 
215  private:
216 
218  QgsLayoutView *mView = nullptr;
219 
220  QgsLayoutViewTool::Flags mFlags = QgsLayoutViewTool::Flags();
221 
223  QCursor mCursor = Qt::ArrowCursor;
224 
226  QPointer< QAction > mAction;
227 
229  QString mToolName;
230 
231  friend class TestQgsLayoutView;
232 
233 };
234 
235 #endif // QGSLAYOUTVIEWTOOL_H
Base class for graphical items within a QgsLayout.
A QgsLayoutViewMouseEvent is the result of a user interaction with the mouse on a QgsLayoutView.
Layout view tool for adding items to a layout.
Abstract base class for all layout view tools.
Flag
Flags for controlling how a tool behaves.
QString toolName() const
Returns a user-visible, translated name for the tool.
void activated()
Emitted when the tool is activated.
void itemFocused(QgsLayoutItem *item)
Emitted when an item is "focused" by the tool, i.e.
void deactivated()
Emitted when the tool is deactivated.
A graphical widget to display and interact with QgsLayouts.
Definition: qgslayoutview.h:50
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_END
Definition: qgis_sip.h:194