QGIS/python/core/auto_generated/qgsactionmanager.sip.in

147 lines
4.2 KiB
Plaintext
Raw Normal View History

2017-04-02 11:04:39 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsactionmanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
[FEATURE] layer refresh and trigger actions on provider notification [needs-docs] In vector layer properties (only usefull for postgres datasources) **in the rendering tab** A "Refresh layer on notification" checkbox has been added to refresh layer on provider notification. For a postgres datasource, if a `NOTIFY qgis;` command is issued by one of the database clients, a refresh of the layer will occur. If the "Only if message is" checkbox is checked, the notification will trigger the refresh only if the message contend is the one specified, e.g. if the user enters "refresh" in the box right next to the "Only if message is" checkbox, then a `NOTIFY qgis, 'refresh';` command in the datatabase will trigger a layer refresh, but `NOTIFY qgis;` or `NOTIFY qgis, 'something else';` won't. **in the actions tab** A column "On notification" has been added, the action editor widget a has text field "Execute if notification message matches" to specify a filter for notification from the provider. The filter is a Perl-type regex. Note that, as opposed to the "layer refresh" that Exemple: - QGIS side "Execute if notification message matches" `^trigger my action` - Postgres side: `NOTIFY qgis, 'trigger my action'` will trigger the action - Postgres side: `NOTIFY qgis, 'trigger my action some additional data'` will trigger the action - Postgres side: `NOTIFY qgis, 'do not trigger my action some additional data'` will NOT trigger the action Please note that if the `^`, which means "starts with", in `^trigger my action` had been ommited, the last notification would have triggered the action because the notification message contains the `trigger my action` A new qgis variable `notification_message` is available for use in actions, it holds the contend of the notification message. To continue with the previous exemple, if the action is of python type with the code: ```python print('[% @notification_message %]') ``` The three notifictions above will result in two printed lines ``` trigger my action trigger my action some additional data ``` User Warning: For postgres providers, if the "Refresh layer on notification" is checked, or if one layer action has "On notification" specified, a new connection to the database is made to listen to postgres notifications. This olds even if transaction groups are enabled at the project level. Note that once the notification mechanism is started in a QGIS session, it will not stop, even if there is no more need for it (Refresh layer on notification" unchecked and no "On notification" in any action). Consequently the connection listening to notification will remain open. IMPLEMENTATION DETAILS: A notify signal has been added to the abstract QgsVectorDataProvider along with a setListening function that enables/disble the notification mechanism. For the moment only the postgres provider implements the notification. QgsAction has a notificationMessage member function that holds the regex to match to trigger action QgsActionManager becomes a QObject and is doing the filtering and execute actions on notifications. The notification notion extends beyond SRGBD servers (postgres and oracle at least have the notify) and the "watch file" in the delimitedtext provider could also benefit from this interface. For the postgres provider a thread is created with a second connection to the database. This thread is responsible for listening postgres notifications. It would be nice to avoid the creation of one listening chanel per provider in the case transaction groups are enabled. Please note that when listening starts (a thread and connection is created in the postgres provider) it cannot be stopped by removing the connected actions or unchecking the refresh check box. Indeed, since we don't know who needs the signals, we dont't want to stop the service. The service will not restart in the next qgis session though. If this behavior is not deemed appropriate, we could use ``` int QObject::receivers ( const char * signal ) const ``` and have QgsDataProvider::setListening return a bool to tell the caller if the signal has actually been closed.
2017-09-08 16:42:30 +02:00
class QgsActionManager: QObject
{
%Docstring
2017-12-15 10:36:55 -04:00
Storage and management of actions associated with a layer.
2017-12-15 10:36:55 -04:00
Actions can trigger custom code or applications to be executed
based on attributes of a given feature.
%End
2017-04-02 11:04:39 +02:00
%TypeHeaderCode
2017-04-02 11:04:39 +02:00
#include "qgsactionmanager.h"
%End
public:
QgsActionManager( QgsVectorLayer *layer );
2017-04-02 11:04:39 +02:00
%Docstring
Constructor
%End
2017-04-02 11:04:39 +02:00
QUuid addAction( QgsAction::ActionType type, const QString &name, const QString &command, bool capture = false );
%Docstring
2017-12-15 10:36:55 -04:00
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.
2017-04-02 11:04:39 +02:00
%End
QUuid addAction( QgsAction::ActionType type, const QString &name, const QString &command, const QString &icon, bool capture = false );
%Docstring
2017-12-15 10:36:55 -04:00
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.
2017-04-02 11:04:39 +02:00
%End
void addAction( const QgsAction &action );
%Docstring
2017-12-15 10:36:55 -04:00
Add a new action to this list.
2017-04-02 11:04:39 +02:00
%End
void removeAction( QUuid actionId );
2017-04-02 11:04:39 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Remove an action by its id.
2017-04-02 11:04:39 +02:00
.. versionadded:: 3.0
%End
void doAction( QUuid actionId, const QgsFeature &feature, int defaultValueIndex = 0, const QgsExpressionContextScope &scope = QgsExpressionContextScope() ) /PyName=doActionFeature/;
2017-04-02 11:04:39 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Does the given action.
2017-12-15 10:36:55 -04:00
:param actionId: action id
:param feature: feature to run action for
:param defaultValueIndex: index of the field to be used if the action has a $currfield placeholder.
:param scope: expression context scope to add during expression evaluation
2017-04-02 11:04:39 +02:00
.. note::
2017-04-03 09:03:30 +10:00
available in Python bindings as doActionFeature
2017-04-02 11:04:39 +02:00
%End
void doAction( QUuid actionId, const QgsFeature &feature, const QgsExpressionContext &context );
2017-04-02 11:04:39 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Does the action using the expression engine to replace any embedded expressions
in the action definition.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param actionId: action id
:param feature: feature to run action for
:param context: expression context to evaluate expressions under
2017-04-02 11:04:39 +02:00
%End
void clearActions();
2017-04-02 11:04:39 +02:00
%Docstring
Removes all actions
%End
QList<QgsAction> actions( const QString &actionScope = QString() ) const;
%Docstring
Returns a list of actions that are available in the given action scope.
2017-12-15 10:36:55 -04:00
If no action scope is provided, all actions will be returned.
2017-04-02 11:04:39 +02:00
.. versionadded:: 3.0
%End
QgsVectorLayer *layer() const;
%Docstring
Returns the layer
2017-04-02 11:04:39 +02:00
%End
bool writeXml( QDomNode &layer_node ) const;
%Docstring
Writes the actions out in XML format
%End
bool readXml( const QDomNode &layer_node );
%Docstring
Reads the actions in in XML format
%End
QgsAction action( QUuid id );
2017-04-02 11:04:39 +02:00
%Docstring
Gets an action by its id.
2017-12-15 10:36:55 -04:00
2017-04-02 11:04:39 +02:00
.. versionadded:: 3.0
%End
void setDefaultAction( const QString &actionScope, QUuid actionId );
2017-04-02 11:04:39 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Each scope can have a default action. This will be saved in the project
file.
2017-04-02 11:04:39 +02:00
.. versionadded:: 3.0
%End
QgsAction defaultAction( const QString &actionScope );
%Docstring
2017-12-15 10:36:55 -04:00
Each scope can have a default action. This will be saved in the project
file.
2017-04-02 11:04:39 +02:00
.. versionadded:: 3.0
%End
};
2017-04-02 11:04:39 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsactionmanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/