QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
actions
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
16
#include "
qgsmaplayeractionregistry.h
"
17
18
#include "
qgsmaplayeraction.h
"
19
20
#include "moc_qgsmaplayeractionregistry.cpp"
21
22
QgsMapLayerActionRegistry::QgsMapLayerActionRegistry
( QObject *parent )
23
: QObject( parent )
24
{}
25
26
void
QgsMapLayerActionRegistry::addMapLayerAction
(
QgsMapLayerAction
*action )
27
{
28
mMapLayerActionList
.append( action );
29
emit
changed
();
30
}
31
32
QList<QgsMapLayerAction *>
QgsMapLayerActionRegistry::mapLayerActions
(
QgsMapLayer
*layer,
Qgis::MapLayerActionTargets
targets,
const
QgsMapLayerActionContext
&context )
33
{
34
QList<QgsMapLayerAction *> validActions;
35
36
for
(
QgsMapLayerAction
*action : std::as_const(
mMapLayerActionList
) )
37
{
38
bool
canRun =
false
;
39
Q_NOWARN_DEPRECATED_PUSH
40
canRun = action->canRunUsingLayer( layer );
41
Q_NOWARN_DEPRECATED_POP
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
54
bool
QgsMapLayerActionRegistry::removeMapLayerAction
(
QgsMapLayerAction
*action )
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
76
void
QgsMapLayerActionRegistry::setDefaultActionForLayer
(
QgsMapLayer
*layer,
QgsMapLayerAction
*action )
77
{
78
mDefaultLayerActionMap[layer] = action;
79
}
80
81
QgsMapLayerAction
*
QgsMapLayerActionRegistry::defaultActionForLayer
(
QgsMapLayer
*layer )
82
{
83
if
( !mDefaultLayerActionMap.contains( layer ) )
84
{
85
return
nullptr
;
86
}
87
88
return
mDefaultLayerActionMap[layer];
89
}
Qgis::MapLayerActionTargets
QFlags< MapLayerActionTarget > MapLayerActionTargets
Map layer action targets.
Definition
qgis.h:5180
QgsMapLayerActionContext
Encapsulates the context in which a QgsMapLayerAction action is executed.
Definition
qgsmaplayeractioncontext.h:34
QgsMapLayerActionRegistry::addMapLayerAction
void addMapLayerAction(QgsMapLayerAction *action)
Adds a map layer action to the registry.
Definition
qgsmaplayeractionregistry.cpp:26
QgsMapLayerActionRegistry::changed
void changed()
Triggered when an action is added or removed from the registry.
QgsMapLayerActionRegistry::removeMapLayerAction
bool removeMapLayerAction(QgsMapLayerAction *action)
Removes a map layer action from the registry.
Definition
qgsmaplayeractionregistry.cpp:54
QgsMapLayerActionRegistry::QgsMapLayerActionRegistry
QgsMapLayerActionRegistry(QObject *parent=nullptr)
Constructor for QgsMapLayerActionRegistry.
Definition
qgsmaplayeractionregistry.cpp:22
QgsMapLayerActionRegistry::setDefaultActionForLayer
void setDefaultActionForLayer(QgsMapLayer *layer, QgsMapLayerAction *action)
Sets the default action for a layer.
Definition
qgsmaplayeractionregistry.cpp:76
QgsMapLayerActionRegistry::defaultActionForLayer
QgsMapLayerAction * defaultActionForLayer(QgsMapLayer *layer)
Returns the default action for a layer.
Definition
qgsmaplayeractionregistry.cpp:81
QgsMapLayerActionRegistry::mapLayerActions
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.
Definition
qgsmaplayeractionregistry.cpp:32
QgsMapLayerActionRegistry::mMapLayerActionList
QList< QgsMapLayerAction * > mMapLayerActionList
Definition
qgsmaplayeractionregistry.h:74
QgsMapLayerAction
An action which can run on map layers.
Definition
qgsmaplayeraction.h:44
QgsMapLayer
Base class for all map layer types.
Definition
qgsmaplayer.h:83
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition
qgis.h:8379
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition
qgis.h:8378
qgsmaplayeraction.h
qgsmaplayeractionregistry.h
Generated on
for QGIS API Documentation by
1.17.0