QGIS API Documentation  2.2.0-Valmiera
 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 
35  public:
37  QgsMapLayerAction( QString name, QObject *parent );
39  QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer );
41  QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType );
42 
44 
46  bool canRunUsingLayer( QgsMapLayer* layer ) const;
47 
50  void triggerForFeature( QgsMapLayer* layer, QgsFeature* feature );
51 
53  void triggerForLayer( QgsMapLayer* layer );
54 
55  signals:
57  void triggeredForFeature( QgsMapLayer* layer, QgsFeature* feature );
58 
60  void triggeredForLayer( QgsMapLayer* layer );
61 
62  private:
63 
64  //true if action is only valid for a single layer
66  //layer if action is only valid for a single layer
68 
69  //true if action is only valid for a specific layer type
71  //layer type if action is only valid for a specific layer type
73 
74 
75 };
76 
80 class GUI_EXPORT QgsMapLayerActionRegistry : public QObject
81 {
82  Q_OBJECT
83 
84  public:
86  static QgsMapLayerActionRegistry * instance();
87 
89 
91  void addMapLayerAction( QgsMapLayerAction * action );
92 
94  QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer* layer );
95 
97  bool removeMapLayerAction( QgsMapLayerAction *action );
98 
100  void setDefaultActionForLayer( QgsMapLayer* layer, QgsMapLayerAction* action );
102  QgsMapLayerAction * defaultActionForLayer( QgsMapLayer* layer );
103 
104  protected:
106  QgsMapLayerActionRegistry( QObject * parent = 0 );
107 
108  signals:
110  void changed();
111 
112  private:
113 
115 
116  QList< QgsMapLayerAction* > mMapLayerActionList;
117 
118  QMap< QgsMapLayer*, QgsMapLayerAction* > mDefaultLayerActionMap;
119 
120 };
121 
122 #endif // QGSMAPLAYERACTIONREGISTRY_H