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.
|
2016-10-24 09:34:13 +10: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
|
2016-10-24 09:34:13 +10: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
|
2016-10-24 09:34:13 +10: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 */
|
|
|
|
bool canRunUsingLayer( QgsMapLayer* layer ) const;
|
|
|
|
|
2014-09-17 09:18:53 +02:00
|
|
|
/** Triggers the action with the specified layer and list of feature. */
|
2015-10-07 11:55:34 +11: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. */
|
|
|
|
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. */
|
2014-01-19 23:04:24 +11:00
|
|
|
void triggerForLayer( QgsMapLayer* layer );
|
|
|
|
|
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 */
|
2014-09-01 16:45:54 +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 */
|
2015-10-26 22:46:25 +11: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 */
|
2014-09-17 08:43:26 +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 */
|
|
|
|
void triggeredForLayer( QgsMapLayer* layer );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
static QgsMapLayerActionRegistry * instance();
|
|
|
|
|
|
|
|
~QgsMapLayerActionRegistry();
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Adds a map layer action to the registry*/
|
2014-01-19 23:04:24 +11:00
|
|
|
void addMapLayerAction( QgsMapLayerAction * action );
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the map layer actions which can run on the specified layer*/
|
2016-10-24 09:34:13 +10: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*/
|
2014-01-19 23:04:24 +11:00
|
|
|
void setDefaultActionForLayer( QgsMapLayer* layer, QgsMapLayerAction* action );
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the default action for a layer*/
|
2014-01-19 23:04:24 +11:00
|
|
|
QgsMapLayerAction * defaultActionForLayer( QgsMapLayer* layer );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
//! protected constructor
|
|
|
|
QgsMapLayerActionRegistry( QObject * parent = 0 );
|
|
|
|
|
|
|
|
signals:
|
|
|
|
/** Triggered when an action is added or removed from the registry */
|
|
|
|
void changed();
|
|
|
|
|
|
|
|
};
|