@@ -46,29 +46,42 @@ class GUI_EXPORT QgsMapLayerAction : public QAction
46
46
Q_DECLARE_FLAGS ( Targets, Target )
47
47
Q_FLAG ( Targets )
48
48
49
+ /* *
50
+ * Flags which control action behavior
51
+ * /since QGIS 3.0
52
+ */
53
+ enum Flag
54
+ {
55
+ EnabledOnlyWhenEditable = 1 << 1 , // !< Action should be shown only for editable layers
56
+ };
57
+
58
+ /* *
59
+ * Action behavior flags.
60
+ * \since QGIS 3.0
61
+ */
62
+ Q_DECLARE_FLAGS ( Flags, Flag )
63
+ Q_FLAG ( Flags )
64
+
49
65
/* *
50
66
* Creates a map layer action which can run on any layer
51
67
* \note using AllActions as a target probably does not make a lot of sense. This default action was settled for API compatibility reasons.
52
68
*/
53
- #ifndef SIP_RUN
54
- QgsMapLayerAction ( const QString &name, QObject *parent SIP_TRANSFERTHIS, Targets targets = AllActions, const QIcon &icon = QIcon(), const bool enabledOnlyWhenEditable = false );
55
- #else
56
- QgsMapLayerAction ( const QString &name, QObject *parent SIP_TRANSFERTHIS, Targets targets = AllActions, const QIcon &icon = QIcon() );
57
- #endif
69
+ QgsMapLayerAction ( const QString &name, QObject *parent SIP_TRANSFERTHIS, Targets targets = AllActions, const QIcon &icon = QIcon(), QgsMapLayerAction::Flags flags = nullptr );
70
+
58
71
// ! Creates a map layer action which can run only on a specific layer
59
- #ifndef SIP_RUN
60
- QgsMapLayerAction ( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer *layer, Targets targets = AllActions, const QIcon &icon = QIcon(), const bool enabledOnlyWhenEditable = false );
61
- #else
62
- QgsMapLayerAction ( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer *layer, Targets targets = AllActions, const QIcon &icon = QIcon() );
63
- #endif
72
+ QgsMapLayerAction ( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer *layer, Targets targets = AllActions, const QIcon &icon = QIcon(), QgsMapLayerAction::Flags flags = nullptr );
73
+
64
74
// ! Creates a map layer action which can run on a specific type of layer
65
- #ifndef SIP_RUN
66
- QgsMapLayerAction ( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer::LayerType layerType, Targets targets = AllActions, const QIcon &icon = QIcon(), const bool enabledOnlyWhenEditable = false );
67
- #else
68
- QgsMapLayerAction ( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer::LayerType layerType, Targets targets = AllActions, const QIcon &icon = QIcon() );
69
- #endif
75
+ QgsMapLayerAction ( const QString &name, QObject *parent SIP_TRANSFERTHIS, QgsMapLayer::LayerType layerType, Targets targets = AllActions, const QIcon &icon = QIcon(), QgsMapLayerAction::Flags flags = nullptr );
76
+
70
77
~QgsMapLayerAction () override ;
71
78
79
+ /* *
80
+ * Layer behavior flags.
81
+ * \since QGIS 3.0
82
+ */
83
+ QgsMapLayerAction::Flags flags () const ;
84
+
72
85
// ! True if action can run using the specified layer
73
86
bool canRunUsingLayer ( QgsMapLayer *layer ) const ;
74
87
@@ -86,8 +99,11 @@ class GUI_EXPORT QgsMapLayerAction : public QAction
86
99
// ! Return availibity of action
87
100
const Targets &targets () const {return mTargets ;}
88
101
89
- // ! Return whether only enabled in editable mode
90
- bool isEnabledOnlyWhenEditable () const { return mEnabledOnlyWhenEditable ; }
102
+ /* *
103
+ * Returns true if the action is only enabled for layers in editable mode.
104
+ * \since QGIS 3.0
105
+ */
106
+ bool isEnabledOnlyWhenEditable () const ;
91
107
92
108
signals:
93
109
// ! Triggered when action has been run for a specific list of features
@@ -102,19 +118,19 @@ class GUI_EXPORT QgsMapLayerAction : public QAction
102
118
private:
103
119
104
120
// true if action is only valid for a single layer
105
- bool mSingleLayer ;
121
+ bool mSingleLayer = false ;
106
122
// layer if action is only valid for a single layer
107
123
QgsMapLayer *mActionLayer = nullptr ;
108
124
109
125
// true if action is only valid for a specific layer type
110
- bool mSpecificLayerType ;
126
+ bool mSpecificLayerType = false ;
111
127
// layer type if action is only valid for a specific layer type
112
- QgsMapLayer::LayerType mLayerType ;
128
+ QgsMapLayer::LayerType mLayerType = QgsMapLayer::VectorLayer ;
113
129
114
130
// determine if the action can be run on layer and/or single feature and/or multiple features
115
- Targets mTargets ;
131
+ Targets mTargets = nullptr ;
116
132
117
- bool mEnabledOnlyWhenEditable ;
133
+ QgsMapLayerAction::Flags mFlags = nullptr ;
118
134
};
119
135
120
136
Q_DECLARE_OPERATORS_FOR_FLAGS ( QgsMapLayerAction::Targets )
@@ -168,4 +184,6 @@ class GUI_EXPORT QgsMapLayerActionRegistry : public QObject
168
184
169
185
};
170
186
187
+ Q_DECLARE_OPERATORS_FOR_FLAGS ( QgsMapLayerAction::Flags )
188
+
171
189
#endif // QGSMAPLAYERACTIONREGISTRY_H
0 commit comments