QGIS API Documentation 3.43.0-Master (c67cf405802)
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
6 email : denis.rouzaud@gmail.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 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
52class GUI_EXPORT QgsIdentifyMenu : public QMenu
53{
54 Q_OBJECT
55
56 public:
58 {
60 FeatureLevel
61 };
62
64 {
65 ActionData() = default;
66
67 ActionData( QgsMapLayer *layer, QgsMapLayerAction *mapLayerAction = nullptr )
68 : mIsValid( true )
69 , mAllResults( !layer )
70 , mIsExternalAction( nullptr != mapLayerAction )
71 , mLayer( layer )
72 , mMapLayerAction( mapLayerAction )
73 {}
74
75 ActionData( QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction = nullptr )
76 : mIsValid( true )
77 , mIsExternalAction( nullptr != mapLayerAction )
78 , mLayer( layer )
79 , mFeatureId( fid )
80 , mLevel( FeatureLevel )
81 , mMapLayerAction( mapLayerAction )
82 {}
83
84 bool mIsValid = false;
85 bool mAllResults = false;
86 bool mIsExternalAction = false;
87 QgsMapLayer *mLayer = nullptr;
88 QgsFeatureId mFeatureId = 0;
89 QgsIdentifyMenu::MenuLevel mLevel = LayerLevel;
90 QgsMapLayerAction *mMapLayerAction = nullptr;
91 };
92
96 explicit QgsIdentifyMenu( QgsMapCanvas *canvas );
97
98 ~QgsIdentifyMenu() override;
99
100
111 static QList<QgsMapToolIdentify::IdentifyResult> findFeaturesOnCanvas( QgsMapMouseEvent *event, QgsMapCanvas *canvas, const QList<Qgis::GeometryType> &geometryTypes );
112
114 void setAllowMultipleReturn( bool multipleReturn ) { mAllowMultipleReturn = multipleReturn; }
115 bool allowMultipleReturn() { return mAllowMultipleReturn; }
116
118 void setExecWithSingleResult( bool execWithSingleResult ) { mExecWithSingleResult = execWithSingleResult; }
119 bool execWithSingleResult() { return mExecWithSingleResult; }
120
125 void setExpressionContextScope( const QgsExpressionContextScope &scope );
126
131 QgsExpressionContextScope expressionContextScope() const;
132
139 void setShowFeatureActions( bool showFeatureActions ) { mShowFeatureActions = showFeatureActions; }
140 bool showFeatureActions() { return mShowFeatureActions; }
141
146 void setResultsIfExternalAction( bool resultsIfExternalAction ) { mResultsIfExternalAction = resultsIfExternalAction; }
147 bool resultsIfExternalAction() { return mResultsIfExternalAction; }
148
153 void setMaxLayerDisplay( int maxLayerDisplay );
154 int maxLayerDisplay() { return mMaxLayerDisplay; }
155
160 void setMaxFeatureDisplay( int maxFeatureDisplay );
161 int maxFeatureDisplay() { return mMaxFeatureDisplay; }
162
164 void addCustomAction( QgsMapLayerAction *action ) { mCustomActionRegistry.addMapLayerAction( action ); }
165
167 void removeCustomActions();
168
174 QList<QgsMapToolIdentify::IdentifyResult> exec( const QList<QgsMapToolIdentify::IdentifyResult> &idResults, QPoint pos );
175
181 Q_DECL_DEPRECATED static void styleHighlight( QgsHighlight *highlight ) SIP_DEPRECATED;
182
183 protected:
184 void closeEvent( QCloseEvent *e ) override;
185
186 private slots:
187 void handleMenuHover();
188 void deleteRubberBands();
189 void layerDestroyed();
190 void triggerMapLayerAction();
191
192 private:
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.
Highlights features on the map.
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.
A registry which tracks map layer actions.
An action which can run on map layers.
Base class for all map layer types.
Definition qgsmaplayer.h:77
A mouse event which is the result of a user interaction with a QgsMapCanvas.
Represents a vector layer which manages a vector based dataset.
#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)