QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmaplayeractionregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaplayeractionregistry.h
3  ---------------------------
4  begin : January 2014
5  copyright : (C) 2014 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
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 QGSMAPLAYERACTIONREGISTRY_H
17 #define QGSMAPLAYERACTIONREGISTRY_H
18 
19 #include <QObject>
20 #include <QList>
21 #include <QMap>
22 #include <QAction>
23 
24 #include "qgsmaplayer.h"
25 
26 class QgsFeature;
27 
31 class GUI_EXPORT QgsMapLayerAction : public QAction
32 {
33  Q_OBJECT
34  Q_FLAGS( Availability )
35 
36  public:
38  {
39  Layer = 1,
40  Feature = 2,
41  LayerAndFeature = Layer | Feature
42  };
43  Q_DECLARE_FLAGS( Availability, AvailabityFlag )
44 
45 
46  QgsMapLayerAction( QString name, QObject *parent, Availability availability = LayerAndFeature );
48  QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Availability availability = LayerAndFeature );
50  QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Availability availability = LayerAndFeature );
51 
53 
55  bool canRunUsingLayer( QgsMapLayer* layer ) const;
56 
59  void triggerForFeature( QgsMapLayer* layer, QgsFeature* feature );
60 
62  void triggerForLayer( QgsMapLayer* layer );
63 
65  void setAvailability( Availability availability ) {mAvailability = availability;}
67  Availability availability() const {return mAvailability;}
68 
69  signals:
71  void triggeredForFeature( QgsMapLayer* layer, QgsFeature* feature );
72 
74  void triggeredForLayer( QgsMapLayer* layer );
75 
76  private:
77 
78  //true if action is only valid for a single layer
80  //layer if action is only valid for a single layer
82 
83  //true if action is only valid for a specific layer type
85  //layer type if action is only valid for a specific layer type
87 
88  // determine if the action can be run on feature and/or layer
89  Availability mAvailability;
90 };
91 
92 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerAction::Availability )
93 
94 
97 class GUI_EXPORT QgsMapLayerActionRegistry : public QObject
98 {
99  Q_OBJECT
100 
101  public:
103  static QgsMapLayerActionRegistry * instance();
104 
106 
108  void addMapLayerAction( QgsMapLayerAction * action );
109 
111  QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer* layer );
112 
114  bool removeMapLayerAction( QgsMapLayerAction *action );
115 
117  void setDefaultActionForLayer( QgsMapLayer* layer, QgsMapLayerAction* action );
119  QgsMapLayerAction * defaultActionForLayer( QgsMapLayer* layer );
120 
121  protected:
123  QgsMapLayerActionRegistry( QObject * parent = 0 );
124 
125  signals:
127  void changed();
128 
129  private:
130 
132 
133  QList< QgsMapLayerAction* > mMapLayerActionList;
134 
135  QMap< QgsMapLayer*, QgsMapLayerAction* > mDefaultLayerActionMap;
136 
137 };
138 
139 #endif // QGSMAPLAYERACTIONREGISTRY_H