QGIS API Documentation  2.12.0-Lyon
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 
32 class GUI_EXPORT QgsIdentifyMenu : public QMenu
33 {
34 
35  Q_OBJECT
36 
37  public:
38  enum MenuLevel
39  {
41  FeatureLevel
42  };
43 
44  struct ActionData
45  {
47  : mIsValid( false )
48  , mAllResults( false )
49  , mIsExternalAction( false )
50  , mLayer( NULL )
51  , mFeatureId( 0 )
52  , mLevel( LayerLevel )
53  , mMapLayerAction( NULL )
54  {}
55 
56  ActionData( QgsMapLayer* layer, QgsMapLayerAction* mapLayerAction = 0 )
57  : mIsValid( true )
58  , mAllResults( layer == 0 )
59  , mIsExternalAction( mapLayerAction != 0 )
60  , mLayer( layer )
61  , mFeatureId( 0 )
62  , mLevel( LayerLevel )
63  , mMapLayerAction( mapLayerAction )
64  {}
65 
66  ActionData( QgsMapLayer* layer, QgsFeatureId fid, QgsMapLayerAction* mapLayerAction = 0 )
67  : mIsValid( true )
68  , mAllResults( false )
69  , mIsExternalAction( mapLayerAction != 0 )
70  , mLayer( layer )
71  , mFeatureId( fid )
72  , mLevel( FeatureLevel )
73  , mMapLayerAction( mapLayerAction )
74  {}
75 
76  bool mIsValid;
83  };
84 
88  explicit QgsIdentifyMenu( QgsMapCanvas* canvas );
89 
90  ~QgsIdentifyMenu();
91 
93  void setAllowMultipleReturn( bool multipleReturn ) { mAllowMultipleReturn = multipleReturn;}
94  bool allowMultipleReturn() { return mAllowMultipleReturn;}
95 
97  void setExecWithSingleResult( bool execWithSingleResult ) { mExecWithSingleResult = execWithSingleResult;}
98  bool execWithSingleResult() { return mExecWithSingleResult;}
99 
106  void setShowFeatureActions( bool showFeatureActions ) { mShowFeatureActions = showFeatureActions; }
107  bool showFeatureActions() { return mShowFeatureActions;}
108 
113  void setResultsIfExternalAction( bool resultsIfExternalAction ) {mResultsIfExternalAction = resultsIfExternalAction;}
114  bool resultsIfExternalAction() {return mResultsIfExternalAction;}
115 
118  void setMaxLayerDisplay( int maxLayerDisplay );
119  int maxLayerDisplay() {return mMaxLayerDisplay;}
120 
123  void setMaxFeatureDisplay( int maxFeatureDisplay );
124  int maxFeatureDisplay() {return mMaxFeatureDisplay;}
125 
127  void addCustomAction( QgsMapLayerAction* action ) {mCustomActionRegistry.addMapLayerAction( action );}
128 
130  void removeCustomActions();
131 
138 
139  protected:
140  virtual void closeEvent( QCloseEvent *e ) override;
141 
142  private slots:
143  void handleMenuHover();
144  void deleteRubberBands();
145  void layerDestroyed();
146  void triggerMapLayerAction();
147 
148  private:
149  class CustomActionRegistry : public QgsMapLayerActionRegistry
150  {
151  public:
152  explicit CustomActionRegistry( QObject *parent );
153  // remove all actions
154  void clear() {mMapLayerActionList.clear();}
155  };
156 
158  void addRasterLayer( QgsMapLayer* layer );
159 
162  void addVectorLayer( QgsVectorLayer* layer, const QList<QgsMapToolIdentify::IdentifyResult>& results, bool singleLayer = false );
163 
165  QList<QgsMapToolIdentify::IdentifyResult> results( QAction* action, bool& externalAction );
166 
167  QgsMapCanvas* mCanvas;
168  QList<QgsHighlight*> mRubberBands;
169  bool mAllowMultipleReturn;
170  bool mExecWithSingleResult;
171  bool mShowFeatureActions;
172  bool mResultsIfExternalAction;
173  int mMaxLayerDisplay;
174  int mMaxFeatureDisplay;
175 
176  // name of the action to be displayed for feature default action, if other actions are shown
177  QString mDefaultActionName;
178 
179  // custom menu actions regirstry
180  CustomActionRegistry mCustomActionRegistry;
181 
182  // map layers with their results, this is the odering of the menu
184 };
185 
187 
188 #endif // QGSIDENTIFYMENU_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
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:107
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.
QAction * exec()
void setExecWithSingleResult(bool execWithSingleResult)
define if the menu will be shown with a single idetify result
ActionData(QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction=0)
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
ActionData(QgsMapLayer *layer, QgsMapLayerAction *mapLayerAction=0)
virtual void closeEvent(QCloseEvent *event)
Q_NOWARN_DEPRECATED_POP Q_DECLARE_METATYPE(QgsExpression::Interval)
Represents a vector layer which manages a vector based data sets.
An action which can run on map layers.