QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsmaplayeraction.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayeraction.cpp
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#include "qgsmaplayeraction.h"
17
18#include "qgsgui.h"
19#include "qgsmaplayer.h"
22#include "qgsvectorlayer.h"
23
24#include "moc_qgsmaplayeraction.cpp"
25
27 : QAction( icon, name, parent )
28 , mTargets( targets )
29 , mFlags( flags )
30{
31}
32
34 : QAction( icon, name, parent )
35 , mSingleLayer( true )
36 , mActionLayer( layer )
37 , mTargets( targets )
38 , mFlags( flags )
39{
40}
41
43 : QAction( icon, name, parent )
44 , mSpecificLayerType( true )
45 , mLayerType( layerType )
46 , mTargets( targets )
47 , mFlags( flags )
48{
49}
50
52{
53 //remove action from registry
55}
56
58{
59 return mFlags;
60}
61
66
68{
70 {
71 // action is only enabled for editable layers
72 if ( !layer )
73 return false;
74 if ( layer->type() != Qgis::LayerType::Vector )
75 return false;
76 if ( !qobject_cast<QgsVectorLayer *>( layer )->isEditable() )
77 return false;
78 }
79
81 {
82 // action is only enabled for layers with geometry
83 if ( !layer )
84 return false;
85 if ( layer->type() != Qgis::LayerType::Vector )
86 return false;
87 if ( qobject_cast<QgsVectorLayer *>( layer )->wkbType() == Qgis::WkbType::NoGeometry )
88 return false;
89 }
90
91 //check layer details
92 if ( !mSingleLayer && !mSpecificLayerType )
93 {
94 //action is not a single layer of specific layer type action,
95 //so return true
96 return true;
97 }
98 if ( mSingleLayer && layer == mActionLayer )
99 {
100 //action is a single layer type and layer matches
101 return true;
102 }
103 else if ( mSpecificLayerType && layer && layer->type() == mLayerType )
104 {
105 //action is for a layer type and layer type matches
106 return true;
107 }
108
109 return false;
110}
111
112void QgsMapLayerAction::triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList )
113{
115 emit triggeredForFeatures( layer, featureList );
117}
118
125
132
133void QgsMapLayerAction::triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList, const QgsMapLayerActionContext &context )
134{
135 emit triggeredForFeaturesV2( layer, featureList, context );
136}
137
139{
140 emit triggeredForFeatureV2( layer, feature, context );
141}
142
144{
145 emit triggeredForLayerV2( layer, context );
146}
147
@ EnableOnlyWhenHasGeometry
Action should be shown only for layers with geometry,.
Definition qgis.h:4653
@ EnabledOnlyWhenEditable
Action should be shown only for editable layers.
Definition qgis.h:4652
QFlags< MapLayerActionTarget > MapLayerActionTargets
Map layer action targets.
Definition qgis.h:4640
LayerType
Types of layers that can be added to a map.
Definition qgis.h:190
@ Vector
Vector layer.
Definition qgis.h:191
QFlags< MapLayerActionFlag > MapLayerActionFlags
Map layer action flags.
Definition qgis.h:4664
@ NoGeometry
No geometry.
Definition qgis.h:294
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
static QgsMapLayerActionRegistry * mapLayerActionRegistry()
Returns the global map layer action registry, used for registering map layer actions.
Definition qgsgui.cpp:146
Encapsulates the context in which a QgsMapLayerAction action is executed.
bool removeMapLayerAction(QgsMapLayerAction *action)
Removes a map layer action from the registry.
void triggeredForFeatureV2(QgsMapLayer *layer, const QgsFeature &feature, const QgsMapLayerActionContext &context)
Triggered when action has been run for a specific feature.
Q_DECL_DEPRECATED void triggeredForFeatures(QgsMapLayer *layer, const QList< QgsFeature > &featureList)
Triggered when action has been run for a specific list of features.
virtual Q_DECL_DEPRECATED bool canRunUsingLayer(QgsMapLayer *layer) const
Returns true if the action can run using the specified layer.
void triggeredForFeaturesV2(QgsMapLayer *layer, const QList< QgsFeature > &featureList, const QgsMapLayerActionContext &context)
Triggered when action has been run for a specific list of features.
Q_DECL_DEPRECATED void triggeredForFeature(QgsMapLayer *layer, const QgsFeature &feature)
Triggered when action has been run for a specific feature.
virtual Q_DECL_DEPRECATED void triggerForFeatures(QgsMapLayer *layer, const QList< QgsFeature > &featureList)
Triggers the action with the specified layer and list of feature.
Q_DECL_DEPRECATED void triggeredForLayer(QgsMapLayer *layer)
Triggered when action has been run for a specific layer.
Qgis::MapLayerActionTargets targets() const
Returns availibity of action.
virtual Q_DECL_DEPRECATED void triggerForLayer(QgsMapLayer *layer)
Triggers the action with the specified layer.
void triggeredForLayerV2(QgsMapLayer *layer, const QgsMapLayerActionContext &context)
Triggered when action has been run for a specific layer.
bool isEnabledOnlyWhenEditable() const
Returns true if the action is only enabled for layers in editable mode.
QgsMapLayerAction(const QString &name, QObject *parent, Qgis::MapLayerActionTargets targets=Qgis::MapLayerActionTarget::AllActions, const QIcon &icon=QIcon(), Qgis::MapLayerActionFlags flags=Qgis::MapLayerActionFlags())
Creates a map layer action which can run on any layer.
Qgis::MapLayerActionFlags flags() const
Layer behavior flags.
virtual Q_DECL_DEPRECATED void triggerForFeature(QgsMapLayer *layer, const QgsFeature &feature)
Triggers the action with the specified layer and feature.
Base class for all map layer types.
Definition qgsmaplayer.h:80
Qgis::LayerType type
Definition qgsmaplayer.h:90
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:7170
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7169