QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
23QgsMapLayerAction::QgsMapLayerAction( const QString &name, QObject *parent, Qgis::MapLayerActionTargets targets, const QIcon &icon, Qgis::MapLayerActionFlags flags )
24 : QAction( icon, name, parent )
25 , mTargets( targets )
26 , mFlags( flags )
27{
28}
29
30QgsMapLayerAction::QgsMapLayerAction( const QString &name, QObject *parent, QgsMapLayer *layer, Qgis::MapLayerActionTargets targets, const QIcon &icon, Qgis::MapLayerActionFlags flags )
31 : QAction( icon, name, parent )
32 , mSingleLayer( true )
33 , mActionLayer( layer )
34 , mTargets( targets )
35 , mFlags( flags )
36{
37}
38
39QgsMapLayerAction::QgsMapLayerAction( const QString &name, QObject *parent, Qgis::LayerType layerType, Qgis::MapLayerActionTargets targets, const QIcon &icon, Qgis::MapLayerActionFlags flags )
40 : QAction( icon, name, parent )
41 , mSpecificLayerType( true )
42 , mLayerType( layerType )
43 , mTargets( targets )
44 , mFlags( flags )
45{
46}
47
49{
50 //remove action from registry
52}
53
54Qgis::MapLayerActionFlags QgsMapLayerAction::flags() const
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
77 //check layer details
78 if ( !mSingleLayer && !mSpecificLayerType )
79 {
80 //action is not a single layer of specific layer type action,
81 //so return true
82 return true;
83 }
84 if ( mSingleLayer && layer == mActionLayer )
85 {
86 //action is a single layer type and layer matches
87 return true;
88 }
89 else if ( mSpecificLayerType && layer && layer->type() == mLayerType )
90 {
91 //action is for a layer type and layer type matches
92 return true;
93 }
94
95 return false;
96}
97
98void QgsMapLayerAction::triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList )
99{
101 emit triggeredForFeatures( layer, featureList );
103}
104
111
118
119void QgsMapLayerAction::triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList, const QgsMapLayerActionContext &context )
120{
121 emit triggeredForFeaturesV2( layer, featureList, context );
122}
123
125{
126 emit triggeredForFeatureV2( layer, feature, context );
127}
128
130{
131 emit triggeredForLayerV2( layer, context );
132}
133
138
@ EnabledOnlyWhenEditable
Action should be shown only for editable layers.
LayerType
Types of layers that can be added to a map.
Definition qgis.h:114
@ Vector
Vector layer.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:56
static QgsMapLayerActionRegistry * mapLayerActionRegistry()
Returns the global map layer action registry, used for registering map layer actions.
Definition qgsgui.cpp:129
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:74
Qgis::LayerType type
Definition qgsmaplayer.h:81
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:4916
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:4915