QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsmodelviewtool.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmodelviewtool.cpp
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#include "qgsmodelviewtool.h"
17#include "moc_qgsmodelviewtool.cpp"
21
22QgsModelViewTool::QgsModelViewTool( QgsModelGraphicsView *view, const QString &name )
23 : QObject( view )
24 , mView( view )
25 , mToolName( name )
26{
27 connect( mView, &QgsModelGraphicsView::willBeDeleted, this, [ = ]
28 {
29 mView = nullptr;
30 } );
31}
32
33bool QgsModelViewTool::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
40QgsModelGraphicsView *QgsModelViewTool::view() const
41{
42 return mView;
43}
44
45QgsModelGraphicsScene *QgsModelViewTool::scene() const
46{
47 return qobject_cast< QgsModelGraphicsScene * >( mView->scene() );
48}
49
51{
52 if ( mView )
53 mView->unsetTool( this );
54}
55
57{
58 return mFlags;
59}
60
62{
63 mFlags = flags;
64}
65
67{
68 event->ignore();
69}
70
72{
73 event->ignore();
74}
75
77{
78 event->ignore();
79}
80
82{
83 event->ignore();
84}
85
86void QgsModelViewTool::wheelEvent( QWheelEvent *event )
87{
88 event->ignore();
89}
90
91void QgsModelViewTool::keyPressEvent( QKeyEvent *event )
92{
93 event->ignore();
94}
95
96void QgsModelViewTool::keyReleaseEvent( QKeyEvent *event )
97{
98 event->ignore();
99}
100
102{
103 return false;
104}
105
106void QgsModelViewTool::setAction( QAction *action )
107{
108 mAction = action;
109}
110
112{
113 return mAction;
114}
115
116void QgsModelViewTool::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 QgsModelViewMouseEvent is the result of a user interaction with the mouse on a QgsModelGraphicsView...
QFlags< Flag > Flags
virtual void keyReleaseEvent(QKeyEvent *event)
Key release event for overriding.
QgsModelGraphicsView * view() const
Returns the view associated with the tool.
virtual void modelDoubleClickEvent(QgsModelViewMouseEvent *event)
Mouse double-click event for overriding.
void setAction(QAction *action)
Associates an action with this tool.
~QgsModelViewTool() override
QAction * action()
Returns the action associated with the tool or nullptr if no action is associated.
virtual void wheelEvent(QWheelEvent *event)
Mouse wheel 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...
QgsModelViewTool::Flags flags() const
Returns the current combination of flags set for the tool.
void setCursor(const QCursor &cursor)
Sets a user defined cursor for use when the tool is active.
virtual void modelMoveEvent(QgsModelViewMouseEvent *event)
Mouse move event for overriding.
void activated()
Emitted when the tool is activated.
virtual bool allowItemInteraction()
Returns true if the tool allows interaction with component graphic items.
virtual void deactivate()
Called when tool is deactivated.
QgsModelViewTool(QgsModelGraphicsView *view, const QString &name)
Constructor for QgsModelViewTool, taking a model view and tool name as parameters.
virtual void activate()
Called when tool is set as the currently active model tool.
void deactivated()
Emitted when the tool is deactivated.
virtual void modelPressEvent(QgsModelViewMouseEvent *event)
Mouse press event for overriding.
void setFlags(QgsModelViewTool::Flags flags)
Sets the combination of flags that will be used for the tool.
virtual void keyPressEvent(QKeyEvent *event)
Key press event for overriding.
virtual void modelReleaseEvent(QgsModelViewMouseEvent *event)
Mouse release event for overriding.
QgsModelGraphicsScene * scene() const
Returns the scene associated with the tool.