QGIS API Documentation 3.41.0-Master (3440c17df1d)
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#include "moc_qgsmaplayeractionregistry.cpp"
18#include "qgsmaplayeraction.h"
19
20QgsMapLayerActionRegistry::QgsMapLayerActionRegistry( QObject *parent ) : QObject( parent )
21{
22
23}
24
26{
27 mMapLayerActionList.append( action );
28 emit changed();
29}
30
32{
33 QList< QgsMapLayerAction * > validActions;
34
35 for ( QgsMapLayerAction *action : std::as_const( mMapLayerActionList ) )
36 {
37 bool canRun = false;
39 canRun = action->canRunUsingLayer( layer );
41 if ( !canRun )
42 canRun = action->canRunUsingLayer( layer, context );
43
44 if ( canRun && ( targets & action->targets() ) )
45 {
46 validActions.append( action );
47 }
48 }
49 return validActions;
50}
51
52
54{
55 if ( mMapLayerActionList.indexOf( action ) != -1 )
56 {
57 mMapLayerActionList.removeAll( action );
58
59 //also remove this action from the default layer action map
60 QMap<QgsMapLayer *, QgsMapLayerAction *>::iterator defaultIt;
61 for ( defaultIt = mDefaultLayerActionMap.begin(); defaultIt != mDefaultLayerActionMap.end(); ++defaultIt )
62 {
63 if ( defaultIt.value() == action )
64 {
65 defaultIt.value() = nullptr;
66 }
67 }
68 emit changed();
69 return true;
70 }
71 //not found
72 return false;
73}
74
76{
77 mDefaultLayerActionMap[ layer ] = action;
78}
79
81{
82 if ( !mDefaultLayerActionMap.contains( layer ) )
83 {
84 return nullptr;
85 }
86
87 return mDefaultLayerActionMap[ layer ];
88}
89
QFlags< MapLayerActionTarget > MapLayerActionTargets
Map layer action targets.
Definition qgis.h:4305
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:76
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6535
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6534