Skip to content
Permalink
Browse files

[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
  • Loading branch information
3nids committed Aug 27, 2014
1 parent b583597 commit 252dc377a43f245d1908ab232e9a424bfd948b9e
@@ -5,20 +5,21 @@ class QgsMapLayerAction : QAction
%End

public:
enum AvailabityFlag
enum Target
{
Layer,
Feature,
LayerAndFeature
Layer ,
SingleFeature,
MultipleFeatures,
AllActions
};
typedef QFlags<QgsMapLayerAction::AvailabityFlag> Availability;
typedef QFlags<QgsMapLayerAction::Target> Targets;

/**Creates a map layer action which can run on any layer*/
QgsMapLayerAction( QString name, QObject *parent, Availability availability = LayerAndFeature );
QgsMapLayerAction( QString name, QObject *parent, Targets targets = AllActions );
/**Creates a map layer action which can run only on a specific layer*/
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Availability availability = LayerAndFeature );
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Targets targets = AllActions );
/**Creates a map layer action which can run on a specific type of layer*/
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Availability availability = LayerAndFeature );
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Targets targets = AllActions );
~QgsMapLayerAction();

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

/** Define the availibility of the action */
void setAvailability( Availability availability );
Availability availability() const;
/** Define the targets of the action */
void setTargets( Targets targets );
Targets targets() const;

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

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

/**Removes a map layer action from the registry*/
bool removeMapLayerAction( QgsMapLayerAction *action );
@@ -3573,7 +3573,7 @@ void QgsComposer::updateAtlasMapLayerAction( QgsVectorLayer *coverageLayer )

if ( coverageLayer )
{
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, coverageLayer, QgsMapLayerAction::Feature );
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, coverageLayer, QgsMapLayerAction::SingleFeature );
QgsMapLayerActionRegistry::instance()->addMapLayerAction( mAtlasFeatureAction );
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, QgsFeature* ) ) );
}
@@ -3618,7 +3618,7 @@ void QgsComposer::updateAtlasMapLayerAction( bool atlasEnabled )
if ( atlasEnabled )
{
QgsAtlasComposition& atlas = mComposition->atlasComposition();
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, atlas.coverageLayer() );
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, atlas.coverageLayer(), QgsMapLayerAction::SingleFeature );
QgsMapLayerActionRegistry::instance()->addMapLayerAction( mAtlasFeatureAction );
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, QgsFeature* ) ) );
}
@@ -16,30 +16,30 @@
#include "qgsmaplayeractionregistry.h"


QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, Availability availability ) : QAction( name, parent ),
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, Targets targets ) : QAction( name, parent ),
mSingleLayer( false ),
mActionLayer( 0 ),
mSpecificLayerType( false ),
mAvailability( availability )
mTargets( targets )
{
}

/**Creates a map layer action which can run only on a specific layer*/
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, QgsMapLayer* layer , Availability availability ) : QAction( name, parent ),
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, QgsMapLayer* layer , Targets targets ) : QAction( name, parent ),
mSingleLayer( true ),
mActionLayer( layer ),
mSpecificLayerType( false ),
mAvailability( availability )
mTargets( targets )
{
}

/**Creates a map layer action which can run on a specific type of layer*/
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, QgsMapLayer::LayerType layerType, Availability availability ) : QAction( name, parent ),
QgsMapLayerAction::QgsMapLayerAction( QString name, QObject* parent, QgsMapLayer::LayerType layerType, Targets targets ) : QAction( name, parent ),
mSingleLayer( false ),
mActionLayer( 0 ),
mSpecificLayerType( true ),
mLayerType( layerType ),
mAvailability( availability )
mTargets( targets )
{
}

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

void QgsMapLayerAction::triggerForFeature( QgsMapLayer* layer, QgsFeature* feature )
void QgsMapLayerAction::triggerForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList )
{
emit triggeredForFeatures( layer, featureList );
}

void QgsMapLayerAction::triggerForFeature( QgsMapLayer* layer, const QgsFeature* feature )
{
emit triggeredForFeature( layer, feature );
//also trigger this action for the specified layer
triggerForLayer( layer );
}

void QgsMapLayerAction::triggerForLayer( QgsMapLayer* layer )
{
emit triggeredForLayer( layer );
//also emit triggered signal
emit triggered();
}

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

QList< QgsMapLayerAction* > QgsMapLayerActionRegistry::mapLayerActions( QgsMapLayer* layer )
QList< QgsMapLayerAction* > QgsMapLayerActionRegistry::mapLayerActions( QgsMapLayer* layer, QgsMapLayerAction::Targets targets )
{
QList< QgsMapLayerAction* > validActions;
QList<QgsMapLayerAction*>::iterator actionIt;
for ( actionIt = mMapLayerActionList.begin(); actionIt != mMapLayerActionList.end(); ++actionIt )
{
if (( *actionIt )->canRunUsingLayer( layer ) )
if (( *actionIt )->canRunUsingLayer( layer ) && ( targets & ( *actionIt )->targets() ) )
{
validActions.append(( *actionIt ) );
}
@@ -34,62 +34,71 @@ class GUI_EXPORT QgsMapLayerAction : public QAction
Q_FLAGS( Availability )

public:
enum AvailabityFlag
enum Target
{
Layer = 1,
Feature = 2,
LayerAndFeature = Layer | Feature
SingleFeature = 2,
MultipleFeatures = 4,
AllActions = Layer | SingleFeature | MultipleFeatures
};
Q_DECLARE_FLAGS( Availability, AvailabityFlag )
Q_DECLARE_FLAGS( Targets, Target )

//! Creates a map layer action which can run on any layer
//! @note using AllActions as a target probably does not make a lot of sense. This default action was settled for API compatiblity reasons.
QgsMapLayerAction( QString name, QObject *parent, Targets targets = AllActions );

/**Creates a map layer action which can run on any layer*/
QgsMapLayerAction( QString name, QObject *parent, Availability availability = LayerAndFeature );
/**Creates a map layer action which can run only on a specific layer*/
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Availability availability = LayerAndFeature );
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Targets targets = AllActions );

/**Creates a map layer action which can run on a specific type of layer*/
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Availability availability = LayerAndFeature );
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Targets targets = AllActions );

~QgsMapLayerAction();

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

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

/** Triggers the action with the specified layer. This also emits the triggered() slot. */
/** Triggers the action with the specified layer and feature. */
void triggerForFeature( QgsMapLayer* layer, const QgsFeature* feature );

/** Triggers the action with the specified layer. */
void triggerForLayer( QgsMapLayer* layer );

/** Define the availibility of the action */
void setAvailability( Availability availability ) {mAvailability = availability;}
/** Define the targets of the action */
void setTargets( Targets targets ) {mTargets = targets;}
/** Return availibity of action */
Availability availability() const {return mAvailability;}
Targets targets() const {return mTargets;}

signals:
/** Triggered when action has been run for a specific list of features */
void triggeredForFeatures( QgsMapLayer* layer, QList<const QgsFeature*> featureList );

/** Triggered when action has been run for a specific feature */
void triggeredForFeature( QgsMapLayer* layer, QgsFeature* feature );
void triggeredForFeature( QgsMapLayer* layer, const QgsFeature* feature );

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

private:

//true if action is only valid for a single layer
// true if action is only valid for a single layer
bool mSingleLayer;
//layer if action is only valid for a single layer
// layer if action is only valid for a single layer
QgsMapLayer* mActionLayer;

//true if action is only valid for a specific layer type
// true if action is only valid for a specific layer type
bool mSpecificLayerType;
//layer type if action is only valid for a specific layer type
// layer type if action is only valid for a specific layer type
QgsMapLayer::LayerType mLayerType;

// determine if the action can be run on feature and/or layer
Availability mAvailability;
// determine if the action can be run on layer and/or single feature and/or multiple features
Targets mTargets;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerAction::Availability )
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerAction::Targets )

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

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

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

0 comments on commit 252dc37

Please sign in to comment.
You can’t perform that action at this time.