QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 : [email protected]
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"
23 #include "qgsexpressioncontext.h"
24 #include "qgis_gui.h"
25 #include "qgis_sip.h"
26 
27 #ifndef SIP_RUN
28 class CustomActionRegistry : public QgsMapLayerActionRegistry
30 {
31  Q_OBJECT
32 
33  public:
34 
35  CustomActionRegistry() = default;
36  // remove all actions
37  void clear() { mMapLayerActionList.clear(); }
38 };
40 #endif
41 
49 class GUI_EXPORT QgsIdentifyMenu : public QMenu
50 {
51 
52  Q_OBJECT
53 
54  public:
55  enum MenuLevel
56  {
57  LayerLevel,
58  FeatureLevel
59  };
60 
61  struct ActionData
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<QgsWkbTypes::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  static void styleHighlight( QgsHighlight *highlight );
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
qgsmaptoolidentify.h
QgsMapLayerAction
An action which can run on map layers The class can be used in two manners:
Definition: qgsmaplayeractionregistry.h:38
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsHighlight
A class for highlight features on the map.
Definition: qgshighlight.h:61
qgsexpressioncontext.h
QgsMapLayerActionRegistry
This class tracks map layer actions.
Definition: qgsmaplayeractionregistry.h:149
qgis_sip.h
QgsIdentifyMenu::MenuLevel
MenuLevel
Definition: qgsidentifymenu.h:68
qgsmaplayeractionregistry.h
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsMapMouseEvent
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas....
Definition: qgsmapmouseevent.h:35
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QgsIdentifyMenu::ActionData
Definition: qgsidentifymenu.h:74
QgsIdentifyMenu
The QgsIdentifyMenu class builds a menu to be used with identify results (.
Definition: qgsidentifymenu.h:49
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28