QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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#include "qgsgui.h"
19#include "qgsmaplayer.h"
20#include "qgsvectorlayer.h"
22#include "moc_qgsmaplayeraction.cpp"
23
24QgsMapLayerAction::QgsMapLayerAction( const QString &name, QObject *parent, Qgis::MapLayerActionTargets targets, const QIcon &icon, Qgis::MapLayerActionFlags flags )
25 : QAction( icon, name, parent )
26 , mTargets( targets )
27 , mFlags( flags )
28{
29}
30
31QgsMapLayerAction::QgsMapLayerAction( const QString &name, QObject *parent, QgsMapLayer *layer, Qgis::MapLayerActionTargets targets, const QIcon &icon, Qgis::MapLayerActionFlags flags )
32 : QAction( icon, name, parent )
33 , mSingleLayer( true )
34 , mActionLayer( layer )
35 , mTargets( targets )
36 , mFlags( flags )
37{
38}
39
40QgsMapLayerAction::QgsMapLayerAction( const QString &name, QObject *parent, Qgis::LayerType layerType, Qgis::MapLayerActionTargets targets, const QIcon &icon, Qgis::MapLayerActionFlags flags )
41 : QAction( icon, name, parent )
42 , mSpecificLayerType( true )
43 , mLayerType( layerType )
44 , mTargets( targets )
45 , mFlags( flags )
46{
47}
48
50{
51 //remove action from registry
53}
54
56{
57 return mFlags;
58}
59
64
66{
68 {
69 // action is only enabled for editable layers
70 if ( !layer )
71 return false;
72 if ( layer->type() != Qgis::LayerType::Vector )
73 return false;
74 if ( !qobject_cast<QgsVectorLayer *>( layer )->isEditable() )
75 return false;
76 }
77
78 //check layer details
79 if ( !mSingleLayer && !mSpecificLayerType )
80 {
81 //action is not a single layer of specific layer type action,
82 //so return true
83 return true;
84 }
85 if ( mSingleLayer && layer == mActionLayer )
86 {
87 //action is a single layer type and layer matches
88 return true;
89 }
90 else if ( mSpecificLayerType && layer && layer->type() == mLayerType )
91 {
92 //action is for a layer type and layer type matches
93 return true;
94 }
95
96 return false;
97}
98
99void QgsMapLayerAction::triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList )
100{
102 emit triggeredForFeatures( layer, featureList );
104}
105
112
119
120void QgsMapLayerAction::triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList, const QgsMapLayerActionContext &context )
121{
122 emit triggeredForFeaturesV2( layer, featureList, context );
123}
124
126{
127 emit triggeredForFeatureV2( layer, feature, context );
128}
129
131{
132 emit triggeredForLayerV2( layer, context );
133}
134
139
@ EnabledOnlyWhenEditable
Action should be shown only for editable layers.
QFlags< MapLayerActionTarget > MapLayerActionTargets
Map layer action targets.
Definition qgis.h:4305
LayerType
Types of layers that can be added to a map.
Definition qgis.h:169
@ Vector
Vector layer.
QFlags< MapLayerActionFlag > MapLayerActionFlags
Map layer action flags.
Definition qgis.h:4328
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:134
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.
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:76
Qgis::LayerType type
Definition qgsmaplayer.h:86
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6535
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6534