QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsmodelviewtool.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmodelviewtool.h
3  -------------------
4  Date : March 2020
5  Copyright : (C) 2020 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 QGSMODELVIEWTOOL_H
17 #define QGSMODELVIEWTOOL_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 QgsModelGraphicsView;
30 class QgsModelComponentGraphicItem;
31 class QgsModelGraphicsScene;
32 
33 #define SIP_NO_FILE
34 
43 class GUI_EXPORT QgsModelViewTool : public QObject
44 {
45 
46  Q_OBJECT
47 
48  public:
49 
51  enum Flag
52  {
53  FlagSnaps = 1 << 1,
54  };
55  Q_DECLARE_FLAGS( Flags, Flag )
56 
57  ~QgsModelViewTool() override;
58 
63  QgsModelViewTool::Flags flags() const;
64 
68  virtual void modelMoveEvent( QgsModelViewMouseEvent *event );
69 
73  virtual void modelDoubleClickEvent( QgsModelViewMouseEvent *event );
74 
82  virtual void modelPressEvent( QgsModelViewMouseEvent *event );
83 
91  virtual void modelReleaseEvent( QgsModelViewMouseEvent *event );
92 
96  virtual void wheelEvent( QWheelEvent *event );
97 
101  virtual void keyPressEvent( QKeyEvent *event );
102 
106  virtual void keyReleaseEvent( QKeyEvent *event );
107 
111  virtual bool allowItemInteraction();
112 
120  void setAction( QAction *action );
121 
126  QAction *action();
127 
131  void setCursor( const QCursor &cursor );
132 
137  virtual void activate();
138 
143  virtual void deactivate();
144 
148  QString toolName() const { return mToolName; }
149 
154  QgsModelGraphicsView *view() const;
155 
160  QgsModelGraphicsScene *scene() const;
161 
162  signals:
163 
167  void activated();
168 
172  void deactivated();
173 
178  void itemFocused( QgsModelComponentGraphicItem *item );
179 
180  protected:
181 
186  void setFlags( QgsModelViewTool::Flags flags );
187 
192  QgsModelViewTool( QgsModelGraphicsView *view SIP_TRANSFERTHIS, const QString &name );
193 
200  bool isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) const;
201 
202  private:
203 
205  QgsModelGraphicsView *mView = nullptr;
206 
207  QgsModelViewTool::Flags mFlags = nullptr;
208 
210  QCursor mCursor = Qt::ArrowCursor;
211 
213  QPointer< QAction > mAction;
214 
216  QString mToolName;
217 
218 
219 };
220 
221 #endif // QGSMODELVIEWTOOL_H
QgsModelViewMouseEvent
Definition: qgsmodelviewmouseevent.h:36
QgsModelViewTool::toolName
QString toolName() const
Returns a user-visible, translated name for the tool.
Definition: qgsmodelviewtool.h:148
qgis_sip.h
QgsModelViewTool
Definition: qgsmodelviewtool.h:43
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsModelViewTool::Flag
Flag
Flags for controlling how a tool behaves.
Definition: qgsmodelviewtool.h:51