Skip to content

Commit

Permalink
availibilty definition for map layer actions
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Aug 13, 2014
1 parent 0901627 commit b88723d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
19 changes: 15 additions & 4 deletions python/gui/qgsmaplayeractionregistry.sip
Expand Up @@ -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 */
Expand All @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposer.cpp
Expand Up @@ -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* ) ) );
}
Expand Down
18 changes: 9 additions & 9 deletions src/gui/qgsmaplayeractionregistry.cpp
Expand Up @@ -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()
Expand Down
23 changes: 19 additions & 4 deletions src/gui/qgsmaplayeractionregistry.h
Expand Up @@ -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();

Expand All @@ -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 );
Expand All @@ -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;
};

/**
Expand Down

3 comments on commit b88723d

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@3nids
Copy link
Member Author

@3nids 3nids commented on b88723d Aug 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.