QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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#include "qgsmaplayeraction.h"
18
19QgsMapLayerActionRegistry::QgsMapLayerActionRegistry( QObject *parent ) : QObject( parent )
20{
21
22}
23
25{
26 mMapLayerActionList.append( action );
27 emit changed();
28}
29
31{
32 QList< QgsMapLayerAction * > validActions;
33
34 for ( QgsMapLayerAction *action : std::as_const( mMapLayerActionList ) )
35 {
36 bool canRun = false;
38 canRun = action->canRunUsingLayer( layer );
40 if ( !canRun )
41 canRun = action->canRunUsingLayer( layer, context );
42
43 if ( canRun && ( targets & action->targets() ) )
44 {
45 validActions.append( action );
46 }
47 }
48 return validActions;
49}
50
51
53{
54 if ( mMapLayerActionList.indexOf( action ) != -1 )
55 {
56 mMapLayerActionList.removeAll( action );
57
58 //also remove this action from the default layer action map
59 QMap<QgsMapLayer *, QgsMapLayerAction *>::iterator defaultIt;
60 for ( defaultIt = mDefaultLayerActionMap.begin(); defaultIt != mDefaultLayerActionMap.end(); ++defaultIt )
61 {
62 if ( defaultIt.value() == action )
63 {
64 defaultIt.value() = nullptr;
65 }
66 }
67 emit changed();
68 return true;
69 }
70 //not found
71 return false;
72}
73
75{
76 mDefaultLayerActionMap[ layer ] = action;
77}
78
80{
81 if ( !mDefaultLayerActionMap.contains( layer ) )
82 {
83 return nullptr;
84 }
85
86 return mDefaultLayerActionMap[ layer ];
87}
88
QFlags< MapLayerActionTarget > MapLayerActionTargets
Map layer action targets.
Definition: qgis.h:3842
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.
QList< QgsMapLayerAction * > mMapLayerActionList
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.
An action which can run on map layers The class can be used in two manners:
Base class for all map layer types.
Definition: qgsmaplayer.h:75
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:5776
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:5775