QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsmaplayeractionregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayeractionregistry.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
17
18#include "qgsmaplayeraction.h"
19
20#include "moc_qgsmaplayeractionregistry.cpp"
21
23 : QObject( parent )
24{
25}
26
28{
29 mMapLayerActionList.append( action );
30 emit changed();
31}
32
34{
35 QList<QgsMapLayerAction *> validActions;
36
37 for ( QgsMapLayerAction *action : std::as_const( mMapLayerActionList ) )
38 {
39 bool canRun = false;
41 canRun = action->canRunUsingLayer( layer );
43 if ( !canRun )
44 canRun = action->canRunUsingLayer( layer, context );
45
46 if ( canRun && ( targets & action->targets() ) )
47 {
48 validActions.append( action );
49 }
50 }
51 return validActions;
52}
53
54
56{
57 if ( mMapLayerActionList.indexOf( action ) != -1 )
58 {
59 mMapLayerActionList.removeAll( action );
60
61 //also remove this action from the default layer action map
62 QMap<QgsMapLayer *, QgsMapLayerAction *>::iterator defaultIt;
63 for ( defaultIt = mDefaultLayerActionMap.begin(); defaultIt != mDefaultLayerActionMap.end(); ++defaultIt )
64 {
65 if ( defaultIt.value() == action )
66 {
67 defaultIt.value() = nullptr;
68 }
69 }
70 emit changed();
71 return true;
72 }
73 //not found
74 return false;
75}
76
78{
79 mDefaultLayerActionMap[layer] = action;
80}
81
83{
84 if ( !mDefaultLayerActionMap.contains( layer ) )
85 {
86 return nullptr;
87 }
88
89 return mDefaultLayerActionMap[layer];
90}
QFlags< MapLayerActionTarget > MapLayerActionTargets
Map layer action targets.
Definition qgis.h:4640
Encapsulates the context in which a QgsMapLayerAction action is executed.
void addMapLayerAction(QgsMapLayerAction *action)
Adds a map layer action to the registry.
void changed()
Triggered when an action is added or removed from the registry.
bool removeMapLayerAction(QgsMapLayerAction *action)
Removes a map layer action from the registry.
QgsMapLayerActionRegistry(QObject *parent=nullptr)
Constructor for QgsMapLayerActionRegistry.
void setDefaultActionForLayer(QgsMapLayer *layer, QgsMapLayerAction *action)
Sets the default action for a layer.
QgsMapLayerAction * defaultActionForLayer(QgsMapLayer *layer)
Returns the default action for a layer.
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer, Qgis::MapLayerActionTargets targets=Qgis::MapLayerActionTarget::AllActions, const QgsMapLayerActionContext &context=QgsMapLayerActionContext())
Returns the map layer actions which can run on the specified layer.
QList< QgsMapLayerAction * > mMapLayerActionList
An action which can run on map layers.
Base class for all map layer types.
Definition qgsmaplayer.h:80
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:7170
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7169