QGIS API Documentation  2.99.0-Master (9fdd060)
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 
34 class GUI_EXPORT QgsMapLayerAction : public QAction
35 {
36  Q_OBJECT
37  Q_FLAGS( Availability )
38 
39  public:
40  enum Target
41  {
42  Layer = 1,
43  SingleFeature = 2,
44  MultipleFeatures = 4,
45  AllActions = Layer | SingleFeature | MultipleFeatures
46  };
47  Q_DECLARE_FLAGS( Targets, Target )
48 
49 
53  QgsMapLayerAction( const QString &name, QObject *parent SIP_TRANSFERTHIS, Targets targets = AllActions, const QIcon &icon = QIcon() );
54 
56  QgsMapLayerAction( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer *layer, Targets targets = AllActions, const QIcon &icon = QIcon() );
57 
59  QgsMapLayerAction( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer::LayerType layerType, Targets targets = AllActions, const QIcon &icon = QIcon() );
60 
62 
64  bool canRunUsingLayer( QgsMapLayer *layer ) const;
65 
67  void triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList );
68 
70  void triggerForFeature( QgsMapLayer *layer, const QgsFeature *feature );
71 
73  void triggerForLayer( QgsMapLayer *layer );
74 
76  void setTargets( Targets targets ) {mTargets = targets;}
78  const Targets &targets() const {return mTargets;}
79 
80  signals:
82  void triggeredForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList );
83 
85  void triggeredForFeature( QgsMapLayer *layer, const QgsFeature &feature );
86 
88  void triggeredForLayer( QgsMapLayer *layer );
89 
90  private:
91 
92  // true if action is only valid for a single layer
93  bool mSingleLayer;
94  // layer if action is only valid for a single layer
95  QgsMapLayer *mActionLayer = nullptr;
96 
97  // true if action is only valid for a specific layer type
98  bool mSpecificLayerType;
99  // layer type if action is only valid for a specific layer type
100  QgsMapLayer::LayerType mLayerType;
101 
102  // determine if the action can be run on layer and/or single feature and/or multiple features
103  Targets mTargets;
104 };
105 
106 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerAction::Targets )
107 
108 
115 class GUI_EXPORT QgsMapLayerActionRegistry : public QObject
116 {
117  Q_OBJECT
118 
119  public:
120 
127  QgsMapLayerActionRegistry( QObject *parent = nullptr );
128 
130  void addMapLayerAction( QgsMapLayerAction *action );
131 
133  QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer *layer, QgsMapLayerAction::Targets targets = QgsMapLayerAction::AllActions );
134 
136  bool removeMapLayerAction( QgsMapLayerAction *action );
137 
139  void setDefaultActionForLayer( QgsMapLayer *layer, QgsMapLayerAction *action );
141  QgsMapLayerAction *defaultActionForLayer( QgsMapLayer *layer );
142 
143  protected:
144 
145  QList< QgsMapLayerAction * > mMapLayerActionList;
146 
147  signals:
149  void changed();
150 
151  private:
152 
153  QMap< QgsMapLayer *, QgsMapLayerAction * > mDefaultLayerActionMap;
154 
155 };
156 
157 #endif // QGSMAPLAYERACTIONREGISTRY_H
void setTargets(Targets targets)
Define the targets of the action.
Base class for all map layer types.
Definition: qgsmaplayer.h:56
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:62
LayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:94
This class tracks map layer actions.
const Targets & targets() const
Return availibity of action.
An action which can run on map layers.