QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
21 #include "qgsactionmenu.h"
22 #include "qgsmapcanvas.h"
23 #include "qgsmaptoolidentify.h"
24 #include "qgsvectorlayer.h"
25 
27 class CustomActionRegistry : public QgsMapLayerActionRegistry
28 {
29  Q_OBJECT
30 
31  public:
32  explicit CustomActionRegistry( QObject *parent );
33  // remove all actions
34  void clear() { mMapLayerActionList.clear(); }
35 };
37 
44 class GUI_EXPORT QgsIdentifyMenu : public QMenu
45 {
46 
47  Q_OBJECT
48 
49  public:
50  enum MenuLevel
51  {
53  FeatureLevel
54  };
55 
56  struct ActionData
57  {
59  : mIsValid( false )
60  , mAllResults( false )
61  , mIsExternalAction( false )
62  , mLayer( nullptr )
63  , mFeatureId( 0 )
64  , mLevel( LayerLevel )
65  , mMapLayerAction( nullptr )
66  {}
67 
68  ActionData( QgsMapLayer* layer, QgsMapLayerAction* mapLayerAction = nullptr )
69  : mIsValid( true )
70  , mAllResults( !layer )
71  , mIsExternalAction( nullptr != mapLayerAction )
72  , mLayer( layer )
73  , mFeatureId( 0 )
74  , mLevel( LayerLevel )
75  , mMapLayerAction( mapLayerAction )
76  {}
77 
78  ActionData( QgsMapLayer* layer, QgsFeatureId fid, QgsMapLayerAction* mapLayerAction = nullptr )
79  : mIsValid( true )
80  , mAllResults( false )
81  , mIsExternalAction( nullptr != mapLayerAction )
82  , mLayer( layer )
83  , mFeatureId( fid )
84  , mLevel( FeatureLevel )
85  , mMapLayerAction( mapLayerAction )
86  {}
87 
88  bool mIsValid;
95  };
96 
100  explicit QgsIdentifyMenu( QgsMapCanvas* canvas );
101 
102  ~QgsIdentifyMenu();
103 
105  void setAllowMultipleReturn( bool multipleReturn ) { mAllowMultipleReturn = multipleReturn;}
106  bool allowMultipleReturn() { return mAllowMultipleReturn;}
107 
109  void setExecWithSingleResult( bool execWithSingleResult ) { mExecWithSingleResult = execWithSingleResult;}
110  bool execWithSingleResult() { return mExecWithSingleResult;}
111 
118  void setShowFeatureActions( bool showFeatureActions ) { mShowFeatureActions = showFeatureActions; }
119  bool showFeatureActions() { return mShowFeatureActions;}
120 
125  void setResultsIfExternalAction( bool resultsIfExternalAction ) {mResultsIfExternalAction = resultsIfExternalAction;}
126  bool resultsIfExternalAction() {return mResultsIfExternalAction;}
127 
130  void setMaxLayerDisplay( int maxLayerDisplay );
131  int maxLayerDisplay() {return mMaxLayerDisplay;}
132 
135  void setMaxFeatureDisplay( int maxFeatureDisplay );
136  int maxFeatureDisplay() {return mMaxFeatureDisplay;}
137 
139  void addCustomAction( QgsMapLayerAction* action ) {mCustomActionRegistry.addMapLayerAction( action );}
140 
142  void removeCustomActions();
143 
150 
156  void setExpressionContextScope( const QgsExpressionContextScope &scope );
157 
163  QgsExpressionContextScope expressionContextScope() const;
164 
165  protected:
166  virtual void closeEvent( QCloseEvent *e ) override;
167 
168  private slots:
169  void handleMenuHover();
170  void deleteRubberBands();
171  void layerDestroyed();
172  void triggerMapLayerAction();
173 
174  private:
175 
177  void addRasterLayer( QgsMapLayer* layer );
178 
181  void addVectorLayer( QgsVectorLayer* layer, const QList<QgsMapToolIdentify::IdentifyResult>& results, bool singleLayer = false );
182 
184  QList<QgsMapToolIdentify::IdentifyResult> results( QAction* action, bool& externalAction );
185 
186  QgsMapCanvas* mCanvas;
187  QList<QgsHighlight*> mRubberBands;
188  bool mAllowMultipleReturn;
189  bool mExecWithSingleResult;
190  bool mShowFeatureActions;
191  bool mResultsIfExternalAction;
192  int mMaxLayerDisplay;
193  int mMaxFeatureDisplay;
194 
195  QgsExpressionContextScope mExpressionContextScope;
196 
197  // name of the action to be displayed for feature default action, if other actions are shown
198  QString mDefaultActionName;
199 
200  // custom menu actions regirstry
201  CustomActionRegistry mCustomActionRegistry;
202 
203  // map layers with their results, this is the odering of the menu
205 };
206 
208 
209 #endif // QGSIDENTIFYMENU_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
ActionData(QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction=nullptr)
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
void setShowFeatureActions(bool showFeatureActions)
define if attribute actions(1) and map layer actions(2) can be listed and run from the menu ...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
bool resultsIfExternalAction()
void addCustomAction(QgsMapLayerAction *action)
adds a new custom action to the menu
QgsMapLayerAction * mMapLayerAction
bool execWithSingleResult()
void setResultsIfExternalAction(bool resultsIfExternalAction)
setResultsIfExternalAction if set to false (default) the menu will not return any results if an exter...
The QgsIdentifyMenu class builds a menu to be used with identify results (.
Single scope for storing variables and functions for use within a QgsExpressionContext.
This class tracks map layer actions.
void setExecWithSingleResult(bool execWithSingleResult)
define if the menu will be shown with a single idetify result
bool allowMultipleReturn()
void setAllowMultipleReturn(bool multipleReturn)
define if the menu executed can return multiple results (e.g. all results or all identified features ...
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Represents a vector layer which manages a vector based data sets.
An action which can run on map layers.
ActionData(QgsMapLayer *layer, QgsMapLayerAction *mapLayerAction=nullptr)