QGIS API Documentation  2.99.0-Master (53aba61)
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 "qgis.h"
21 #include <QList>
22 #include <QMap>
23 #include <QAction>
24 
25 #include "qgsmaplayer.h"
26 #include "qgis_gui.h"
27 
28 class QgsFeature;
29 
33 class GUI_EXPORT QgsMapLayerAction : public QAction
34 {
35  Q_OBJECT
36  Q_FLAGS( Availability )
37 
38  public:
39  enum Target
40  {
41  Layer = 1,
42  SingleFeature = 2,
43  MultipleFeatures = 4,
44  AllActions = Layer | SingleFeature | MultipleFeatures
45  };
46  Q_DECLARE_FLAGS( Targets, Target )
47 
48 
49  QgsMapLayerAction( const QString &name, QObject *parent SIP_TRANSFERTHIS, Targets targets = AllActions, const QIcon &icon = QIcon() );
51 
53  QgsMapLayerAction( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer *layer, Targets targets = AllActions, const QIcon &icon = QIcon() );
54 
56  QgsMapLayerAction( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer::LayerType layerType, Targets targets = AllActions, const QIcon &icon = QIcon() );
57 
59 
61  bool canRunUsingLayer( QgsMapLayer *layer ) const;
62 
64  void triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList );
65 
67  void triggerForFeature( QgsMapLayer *layer, const QgsFeature *feature );
68 
70  void triggerForLayer( QgsMapLayer *layer );
71 
73  void setTargets( Targets targets ) {mTargets = targets;}
75  const Targets &targets() const {return mTargets;}
76 
77  signals:
79  void triggeredForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList );
80 
82  void triggeredForFeature( QgsMapLayer *layer, const QgsFeature &feature );
83 
85  void triggeredForLayer( QgsMapLayer *layer );
86 
87  private:
88 
89  // true if action is only valid for a single layer
90  bool mSingleLayer;
91  // layer if action is only valid for a single layer
92  QgsMapLayer *mActionLayer = nullptr;
93 
94  // true if action is only valid for a specific layer type
95  bool mSpecificLayerType;
96  // layer type if action is only valid for a specific layer type
97  QgsMapLayer::LayerType mLayerType;
98 
99  // determine if the action can be run on layer and/or single feature and/or multiple features
100  Targets mTargets;
101 };
102 
103 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerAction::Targets )
104 
105 
111 class GUI_EXPORT QgsMapLayerActionRegistry : public QObject
112 {
113  Q_OBJECT
114 
115  public:
116 
123  QgsMapLayerActionRegistry( QObject *parent = nullptr );
124 
126  void addMapLayerAction( QgsMapLayerAction *action );
127 
129  QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer *layer, QgsMapLayerAction::Targets targets = QgsMapLayerAction::AllActions );
130 
132  bool removeMapLayerAction( QgsMapLayerAction *action );
133 
135  void setDefaultActionForLayer( QgsMapLayer *layer, QgsMapLayerAction *action );
137  QgsMapLayerAction *defaultActionForLayer( QgsMapLayer *layer );
138 
139  protected:
140 
141  QList< QgsMapLayerAction * > mMapLayerActionList;
142 
143  signals:
145  void changed();
146 
147  private:
148 
149  QMap< QgsMapLayer *, QgsMapLayerAction * > mDefaultLayerActionMap;
150 
151 };
152 
153 #endif // QGSMAPLAYERACTIONREGISTRY_H
void setTargets(Targets targets)
Define the targets of the action.
Base class for all map layer types.
Definition: qgsmaplayer.h:54
QList< QgsMapLayerAction *> mMapLayerActionList
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:61
LayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:92
This class tracks map layer actions.
const Targets & targets() const
Return availibity of action.
An action which can run on map layers.