QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 Q_OBJECT
52
53 public:
55 {
57 FeatureLevel
58 };
59
61 {
62 ActionData() = default;
63
64 ActionData( QgsMapLayer *layer, QgsMapLayerAction *mapLayerAction = nullptr )
65 : mIsValid( true )
66 , mAllResults( !layer )
67 , mIsExternalAction( nullptr != mapLayerAction )
68 , mLayer( layer )
69 , mMapLayerAction( mapLayerAction )
70 {}
71
72 ActionData( QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction = nullptr )
73 : mIsValid( true )
74 , mIsExternalAction( nullptr != mapLayerAction )
75 , mLayer( layer )
76 , mFeatureId( fid )
77 , mLevel( FeatureLevel )
78 , mMapLayerAction( mapLayerAction )
79 {}
80
81 bool mIsValid = false;
82 bool mAllResults = false;
83 bool mIsExternalAction = false;
84 QgsMapLayer *mLayer = nullptr;
85 QgsFeatureId mFeatureId = 0;
86 QgsIdentifyMenu::MenuLevel mLevel = LayerLevel;
87 QgsMapLayerAction *mMapLayerAction = nullptr;
88 };
89
93 explicit QgsIdentifyMenu( QgsMapCanvas *canvas );
94
95 ~QgsIdentifyMenu() override;
96
97
108 static QList<QgsMapToolIdentify::IdentifyResult> findFeaturesOnCanvas( QgsMapMouseEvent *event, QgsMapCanvas *canvas, const QList<Qgis::GeometryType> &geometryTypes );
109
111 void setAllowMultipleReturn( bool multipleReturn ) { mAllowMultipleReturn = multipleReturn; }
112 bool allowMultipleReturn() { return mAllowMultipleReturn; }
113
115 void setExecWithSingleResult( bool execWithSingleResult ) { mExecWithSingleResult = execWithSingleResult; }
116 bool execWithSingleResult() { return mExecWithSingleResult; }
117
122 void setExpressionContextScope( const QgsExpressionContextScope &scope );
123
128 QgsExpressionContextScope expressionContextScope() const;
129
136 void setShowFeatureActions( bool showFeatureActions ) { mShowFeatureActions = showFeatureActions; }
137 bool showFeatureActions() { return mShowFeatureActions; }
138
143 void setResultsIfExternalAction( bool resultsIfExternalAction ) { mResultsIfExternalAction = resultsIfExternalAction; }
144 bool resultsIfExternalAction() { return mResultsIfExternalAction; }
145
150 void setMaxLayerDisplay( int maxLayerDisplay );
151 int maxLayerDisplay() { return mMaxLayerDisplay; }
152
157 void setMaxFeatureDisplay( int maxFeatureDisplay );
158 int maxFeatureDisplay() { return mMaxFeatureDisplay; }
159
161 void addCustomAction( QgsMapLayerAction *action ) { mCustomActionRegistry.addMapLayerAction( action ); }
162
164 void removeCustomActions();
165
171 QList<QgsMapToolIdentify::IdentifyResult> exec( const QList<QgsMapToolIdentify::IdentifyResult> &idResults, QPoint pos );
172
178 Q_DECL_DEPRECATED static void styleHighlight( QgsHighlight *highlight ) SIP_DEPRECATED;
179
180 protected:
181 void closeEvent( QCloseEvent *e ) override;
182
183 private slots:
184 void handleMenuHover();
185 void deleteRubberBands();
186 void layerDestroyed();
187 void triggerMapLayerAction();
188
189 private:
191 void addRasterLayer( QgsMapLayer *layer );
192
197 void addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapToolIdentify::IdentifyResult> &results, bool singleLayer = false );
198
200 QList<QgsMapToolIdentify::IdentifyResult> results( QAction *action, bool &externalAction );
201
202 QgsMapCanvas *mCanvas = nullptr;
203 QList<QgsHighlight *> mRubberBands;
204 bool mAllowMultipleReturn;
205 bool mExecWithSingleResult;
206 bool mShowFeatureActions;
207 bool mResultsIfExternalAction;
208 int mMaxLayerDisplay;
209 int mMaxFeatureDisplay;
210
211 QgsExpressionContextScope mExpressionContextScope;
212
213 // name of the action to be displayed for feature default action, if other actions are shown
214 QString mDefaultActionName;
215
216 // custom menu actions regirstry
217 CustomActionRegistry mCustomActionRegistry;
218
219 // map layers with their results, this is the odering of the menu
220 QMap<QgsMapLayer *, QList<QgsMapToolIdentify::IdentifyResult>> mLayerIdResults;
221};
222
224
225#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)