QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsidentifymenu.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsidentifymenu.h - menu to be used in identify map tool
3 ---------------------
4 begin : August 2014
5 copyright : (C) 2014 by Denis Rouzaud
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 QGSIDENTIFYMENU_H
17#define QGSIDENTIFYMENU_H
18
19#include <QMenu>
20
22#include "qgsmaptoolidentify.h"
24#include "qgis_gui.h"
25#include "qgis_sip.h"
26
27#ifndef SIP_RUN
29class CustomActionRegistry : public QgsMapLayerActionRegistry
30{
31 Q_OBJECT
32
33 public:
35 CustomActionRegistry() = default;
36 // remove all actions
37 void clear() { mMapLayerActionList.clear(); }
38};
40#endif
41
49class GUI_EXPORT QgsIdentifyMenu : public QMenu
50{
51
52 Q_OBJECT
53
54 public:
56 {
58 FeatureLevel
59 };
60
62 {
63
64 ActionData() = default;
65
66 ActionData( QgsMapLayer *layer, QgsMapLayerAction *mapLayerAction = nullptr )
67 : mIsValid( true )
68 , mAllResults( !layer )
69 , mIsExternalAction( nullptr != mapLayerAction )
70 , mLayer( layer )
71 , mMapLayerAction( mapLayerAction )
72 {}
73
74 ActionData( QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction = nullptr )
75 : mIsValid( true )
76 , mIsExternalAction( nullptr != mapLayerAction )
77 , mLayer( layer )
78 , mFeatureId( fid )
79 , mLevel( FeatureLevel )
80 , mMapLayerAction( mapLayerAction )
81 {}
82
83 bool mIsValid = false;
84 bool mAllResults = false;
85 bool mIsExternalAction = false;
86 QgsMapLayer *mLayer = nullptr;
87 QgsFeatureId mFeatureId = 0;
88 QgsIdentifyMenu::MenuLevel mLevel = LayerLevel;
89 QgsMapLayerAction *mMapLayerAction = nullptr;
90 };
91
95 explicit QgsIdentifyMenu( QgsMapCanvas *canvas );
96
97 ~QgsIdentifyMenu() override;
98
99
110 static QList<QgsMapToolIdentify::IdentifyResult> findFeaturesOnCanvas( QgsMapMouseEvent *event, QgsMapCanvas *canvas, const QList<Qgis::GeometryType> &geometryTypes );
111
113 void setAllowMultipleReturn( bool multipleReturn ) { mAllowMultipleReturn = multipleReturn;}
114 bool allowMultipleReturn() { return mAllowMultipleReturn;}
115
117 void setExecWithSingleResult( bool execWithSingleResult ) { mExecWithSingleResult = execWithSingleResult;}
118 bool execWithSingleResult() { return mExecWithSingleResult;}
119
124 void setExpressionContextScope( const QgsExpressionContextScope &scope );
125
130 QgsExpressionContextScope expressionContextScope() const;
131
138 void setShowFeatureActions( bool showFeatureActions ) { mShowFeatureActions = showFeatureActions; }
139 bool showFeatureActions() { return mShowFeatureActions;}
140
145 void setResultsIfExternalAction( bool resultsIfExternalAction ) {mResultsIfExternalAction = resultsIfExternalAction;}
146 bool resultsIfExternalAction() {return mResultsIfExternalAction;}
147
152 void setMaxLayerDisplay( int maxLayerDisplay );
153 int maxLayerDisplay() {return mMaxLayerDisplay;}
154
159 void setMaxFeatureDisplay( int maxFeatureDisplay );
160 int maxFeatureDisplay() {return mMaxFeatureDisplay;}
161
163 void addCustomAction( QgsMapLayerAction *action ) {mCustomActionRegistry.addMapLayerAction( action );}
164
166 void removeCustomActions();
167
173 QList<QgsMapToolIdentify::IdentifyResult> exec( const QList<QgsMapToolIdentify::IdentifyResult> &idResults, QPoint pos );
174
180 Q_DECL_DEPRECATED static void styleHighlight( QgsHighlight *highlight ) SIP_DEPRECATED;
181
182 protected:
183 void closeEvent( QCloseEvent *e ) override;
184
185 private slots:
186 void handleMenuHover();
187 void deleteRubberBands();
188 void layerDestroyed();
189 void triggerMapLayerAction();
190
191 private:
192
194 void addRasterLayer( QgsMapLayer *layer );
195
200 void addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapToolIdentify::IdentifyResult> &results, bool singleLayer = false );
201
203 QList<QgsMapToolIdentify::IdentifyResult> results( QAction *action, bool &externalAction );
204
205 QgsMapCanvas *mCanvas = nullptr;
206 QList<QgsHighlight *> mRubberBands;
207 bool mAllowMultipleReturn;
208 bool mExecWithSingleResult;
209 bool mShowFeatureActions;
210 bool mResultsIfExternalAction;
211 int mMaxLayerDisplay;
212 int mMaxFeatureDisplay;
213
214 QgsExpressionContextScope mExpressionContextScope;
215
216 // name of the action to be displayed for feature default action, if other actions are shown
217 QString mDefaultActionName;
218
219 // custom menu actions regirstry
220 CustomActionRegistry mCustomActionRegistry;
221
222 // map layers with their results, this is the odering of the menu
223 QMap <QgsMapLayer *, QList<QgsMapToolIdentify::IdentifyResult> > mLayerIdResults;
224};
225
227
228#endif // QGSIDENTIFYMENU_H
Single scope for storing variables and functions for use within a QgsExpressionContext.
A class for highlight features on the map.
The QgsIdentifyMenu class builds a menu to be used with identify results (.
void setAllowMultipleReturn(bool multipleReturn)
define if the menu executed can return multiple results (e.g. all results or all identified features ...
void setResultsIfExternalAction(bool resultsIfExternalAction)
setResultsIfExternalAction if set to false (default) the menu will not return any results if an exter...
void addCustomAction(QgsMapLayerAction *action)
adds a new custom action to the menu
void setShowFeatureActions(bool showFeatureActions)
define if attribute actions(1) and map layer actions(2) can be listed and run from the menu
void setExecWithSingleResult(bool execWithSingleResult)
define if the menu will be shown with a single identify result
bool resultsIfExternalAction()
Map canvas is a class for displaying all GIS data types on a canvas.
This class tracks map layer actions.
An action which can run on map layers The class can be used in two manners:
Base class for all map layer types.
Definition qgsmaplayer.h:76
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Represents a vector layer which manages a vector based data sets.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
ActionData(QgsMapLayer *layer, QgsMapLayerAction *mapLayerAction=nullptr)
ActionData(QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction=nullptr)