Skip to content
Permalink
Browse files

availibilty definition for map layer actions

  • Loading branch information
3nids committed Aug 13, 2014
1 parent 0901627 commit b88723d069d9bc810dd6a1701a24b1f2eade2dd8
@@ -5,13 +5,20 @@ class QgsMapLayerAction : QAction
%End

public:
enum AvailabityFlag
{
Layer,
Feature,
LayerAndFeature
};
typedef QFlags<QgsMapLayerAction::AvailabityFlag> Availability;

/**Creates a map layer action which can run on any layer*/
QgsMapLayerAction( QString name, QObject *parent );
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 );
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Availability availability = LayerAndFeature );
/**Creates a map layer action which can run on a specific type of layer*/
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType );

QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Availability availability = LayerAndFeature );
~QgsMapLayerAction();

/** True if action can run using the specified layer */
@@ -24,6 +31,10 @@ 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 availibitly );
Availability availability() const;

signals:
/** Triggered when action has been run for a specific feature */
void triggeredForFeature( QgsMapLayer* layer, QgsFeature* feature );
@@ -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 );
mAtlasFeatureAction = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( mTitle ), this, coverageLayer, QgsMapLayerAction::Feature );
QgsMapLayerActionRegistry::instance()->addMapLayerAction( mAtlasFeatureAction );
connect( mAtlasFeatureAction, SIGNAL( triggeredForFeature( QgsMapLayer*, QgsFeature* ) ), this, SLOT( setAtlasFeature( QgsMapLayer*, QgsFeature* ) ) );
}
@@ -16,31 +16,31 @@
#include "qgsmaplayeractionregistry.h"


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

}

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

}

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

}

QgsMapLayerAction::~QgsMapLayerAction()
@@ -31,14 +31,23 @@ class QgsFeature;
class GUI_EXPORT QgsMapLayerAction : public QAction
{
Q_OBJECT
Q_FLAGS( Availability )

public:
enum AvailabityFlag
{
Layer = 1,
Feature = 2,
LayerAndFeature = Layer | Feature
};
Q_DECLARE_FLAGS( Availability, AvailabityFlag )

/**Creates a map layer action which can run on any layer*/
QgsMapLayerAction( QString name, QObject *parent );
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 );
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer* layer, Availability availability = LayerAndFeature );
/**Creates a map layer action which can run on a specific type of layer*/
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType );
QgsMapLayerAction( QString name, QObject *parent, QgsMapLayer::LayerType layerType, Availability availability = LayerAndFeature );

~QgsMapLayerAction();

@@ -52,6 +61,11 @@ class GUI_EXPORT QgsMapLayerAction : public 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 availabitly ) {mAvailability = availabitly;}
/** Return availibity of action */
Availability availability() const {return mAvailability;}

signals:
/** Triggered when action has been run for a specific feature */
void triggeredForFeature( QgsMapLayer* layer, QgsFeature* feature );
@@ -71,7 +85,8 @@ class GUI_EXPORT QgsMapLayerAction : public QAction
//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;
};

/**

3 comments on commit b88723d

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Aug 13, 2014

@3nids looks like you included the old api in the sip file here

@3nids

This comment has been minimized.

Copy link
Member Author

@3nids 3nids replied Aug 14, 2014

you meant I didn't break the API because methods are created for both layer and features?

Also, it is right that we could change it in c++, but not sure it makes sense to have different default values in python.

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Aug 14, 2014

@3nids actually ignore that - I didn't read the commit properly. Sorry for the noise!

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