2014-01-19 23:04:24 +11:00
|
|
|
class QgsMapLayerAction : QAction
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsmaplayeractionregistry.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
2014-08-27 10:49:19 +02:00
|
|
|
enum Target
|
2014-08-13 14:30:23 +02:00
|
|
|
{
|
2014-09-17 08:43:26 +02:00
|
|
|
Layer,
|
2014-08-27 10:49:19 +02:00
|
|
|
SingleFeature,
|
|
|
|
MultipleFeatures,
|
|
|
|
AllActions
|
2014-08-13 14:30:23 +02:00
|
|
|
};
|
2014-08-27 10:49:19 +02:00
|
|
|
typedef QFlags<QgsMapLayerAction::Target> Targets;
|
2014-08-13 14:30:23 +02:00
|
|
|
|
2014-09-17 08:43:26 +02:00
|
|
|
//! Creates a map layer action which can run on any layer
|
2017-01-12 22:01:50 +01:00
|
|
|
//! @note using AllActions as a target probably does not make a lot of sense. This default action was settled for API compatibility reasons.
|
2017-05-01 16:42:33 +02:00
|
|
|
QgsMapLayerAction( const QString &name, QObject *parent /TransferThis/, Targets targets = AllActions, const QIcon &icon = QIcon() );
|
2014-09-17 08:43:26 +02:00
|
|
|
|
|
|
|
//! Creates a map layer action which can run only on a specific layer
|
2017-05-01 16:42:33 +02:00
|
|
|
QgsMapLayerAction( const QString &name, QObject *parent /TransferThis/, QgsMapLayer *layer, Targets targets = AllActions, const QIcon &icon = QIcon() );
|
2014-09-17 08:43:26 +02:00
|
|
|
|
|
|
|
//! Creates a map layer action which can run on a specific type of layer
|
2017-05-01 16:42:33 +02:00
|
|
|
QgsMapLayerAction( const QString &name, QObject *parent /TransferThis/, QgsMapLayer::LayerType layerType, Targets targets = AllActions, const QIcon &icon = QIcon() );
|
2014-09-17 08:43:26 +02:00
|
|
|
|
2014-01-19 23:04:24 +11:00
|
|
|
~QgsMapLayerAction();
|
|
|
|
|
|
|
|
/** True if action can run using the specified layer */
|
2017-05-01 16:42:33 +02:00
|
|
|
bool canRunUsingLayer( QgsMapLayer *layer ) const;
|
2014-01-19 23:04:24 +11:00
|
|
|
|
2014-09-17 09:18:53 +02:00
|
|
|
/** Triggers the action with the specified layer and list of feature. */
|
2017-05-01 16:42:33 +02:00
|
|
|
void triggerForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList );
|
2014-09-17 08:43:26 +02:00
|
|
|
|
|
|
|
/** Triggers the action with the specified layer and feature. */
|
2017-05-01 16:42:33 +02:00
|
|
|
void triggerForFeature( QgsMapLayer *layer, const QgsFeature *feature );
|
2014-01-19 23:04:24 +11:00
|
|
|
|
2014-09-17 08:43:26 +02:00
|
|
|
/** Triggers the action with the specified layer. */
|
2017-05-01 16:42:33 +02:00
|
|
|
void triggerForLayer( QgsMapLayer *layer );
|
2014-01-19 23:04:24 +11:00
|
|
|
|
2014-08-27 10:49:19 +02:00
|
|
|
/** Define the targets of the action */
|
2016-10-24 09:34:13 +10:00
|
|
|
void setTargets( Targets targets );
|
2014-09-17 08:43:26 +02:00
|
|
|
/** Return availibity of action */
|
2017-05-01 16:42:33 +02:00
|
|
|
const Targets &targets() const;
|
2014-08-17 13:37:26 +02:00
|
|
|
|
2014-01-19 23:04:24 +11:00
|
|
|
signals:
|
2014-09-17 09:18:53 +02:00
|
|
|
/** Triggered when action has been run for a specific list of features */
|
2017-05-01 16:42:33 +02:00
|
|
|
void triggeredForFeatures( QgsMapLayer *layer, const QList<QgsFeature> &featureList );
|
2014-09-17 09:18:53 +02:00
|
|
|
|
2014-01-19 23:04:24 +11:00
|
|
|
/** Triggered when action has been run for a specific feature */
|
2017-05-01 16:42:33 +02:00
|
|
|
void triggeredForFeature( QgsMapLayer *layer, const QgsFeature &feature );
|
2014-01-19 23:04:24 +11:00
|
|
|
|
|
|
|
/** Triggered when action has been run for a specific layer */
|
2017-05-01 16:42:33 +02:00
|
|
|
void triggeredForLayer( QgsMapLayer *layer );
|
2014-01-19 23:04:24 +11:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-09-01 10:51:06 +02:00
|
|
|
QFlags<QgsMapLayerAction::Target> operator|(QgsMapLayerAction::Target f1, QFlags<QgsMapLayerAction::Target> f2);
|
|
|
|
|
2014-01-19 23:04:24 +11:00
|
|
|
class QgsMapLayerActionRegistry : QObject
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsmaplayeractionregistry.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
//! Returns the instance pointer, creating the object on the first call
|
2017-05-03 07:45:22 +02:00
|
|
|
static QgsMapLayerActionRegistry *instance();
|
2014-01-19 23:04:24 +11:00
|
|
|
|
|
|
|
~QgsMapLayerActionRegistry();
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Adds a map layer action to the registry*/
|
2017-05-03 07:45:22 +02:00
|
|
|
void addMapLayerAction( QgsMapLayerAction *action );
|
2014-01-19 23:04:24 +11:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the map layer actions which can run on the specified layer*/
|
2017-05-01 16:42:33 +02:00
|
|
|
QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer *layer, QgsMapLayerAction::Targets targets = QgsMapLayerAction::AllActions );
|
2014-01-19 23:04:24 +11:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Removes a map layer action from the registry*/
|
2014-01-19 23:04:24 +11:00
|
|
|
bool removeMapLayerAction( QgsMapLayerAction *action );
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets the default action for a layer*/
|
2017-05-01 16:42:33 +02:00
|
|
|
void setDefaultActionForLayer( QgsMapLayer *layer, QgsMapLayerAction *action );
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the default action for a layer*/
|
2017-05-03 07:45:22 +02:00
|
|
|
QgsMapLayerAction *defaultActionForLayer( QgsMapLayer *layer );
|
2014-01-19 23:04:24 +11:00
|
|
|
|
|
|
|
protected:
|
|
|
|
//! protected constructor
|
2017-05-03 07:45:22 +02:00
|
|
|
QgsMapLayerActionRegistry( QObject *parent = 0 );
|
2014-01-19 23:04:24 +11:00
|
|
|
|
|
|
|
signals:
|
|
|
|
/** Triggered when an action is added or removed from the registry */
|
|
|
|
void changed();
|
|
|
|
|
|
|
|
};
|