QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
21
22#include "moc_qgsmodelviewtool.cpp"
23
24QgsModelViewTool::QgsModelViewTool( QgsModelGraphicsView *view, const QString &name )
25 : QObject( view )
26 , mView( view )
27 , mToolName( name )
28{
29 connect( mView, &QgsModelGraphicsView::willBeDeleted, this, [this] {
30 mView = nullptr;
31 } );
32}
33
34bool QgsModelViewTool::isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) const
35{
36 const int diffX = endViewPoint.x() - startViewPoint.x();
37 const int diffY = endViewPoint.y() - startViewPoint.y();
38 return std::abs( diffX ) >= 2 || std::abs( diffY ) >= 2;
39}
40
41QgsModelGraphicsView *QgsModelViewTool::view() const
42{
43 return mView;
44}
45
46QgsModelGraphicsScene *QgsModelViewTool::scene() const
47{
48 return qobject_cast<QgsModelGraphicsScene *>( mView->scene() );
49}
50
52{
53 if ( mView )
54 mView->unsetTool( this );
55}
56
58{
59 return mFlags;
60}
61
66
68{
69 event->ignore();
70}
71
73{
74 event->ignore();
75}
76
78{
79 event->ignore();
80}
81
83{
84 event->ignore();
85}
86
87void QgsModelViewTool::wheelEvent( QWheelEvent *event )
88{
89 event->ignore();
90}
91
92void QgsModelViewTool::keyPressEvent( QKeyEvent *event )
93{
94 event->ignore();
95}
96
97void QgsModelViewTool::keyReleaseEvent( QKeyEvent *event )
98{
99 event->ignore();
100}
101
103{
104 return false;
105}
106
108{
109 mAction = action;
110}
111
113{
114 return mAction;
115}
116
117void QgsModelViewTool::setCursor( const QCursor &cursor )
118{
119 mCursor = cursor;
120}
121
123{
124 // make action and/or button active
125 if ( mAction )
126 mAction->setChecked( true );
127
128 mView->viewport()->setCursor( mCursor );
129 emit activated();
130}
131
133{
134 if ( mAction )
135 mAction->setChecked( false );
136
137 emit deactivated();
138}
A mouse event which is the result of a user interaction with 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.