QGIS API Documentation  2.99.0-Master (0a63d1f)
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 #include "qgis_gui.h"
26 
27 class QgsFeature;
28 
32 class GUI_EXPORT QgsMapLayerAction : public QAction
33 {
34  Q_OBJECT
35  Q_FLAGS( Availability )
36 
37  public:
38  enum Target
39  {
40  Layer = 1,
41  SingleFeature = 2,
42  MultipleFeatures = 4,
43  AllActions = Layer | SingleFeature | MultipleFeatures
44  };
45  Q_DECLARE_FLAGS( Targets, Target )
46 
47 
48  QgsMapLayerAction( const QString& name, QObject *parent, Targets targets = AllActions, const QIcon& icon = QIcon() );
50 
52  QgsMapLayerAction( const QString& name, QObject *parent, QgsMapLayer* layer, Targets targets = AllActions, const QIcon& icon = QIcon() );
53 
55  QgsMapLayerAction( const QString& name, QObject *parent, QgsMapLayer::LayerType layerType, Targets targets = AllActions, const QIcon& icon = QIcon() );
56 
58 
60  bool canRunUsingLayer( QgsMapLayer* layer ) const;
61 
63  void triggerForFeatures( QgsMapLayer* layer, const QList<QgsFeature>& featureList );
64 
66  void triggerForFeature( QgsMapLayer* layer, const QgsFeature* feature );
67 
69  void triggerForLayer( QgsMapLayer* layer );
70 
72  void setTargets( Targets targets ) {mTargets = targets;}
74  const Targets& targets() const {return mTargets;}
75 
76  signals:
78  void triggeredForFeatures( QgsMapLayer* layer, const QList<QgsFeature>& featureList );
79 
81  void triggeredForFeature( QgsMapLayer* layer, const QgsFeature& feature );
82 
84  void triggeredForLayer( QgsMapLayer* layer );
85 
86  private:
87 
88  // true if action is only valid for a single layer
89  bool mSingleLayer;
90  // layer if action is only valid for a single layer
91  QgsMapLayer* mActionLayer;
92 
93  // true if action is only valid for a specific layer type
94  bool mSpecificLayerType;
95  // layer type if action is only valid for a specific layer type
96  QgsMapLayer::LayerType mLayerType;
97 
98  // determine if the action can be run on layer and/or single feature and/or multiple features
99  Targets mTargets;
100 };
101 
102 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerAction::Targets )
103 
104 
107 class GUI_EXPORT QgsMapLayerActionRegistry : public QObject
108 {
109  Q_OBJECT
110 
111  public:
113  static QgsMapLayerActionRegistry * instance();
114 
116  void addMapLayerAction( QgsMapLayerAction * action );
117 
119  QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer* layer, QgsMapLayerAction::Targets targets = QgsMapLayerAction::AllActions );
120 
122  bool removeMapLayerAction( QgsMapLayerAction *action );
123 
125  void setDefaultActionForLayer( QgsMapLayer* layer, QgsMapLayerAction* action );
127  QgsMapLayerAction * defaultActionForLayer( QgsMapLayer* layer );
128 
129  protected:
131  QgsMapLayerActionRegistry( QObject * parent = nullptr );
132 
133  QList< QgsMapLayerAction* > mMapLayerActionList;
134 
135  signals:
137  void changed();
138 
139  private:
140 
141  static QgsMapLayerActionRegistry *sInstance;
142 
143  QMap< QgsMapLayer*, QgsMapLayerAction* > mDefaultLayerActionMap;
144 
145 };
146 
147 #endif // QGSMAPLAYERACTIONREGISTRY_H
void setTargets(Targets targets)
Define the targets of the action.
Base class for all map layer types.
Definition: qgsmaplayer.h:50
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:136
LayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:59
QList< QgsMapLayerAction *> mMapLayerActionList
This class tracks map layer actions.
const Targets & targets() const
Return availibity of action.
An action which can run on map layers.