QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
33 : QAction( icon, name, parent )
34 , mSingleLayer( true )
35 , mActionLayer( layer )
36 , mTargets( targets )
37 , mFlags( flags )
38{}
39
41 : QAction( icon, name, parent )
42 , mSpecificLayerType( true )
43 , mLayerType( layerType )
44 , mTargets( targets )
45 , mFlags( flags )
46{}
47
49{
50 //remove action from registry
52}
53
55{
56 return mFlags;
57}
58
63
65{
67 {
68 // action is only enabled for editable layers
69 if ( !layer )
70 return false;
71 if ( layer->type() != Qgis::LayerType::Vector )
72 return false;
73 if ( !qobject_cast<QgsVectorLayer *>( layer )->isEditable() )
74 return false;
75 }
76
78 {
79 // action is only enabled for layers with geometry
80 if ( !layer )
81 return false;
82 if ( layer->type() != Qgis::LayerType::Vector )
83 return false;
84 if ( qobject_cast<QgsVectorLayer *>( layer )->wkbType() == Qgis::WkbType::NoGeometry )
85 return false;
86 }
87
88 //check layer details
89 if ( !mSingleLayer && !mSpecificLayerType )
90 {
91 //action is not a single layer of specific layer type action,
92 //so return true
93 return true;
94 }
95 if ( mSingleLayer && layer == mActionLayer )
96 {
97 //action is a single layer type and layer matches
98 return true;
99 }
100 else if ( mSpecificLayerType && layer && layer->type() == mLayerType )
101 {
102 //action is for a layer type and layer type matches
103 return true;
104 }
105
106 return false;
107}
108
109void QgsMapLayerAction::triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList )
110{
112 emit triggeredForFeatures( layer, featureList );
114}
115
122
129
130void QgsMapLayerAction::triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList, const QgsMapLayerActionContext &context )
131{
132 emit triggeredForFeaturesV2( layer, featureList, context );
133}
134
136{
137 emit triggeredForFeatureV2( layer, feature, context );
138}
139
141{
142 emit triggeredForLayerV2( layer, context );
143}
144
@ EnableOnlyWhenHasGeometry
Action should be shown only for layers with geometry,.
Definition qgis.h:4810
@ EnabledOnlyWhenEditable
Action should be shown only for editable layers.
Definition qgis.h:4809
QFlags< MapLayerActionTarget > MapLayerActionTargets
Map layer action targets.
Definition qgis.h:4797
LayerType
Types of layers that can be added to a map.
Definition qgis.h:206
@ Vector
Vector layer.
Definition qgis.h:207
QFlags< MapLayerActionFlag > MapLayerActionFlags
Map layer action flags.
Definition qgis.h:4821
@ NoGeometry
No geometry.
Definition qgis.h:312
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
static QgsMapLayerActionRegistry * mapLayerActionRegistry()
Returns the global map layer action registry, used for registering map layer actions.
Definition qgsgui.cpp:149
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:83
Qgis::LayerType type
Definition qgsmaplayer.h:93
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:7504
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7503