QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 {
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
125 void setExpressionContextScope( const QgsExpressionContextScope &scope );
126
132 QgsExpressionContextScope expressionContextScope() const;
133
140 void setShowFeatureActions( bool showFeatureActions ) { mShowFeatureActions = showFeatureActions; }
141 bool showFeatureActions() { return mShowFeatureActions;}
142
147 void setResultsIfExternalAction( bool resultsIfExternalAction ) {mResultsIfExternalAction = resultsIfExternalAction;}
148 bool resultsIfExternalAction() {return mResultsIfExternalAction;}
149
154 void setMaxLayerDisplay( int maxLayerDisplay );
155 int maxLayerDisplay() {return mMaxLayerDisplay;}
156
161 void setMaxFeatureDisplay( int maxFeatureDisplay );
162 int maxFeatureDisplay() {return mMaxFeatureDisplay;}
163
165 void addCustomAction( QgsMapLayerAction *action ) {mCustomActionRegistry.addMapLayerAction( action );}
166
168 void removeCustomActions();
169
175 QList<QgsMapToolIdentify::IdentifyResult> exec( const QList<QgsMapToolIdentify::IdentifyResult> &idResults, QPoint pos );
176
182 Q_DECL_DEPRECATED static void styleHighlight( QgsHighlight *highlight ) SIP_DEPRECATED;
183
184 protected:
185 void closeEvent( QCloseEvent *e ) override;
186
187 private slots:
188 void handleMenuHover();
189 void deleteRubberBands();
190 void layerDestroyed();
191 void triggerMapLayerAction();
192
193 private:
194
196 void addRasterLayer( QgsMapLayer *layer );
197
202 void addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapToolIdentify::IdentifyResult> &results, bool singleLayer = false );
203
205 QList<QgsMapToolIdentify::IdentifyResult> results( QAction *action, bool &externalAction );
206
207 QgsMapCanvas *mCanvas = nullptr;
208 QList<QgsHighlight *> mRubberBands;
209 bool mAllowMultipleReturn;
210 bool mExecWithSingleResult;
211 bool mShowFeatureActions;
212 bool mResultsIfExternalAction;
213 int mMaxLayerDisplay;
214 int mMaxFeatureDisplay;
215
216 QgsExpressionContextScope mExpressionContextScope;
217
218 // name of the action to be displayed for feature default action, if other actions are shown
219 QString mDefaultActionName;
220
221 // custom menu actions regirstry
222 CustomActionRegistry mCustomActionRegistry;
223
224 // map layers with their results, this is the odering of the menu
225 QMap <QgsMapLayer *, QList<QgsMapToolIdentify::IdentifyResult> > mLayerIdResults;
226};
227
229
230#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:74
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()=default
Constructor for ActionData.
ActionData(QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction=nullptr)