QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  {}
49 
50  ActionData( QgsMapLayer* layer, QgsMapLayerAction* mapLayerAction = 0 )
51  : mIsValid( true )
52  , mAllResults( layer == 0 )
53  , mIsExternalAction( mapLayerAction != 0 )
54  , mLayer( layer )
55  , mLevel( LayerLevel )
56  , mMapLayerAction( mapLayerAction )
57  {}
58 
59  ActionData( QgsMapLayer* layer, QgsFeatureId fid, QgsMapLayerAction* mapLayerAction = 0 )
60  : mIsValid( true )
61  , mAllResults( false )
62  , mIsExternalAction( mapLayerAction != 0 )
63  , mLayer( layer )
64  , mFeatureId( fid )
65  , mLevel( FeatureLevel )
66  , mMapLayerAction( mapLayerAction )
67  {}
68 
69  bool mIsValid;
76  };
77 
81  explicit QgsIdentifyMenu( QgsMapCanvas* canvas );
82 
83  ~QgsIdentifyMenu();
84 
86  void setAllowMultipleReturn( bool multipleReturn ) { mAllowMultipleReturn = multipleReturn;}
87  bool allowMultipleReturn() { return mAllowMultipleReturn;}
88 
90  void setExecWithSingleResult( bool execWithSingleResult ) { mExecWithSingleResult = execWithSingleResult;}
91  bool execWithSingleResult() { return mExecWithSingleResult;}
92 
99  void setShowFeatureActions( bool showFeatureActions ) { mShowFeatureActions = showFeatureActions; }
100  bool showFeatureActions() { return mShowFeatureActions;}
101 
106  void setResultsIfExternalAction( bool resultsIfExternalAction ) {mResultsIfExternalAction = resultsIfExternalAction;}
107  bool resultsIfExternalAction() {return mResultsIfExternalAction;}
108 
111  void setMaxLayerDisplay( int maxLayerDisplay );
112  int maxLayerDisplay() {return mMaxLayerDisplay;}
113 
116  void setMaxFeatureDisplay( int maxFeatureDisplay );
117  int maxFeatureDisplay() {return mMaxFeatureDisplay;}
118 
120  void addCustomAction( QgsMapLayerAction* action ) {mCustomActionRegistry.addMapLayerAction( action );}
121 
123  void removeCustomActions();
124 
130  QList<QgsMapToolIdentify::IdentifyResult> exec( const QList<QgsMapToolIdentify::IdentifyResult> idResults, QPoint pos );
131 
132  protected:
133  virtual void closeEvent( QCloseEvent *e );
134 
135  private slots:
136  void handleMenuHover();
137  void deleteRubberBands();
138  void layerDestroyed();
139  void triggerMapLayerAction();
140 
141  private:
142  class CustomActionRegistry : public QgsMapLayerActionRegistry
143  {
144  public:
145  explicit CustomActionRegistry( QObject *parent );
146  // remove all actions
147  void clear() {mMapLayerActionList.clear();}
148  };
149 
151  void addRasterLayer( QgsMapLayer* layer );
152 
155  void addVectorLayer( QgsVectorLayer* layer, const QList<QgsMapToolIdentify::IdentifyResult> results, bool singleLayer = false );
156 
158  QList<QgsMapToolIdentify::IdentifyResult> results( QAction* action, bool& externalAction );
159 
160  QgsMapCanvas* mCanvas;
161  QList<QgsHighlight*> mRubberBands;
162  bool mAllowMultipleReturn;
163  bool mExecWithSingleResult;
164  bool mShowFeatureActions;
165  bool mResultsIfExternalAction;
166  int mMaxLayerDisplay;
167  int mMaxFeatureDisplay;
168 
169  // name of the action to be displayed for feature default action, if other actions are shown
170  QString mDefaultActionName;
171 
172  // custom menu actions regirstry
173  CustomActionRegistry mCustomActionRegistry;
174 
175  // map layers with their results, this is the odering of the menu
176  QMap <QgsMapLayer*, QList<QgsMapToolIdentify::IdentifyResult> > mLayerIdResults;
177 };
178 
180 
181 #endif // QGSIDENTIFYMENU_H