QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
27{
28 mMapLayerActionList.append( action );
29 emit changed();
30}
31
33{
34 QList<QgsMapLayerAction *> validActions;
35
36 for ( QgsMapLayerAction *action : std::as_const( mMapLayerActionList ) )
37 {
38 bool canRun = false;
40 canRun = action->canRunUsingLayer( layer );
42 if ( !canRun )
43 canRun = action->canRunUsingLayer( layer, context );
44
45 if ( canRun && ( targets & action->targets() ) )
46 {
47 validActions.append( action );
48 }
49 }
50 return validActions;
51}
52
53
55{
56 if ( mMapLayerActionList.indexOf( action ) != -1 )
57 {
58 mMapLayerActionList.removeAll( action );
59
60 //also remove this action from the default layer action map
61 QMap<QgsMapLayer *, QgsMapLayerAction *>::iterator defaultIt;
62 for ( defaultIt = mDefaultLayerActionMap.begin(); defaultIt != mDefaultLayerActionMap.end(); ++defaultIt )
63 {
64 if ( defaultIt.value() == action )
65 {
66 defaultIt.value() = nullptr;
67 }
68 }
69 emit changed();
70 return true;
71 }
72 //not found
73 return false;
74}
75
77{
78 mDefaultLayerActionMap[layer] = action;
79}
80
82{
83 if ( !mDefaultLayerActionMap.contains( layer ) )
84 {
85 return nullptr;
86 }
87
88 return mDefaultLayerActionMap[layer];
89}
QFlags< MapLayerActionTarget > MapLayerActionTargets
Map layer action targets.
Definition qgis.h:4797
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:83
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:7504
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7503