Skip to content

Commit

Permalink
Rename QgsAttributeAction to QgsActionManager
Browse files Browse the repository at this point in the history
The original name was not representative for the scope of the class
and misleading at best.
The class manages actions for a given layer and it's not a single action
like the former name suggested.
There is a typedef introduced to keep it in the API until we can remove
it with QGIS 3.
  • Loading branch information
m-kuhn committed May 2, 2016
1 parent ff4ad50 commit 2faaf1c
Show file tree
Hide file tree
Showing 28 changed files with 583 additions and 373 deletions.
2 changes: 2 additions & 0 deletions python/core/core.sip
Expand Up @@ -19,6 +19,8 @@
%Include qgis.sip

%Include qgsapplication.sip
%Include qgsaction.sip
%Include qgsactionmanager.sip
%Include qgsattributeaction.sip
%Include qgsbrowsermodel.sip
%Include qgsclipper.sip
Expand Down
60 changes: 60 additions & 0 deletions python/core/qgsaction.sip
@@ -0,0 +1,60 @@
/***************************************************************************
qgsaction.h - QgsAction

---------------------
begin : 18.4.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/** \ingroup core
* Utility class that encapsulates an action based on vector attributes.
*/
class QgsAction
{
%TypeHeaderCode
#include <qgsaction.h>
%End
public:
enum ActionType
{
Generic,
GenericPython,
Mac,
Windows,
Unix,
OpenUrl,
};

QgsAction( ActionType type, const QString& name, const QString& action, bool capture );

QgsAction( ActionType type, const QString& name, const QString& action, const QString& icon, bool capture );

//! The name of the action
QString name() const;

//! The path to the icon
QString iconPath() const;

//! The icon
QIcon icon() const;

//! The action
QString action() const;

//! The action type
ActionType type() const;

//! Whether to capture output for display when this action is run
bool capture() const;

//! Whether the action is runable on the current platform
bool runable() const;
};
134 changes: 134 additions & 0 deletions python/core/qgsactionmanager.sip
@@ -0,0 +1,134 @@
/***************************************************************************
qgsattributemanager.h

These classes store and control the managment and execution of actions
associated with a particular Qgis layer. Actions are defined to be
external programs that are run with user-specified inputs that can
depend on the contents of layer attributes.

-------------------
begin : Oct 24 2004
copyright : (C) 2004 by Gavin Macaulay
email : gavin at macaulay dot co dot nz
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/** \class QgsActionManager
* \brief Storage and management of actions associated with Qgis layer
* attributes.
*/

class QgsActionManager
{
%TypeHeaderCode
#include <qgsactionmanager.h>
%End
public:
//! Constructor
QgsActionManager( QgsVectorLayer *layer );

//! Destructor
virtual ~QgsActionManager();

/** Add an action with the given name and action details.
* Will happily have duplicate names and actions. If
* capture is true, when running the action using doAction(),
* any stdout from the process will be captured and displayed in a
* dialog box.
*/
void addAction( QgsAction::ActionType type, const QString& name, const QString& action, bool capture = false );

/** Add an action with the given name and action details.
* Will happily have duplicate names and actions. If
* capture is true, when running the action using doAction(),
* any stdout from the process will be captured and displayed in a
* dialog box.
*/
void addAction( QgsAction::ActionType type, const QString& name, const QString& action, const QString& icon, bool capture = false );

//! Remove an action at given index
void removeAction( int index );

/** Does the given values. defaultValueIndex is the index of the
* field to be used if the action has a $currfield placeholder.
* @note available in python bindings as doActionFeature
*/
void doAction( int index,
const QgsFeature &feat,
int defaultValueIndex = 0 ) /PyName=doActionFeature/;

/** Does the action using the expression builder to expand it
* and getting values from the passed feature attribute map.
* substitutionMap is used to pass custom substitutions, to replace
* each key in the map with the associated value
* @note available in python bindings as doActionFeatureWithSubstitution
*/
void doAction( int index,
const QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap ) /PyName=doActionFeatureWithSubstitution/;

//! Removes all actions
void clearActions();

//! List all actions
QList<QgsAction> listActions() const;

//! Return the layer
QgsVectorLayer* layer() const;

/** Expands the given action, replacing all %'s with the value as
* given.
*/
QString expandAction( QString action, const QMap<int, QVariant> &attributes, uint defaultValueIndex );

/** Expands the given action using the expression builder
* This function currently replaces each expression between [% and %]
* placeholders in the action with the result of its evaluation on
* the feature passed as argument.
*
* Additional substitutions can be passed through the substitutionMap
* parameter
*/
QString expandAction( const QString& action,
QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap = 0 );


//! Writes the actions out in XML format
bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;

//! Reads the actions in in XML format
bool readXML( const QDomNode& layer_node );

int size() const;
/**
* Get the action at the specified index.
*/
QgsAction at( int idx ) const;
/**
* Get the action at the specified index.
*/
QgsAction operator[]( int idx ) const;

/** @deprecated Initialize QgsPythonRunner instead
* @note not available in Python bindings
*/
// Q_DECL_DEPRECATED static void setPythonExecute( void ( * )( const QString & ) );

/**
* Get the index of the default action
*/
int defaultAction() const;
/**
* Set the index of the default action
*/
void setDefaultAction( int actionNumber );
};
164 changes: 24 additions & 140 deletions python/core/qgsattributeaction.sip
@@ -1,141 +1,25 @@
class QgsAction
{
%TypeHeaderCode
#include "qgsattributeaction.h"
%End

public:
enum ActionType
{
Generic,
GenericPython,
Mac,
Windows,
Unix,
OpenUrl,
};

QgsAction( ActionType type, const QString& name, const QString& action, bool capture );

//! The name of the action
QString name() const;

//! The path to the icon
const QString iconPath() const;

//! The icon
const QIcon icon() const;

//! The action
QString action() const;

//! The action type
ActionType type() const;

//! Whether to capture output for display when this action is run
bool capture() const;

//! Whether the action is runable on the current platform
bool runable() const;
};

/** \class QgsAttributeAction
* \brief Storage and management of actions associated with Qgis layer
* attributes.
/***************************************************************************
qgsactionmanager.h

This is a legacy header to keep backwards compatibility until QGIS 3.

-------------------
begin : Oct 24 2004
copyright : (C) 2004 by Gavin Macaulay
email : gavin at macaulay dot co dot nz
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* QgsAttributeAction is deprecated and has been replaced with
* QgsActionManager. This legacy typedef will be removed with QGIS 3.
*/

class QgsAttributeAction
{
%TypeHeaderCode
#include "qgsattributeaction.h"
%End
public:
//! Constructor
QgsAttributeAction( QgsVectorLayer *layer );

//! Destructor
virtual ~QgsAttributeAction();

/** Add an action with the given name and action details.
* Will happily have duplicate names and actions. If
* capture is true, when running the action using doAction(),
* any stdout from the process will be captured and displayed in a
* dialog box.
*/
void addAction( QgsAction::ActionType type, const QString& name, const QString& action, bool capture = false );

/** Add an action with the given name and action details.
* Will happily have duplicate names and actions. If
* capture is true, when running the action using doAction(),
* any stdout from the process will be captured and displayed in a
* dialog box.
*/
void addAction( QgsAction::ActionType type, const QString& name, const QString& action, const QString& icon, bool capture = false );

//! Remove an action at given index
void removeAction( int index );

/** Does the given values. defaultValueIndex is the index of the
* field to be used if the action has a $currfield placeholder.
* @note available in python bindings as doActionFeature
*/
void doAction( int index,
const QgsFeature &feat,
int defaultValueIndex = 0 ) /PyName=doActionFeature/;

/** Does the action using the expression builder to expand it
* and getting values from the passed feature attribute map.
* substitutionMap is used to pass custom substitutions, to replace
* each key in the map with the associated value
* @note available in python bindings as doActionFeatureWithSubstitution
*/
void doAction( int index,
const QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap ) /PyName=doActionFeatureWithSubstitution/;

//! Removes all actions
void clearActions();

//! List all actions
const QList<QgsAction>& listActions();

//! Return the layer
QgsVectorLayer *layer();

/** Expands the given action, replacing all %'s with the value as
* given.
*/
QString expandAction( QString action, const QMap<int, QVariant> &attributes, uint defaultValueIndex );

/** Expands the given action using the expression builder
* This function currently replaces each expression between [% and %]
* placeholders in the action with the result of its evaluation on
* the feature passed as argument.
*
* Additional substitutions can be passed through the substitutionMap
* parameter
*/
QString expandAction( const QString& action,
QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap = 0 );


//! Writes the actions out in XML format
bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;

//! Reads the actions in in XML format
bool readXML( const QDomNode& layer_node );

int size() const;
QgsAction &at( int idx );
QgsAction &operator[]( int idx );

/** @deprecated Initialize QgsPythonRunner instead
* @note not available in Python bindings
*/
// Q_DECL_DEPRECATED static void setPythonExecute( void ( * )( const QString & ) );

//! Whether the action is the default action
int defaultAction() const;
void setDefaultAction( int actionNumber );
};
typedef QgsActionManager QgsAttributeAction;

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson May 10, 2016

Collaborator

@m-kuhn does this work for you? It builds for me but QgsAttributeAction is not accessible from Python.

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn via email May 11, 2016

Author Member
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayer.sip
Expand Up @@ -278,7 +278,7 @@ class QgsVectorLayer : QgsMapLayer
*/
// const QgsLabel *label() const;

QgsAttributeAction *actions();
QgsActionManager *actions();

/**
* The number of features that are selected in this layer
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgsidentifymenu.sip
Expand Up @@ -47,7 +47,7 @@ class QgsIdentifyMenu : QMenu
/**
* @brief define if attribute actions(1) and map layer actions(2) can be listed and run from the menu
* @note custom actions will be shown in any case if they exist.
* @note (1) attribute actions are defined by the user in the layer properties @see QgsAttributeAction
* @note (1) attribute actions are defined by the user in the layer properties @see QgsActionManager
* @note (2) map layer actions are built-in c++ actions or actions which are defined by a python plugin @see QgsMapLayerActionRegistry
*/
void setShowFeatureActions( bool showFeatureActions );
Expand Down

0 comments on commit 2faaf1c

Please sign in to comment.