Skip to content

Commit 252dc37

Browse files
committed
[map layer actions] action for group of features, rename availability to target (flags), only emit signal for defined target"
Conflicts: src/gui/qgsmaplayeractionregistry.cpp src/gui/qgsmaplayeractionregistry.h
1 parent b583597 commit 252dc37

File tree

4 files changed

+62
-51
lines changed

4 files changed

+62
-51
lines changed

python/gui/qgsmaplayeractionregistry.sip

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ class QgsMapLayerAction : QAction
55
%End
66

77
public:
8-
enum AvailabityFlag
8+
enum Target
99
{
10-
Layer,
11-
Feature,
12-
LayerAndFeature
10+
Layer ,
11+
SingleFeature,
12+
MultipleFeatures,
13+
AllActions
1314
};
14-
typedef QFlags<QgsMapLayerAction::AvailabityFlag> Availability;
15+
typedef QFlags<QgsMapLayerAction::Target> Targets;
1516

1617
/**Creates a map layer action which can run on any layer*/
17-
QgsMapLayerAction( QString name, QObject *parent, Availability availability = LayerAndFeature );
18+
QgsMapLayerAction( QString name, QObject *parent, Targets targets = AllActions );
1819
/**Creates a map layer action which can run only on a specific layer*/
19-
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Availability availability = LayerAndFeature );
20+
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Targets targets = AllActions );
2021
/**Creates a map layer action which can run on a specific type of layer*/
21-
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Availability availability = LayerAndFeature );
22+
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Targets targets = AllActions );
2223
~QgsMapLayerAction();
2324

2425
/** True if action can run using the specified layer */
@@ -31,9 +32,9 @@ class QgsMapLayerAction : QAction
3132
/** Triggers the action with the specified layer. This also emits the triggered() slot. */
3233
void triggerForLayer( QgsMapLayer* layer );
3334

34-
/** Define the availibility of the action */
35-
void setAvailability( Availability availability );
36-
Availability availability() const;
35+
/** Define the targets of the action */
36+
void setTargets( Targets targets );
37+
Targets targets() const;
3738

3839
signals:
3940
/** Triggered when action has been run for a specific feature */
@@ -60,7 +61,7 @@ class QgsMapLayerActionRegistry : QObject
6061
void addMapLayerAction( QgsMapLayerAction * action );
6162

6263
/**Returns the map layer actions which can run on the specified layer*/
63-
QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer* layer );
64+
QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer* layer, QgsMapLayerAction::Targets targets = QgsMapLayerAction::AllActions );
6465

6566
/**Removes a map layer action from the registry*/
6667
bool removeMapLayerAction( QgsMapLayerAction *action );

src/app/composer/qgscomposer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,7 +3573,7 @@ void QgsComposer::updateAtlasMapLayerAction( QgsVectorLayer *coverageLayer )
35733573

35743574
if ( coverageLayer )
35753575
{
3576-
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, coverageLayer, QgsMapLayerAction::Feature );
3576+
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, coverageLayer, QgsMapLayerAction::SingleFeature );
35773577
QgsMapLayerActionRegistry::instance()->addMapLayerAction( mAtlasFeatureAction );
35783578
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, QgsFeature* ) ) );
35793579
}
@@ -3618,7 +3618,7 @@ void QgsComposer::updateAtlasMapLayerAction( bool atlasEnabled )
36183618
if ( atlasEnabled )
36193619
{
36203620
QgsAtlasComposition& atlas = mComposition->atlasComposition();
3621-
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, atlas.coverageLayer() );
3621+
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, atlas.coverageLayer(), QgsMapLayerAction::SingleFeature );
36223622
QgsMapLayerActionRegistry::instance()->addMapLayerAction( mAtlasFeatureAction );
36233623
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, QgsFeature* ) ) );
36243624
}

src/gui/qgsmaplayeractionregistry.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@
1616
#include "qgsmaplayeractionregistry.h"
1717

1818

19-
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, Availability availability ) : QAction( name, parent ),
19+
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, Targets targets ) : QAction( name, parent ),
2020
mSingleLayer( false ),
2121
mActionLayer( 0 ),
2222
mSpecificLayerType( false ),
23-
mAvailability( availability )
23+
mTargets( targets )
2424
{
2525
}
2626

2727
/**Creates a map layer action which can run only on a specific layer*/
28-
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, QgsMapLayer* layer , Availability availability ) : QAction( name, parent ),
28+
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, QgsMapLayer* layer , Targets targets ) : QAction( name, parent ),
2929
mSingleLayer( true ),
3030
mActionLayer( layer ),
3131
mSpecificLayerType( false ),
32-
mAvailability( availability )
32+
mTargets( targets )
3333
{
3434
}
3535

3636
/**Creates a map layer action which can run on a specific type of layer*/
37-
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, QgsMapLayer::LayerType layerType, Availability availability ) : QAction( name, parent ),
37+
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, QgsMapLayer::LayerType layerType, Targets targets ) : QAction( name, parent ),
3838
mSingleLayer( false ),
3939
mActionLayer( 0 ),
4040
mSpecificLayerType( true ),
4141
mLayerType( layerType ),
42-
mAvailability( availability )
42+
mTargets( targets )
4343
{
4444
}
4545

@@ -72,18 +72,19 @@ bool QgsMapLayerAction::canRunUsingLayer( QgsMapLayer* layer ) const
7272
return false;
7373
}
7474

75-
void QgsMapLayerAction::triggerForFeature( QgsMapLayer* layer, QgsFeature* feature )
75+
void QgsMapLayerAction::triggerForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList )
76+
{
77+
emit triggeredForFeatures( layer, featureList );
78+
}
79+
80+
void QgsMapLayerAction::triggerForFeature( QgsMapLayer* layer, const QgsFeature* feature )
7681
{
7782
emit triggeredForFeature( layer, feature );
78-
//also trigger this action for the specified layer
79-
triggerForLayer( layer );
8083
}
8184

8285
void QgsMapLayerAction::triggerForLayer( QgsMapLayer* layer )
8386
{
8487
emit triggeredForLayer( layer );
85-
//also emit triggered signal
86-
emit triggered();
8788
}
8889

8990
//
@@ -119,13 +120,13 @@ void QgsMapLayerActionRegistry::addMapLayerAction( QgsMapLayerAction * action )
119120
emit changed();
120121
}
121122

122-
QList< QgsMapLayerAction* > QgsMapLayerActionRegistry::mapLayerActions( QgsMapLayer* layer )
123+
QList< QgsMapLayerAction* > QgsMapLayerActionRegistry::mapLayerActions( QgsMapLayer* layer, QgsMapLayerAction::Targets targets )
123124
{
124125
QList< QgsMapLayerAction* > validActions;
125126
QList<QgsMapLayerAction*>::iterator actionIt;
126127
for ( actionIt = mMapLayerActionList.begin(); actionIt != mMapLayerActionList.end(); ++actionIt )
127128
{
128-
if (( *actionIt )->canRunUsingLayer( layer ) )
129+
if (( *actionIt )->canRunUsingLayer( layer ) && ( targets & ( *actionIt )->targets() ) )
129130
{
130131
validActions.append(( *actionIt ) );
131132
}

src/gui/qgsmaplayeractionregistry.h

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,62 +34,71 @@ class GUI_EXPORT QgsMapLayerAction : public QAction
3434
Q_FLAGS( Availability )
3535

3636
public:
37-
enum AvailabityFlag
37+
enum Target
3838
{
3939
Layer = 1,
40-
Feature = 2,
41-
LayerAndFeature = Layer | Feature
40+
SingleFeature = 2,
41+
MultipleFeatures = 4,
42+
AllActions = Layer | SingleFeature | MultipleFeatures
4243
};
43-
Q_DECLARE_FLAGS( Availability, AvailabityFlag )
44+
Q_DECLARE_FLAGS( Targets, Target )
45+
46+
//! Creates a map layer action which can run on any layer
47+
//! @note using AllActions as a target probably does not make a lot of sense. This default action was settled for API compatiblity reasons.
48+
QgsMapLayerAction( QString name, QObject *parent, Targets targets = AllActions );
4449

45-
/**Creates a map layer action which can run on any layer*/
46-
QgsMapLayerAction( QString name, QObject *parent, Availability availability = LayerAndFeature );
4750
/**Creates a map layer action which can run only on a specific layer*/
48-
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Availability availability = LayerAndFeature );
51+
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Targets targets = AllActions );
52+
4953
/**Creates a map layer action which can run on a specific type of layer*/
50-
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Availability availability = LayerAndFeature );
54+
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Targets targets = AllActions );
5155

5256
~QgsMapLayerAction();
5357

5458
/** True if action can run using the specified layer */
5559
bool canRunUsingLayer( QgsMapLayer* layer ) const;
5660

57-
/** Triggers the action with the specified layer and feature. This also emits the triggeredForLayer( QgsMapLayer *)
58-
* and triggered() slots */
59-
void triggerForFeature( QgsMapLayer* layer, QgsFeature* feature );
61+
/** Triggers the action with the specified layer and list of feature. */
62+
void triggerForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList );
6063

61-
/** Triggers the action with the specified layer. This also emits the triggered() slot. */
64+
/** Triggers the action with the specified layer and feature. */
65+
void triggerForFeature( QgsMapLayer* layer, const QgsFeature* feature );
66+
67+
/** Triggers the action with the specified layer. */
6268
void triggerForLayer( QgsMapLayer* layer );
6369

64-
/** Define the availibility of the action */
65-
void setAvailability( Availability availability ) {mAvailability = availability;}
70+
/** Define the targets of the action */
71+
void setTargets( Targets targets ) {mTargets = targets;}
6672
/** Return availibity of action */
67-
Availability availability() const {return mAvailability;}
73+
Targets targets() const {return mTargets;}
6874

6975
signals:
76+
/** Triggered when action has been run for a specific list of features */
77+
void triggeredForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList );
78+
7079
/** Triggered when action has been run for a specific feature */
71-
void triggeredForFeature( QgsMapLayer* layer, QgsFeature* feature );
80+
void triggeredForFeature( QgsMapLayer* layer, const QgsFeature* feature );
7281

7382
/** Triggered when action has been run for a specific layer */
7483
void triggeredForLayer( QgsMapLayer* layer );
7584

7685
private:
7786

78-
//true if action is only valid for a single layer
87+
// true if action is only valid for a single layer
7988
bool mSingleLayer;
80-
//layer if action is only valid for a single layer
89+
// layer if action is only valid for a single layer
8190
QgsMapLayer* mActionLayer;
8291

83-
//true if action is only valid for a specific layer type
92+
// true if action is only valid for a specific layer type
8493
bool mSpecificLayerType;
85-
//layer type if action is only valid for a specific layer type
94+
// layer type if action is only valid for a specific layer type
8695
QgsMapLayer::LayerType mLayerType;
8796

88-
// determine if the action can be run on feature and/or layer
89-
Availability mAvailability;
97+
// determine if the action can be run on layer and/or single feature and/or multiple features
98+
Targets mTargets;
9099
};
91100

92-
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerAction::Availability )
101+
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerAction::Targets )
93102

94103
/**
95104
* This class tracks map layer actions
@@ -108,7 +117,7 @@ class GUI_EXPORT QgsMapLayerActionRegistry : public QObject
108117
void addMapLayerAction( QgsMapLayerAction * action );
109118

110119
/**Returns the map layer actions which can run on the specified layer*/
111-
QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer* layer );
120+
QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer* layer, QgsMapLayerAction::Targets targets = QgsMapLayerAction::AllActions );
112121

113122
/**Removes a map layer action from the registry*/
114123
bool removeMapLayerAction( QgsMapLayerAction *action );

0 commit comments

Comments
 (0)