QGIS API Documentation  2.14.0-Essen
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 
151  protected:
152  virtual void closeEvent( QCloseEvent *e ) override;
153 
154  private slots:
155  void handleMenuHover();
156  void deleteRubberBands();
157  void layerDestroyed();
158  void triggerMapLayerAction();
159 
160  private:
161 
163  void addRasterLayer( QgsMapLayer* layer );
164 
167  void addVectorLayer( QgsVectorLayer* layer, const QList<QgsMapToolIdentify::IdentifyResult>& results, bool singleLayer = false );
168 
170  QList<QgsMapToolIdentify::IdentifyResult> results( QAction* action, bool& externalAction );
171 
172  QgsMapCanvas* mCanvas;
173  QList<QgsHighlight*> mRubberBands;
174  bool mAllowMultipleReturn;
175  bool mExecWithSingleResult;
176  bool mShowFeatureActions;
177  bool mResultsIfExternalAction;
178  int mMaxLayerDisplay;
179  int mMaxFeatureDisplay;
180 
181  // name of the action to be displayed for feature default action, if other actions are shown
182  QString mDefaultActionName;
183 
184  // custom menu actions regirstry
185  CustomActionRegistry mCustomActionRegistry;
186 
187  // map layers with their results, this is the odering of the menu
189 };
190 
191 Q_DECLARE_METATYPE( QgsIdentifyMenu::ActionData )
192 
193 #endif // QGSIDENTIFYMENU_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
ActionData(QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction=nullptr)
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:105
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 (.
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)