2017-04-02 11:04:39 +02:00
|
|
|
/************************************************************************
|
|
|
|
* This file has been generated automatically from *
|
|
|
|
* *
|
|
|
|
* src/core/qgsaction.h *
|
|
|
|
* *
|
|
|
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-18 17:32:58 +02:00
|
|
|
class QgsAction
|
|
|
|
{
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Utility class that encapsulates an action based on vector attributes.
|
2017-04-02 11:04:39 +02:00
|
|
|
%End
|
|
|
|
|
2016-04-18 17:32:58 +02:00
|
|
|
%TypeHeaderCode
|
2017-04-02 11:04:39 +02:00
|
|
|
#include "qgsaction.h"
|
2016-04-18 17:32:58 +02:00
|
|
|
%End
|
|
|
|
public:
|
|
|
|
enum ActionType
|
|
|
|
{
|
|
|
|
Generic,
|
|
|
|
GenericPython,
|
|
|
|
Mac,
|
|
|
|
Windows,
|
|
|
|
Unix,
|
|
|
|
OpenUrl,
|
|
|
|
};
|
|
|
|
|
2016-11-03 22:48:19 +01:00
|
|
|
QgsAction();
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Default constructor
|
2017-04-02 11:04:39 +02:00
|
|
|
%End
|
2017-04-26 08:22:27 +02:00
|
|
|
|
2017-04-02 11:04:39 +02:00
|
|
|
QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false );
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Create a new QgsAction
|
2017-04-02 11:04:39 +02:00
|
|
|
|
2017-12-15 10:36:55 -04:00
|
|
|
:param type: The type of this action
|
|
|
|
:param description: A human readable description string
|
|
|
|
:param command: The action text. Its interpretation depends on the type
|
|
|
|
:param capture: If this is set to true, the output will be captured when an action is run
|
2018-02-25 08:21:52 +10:00
|
|
|
:param enabledOnlyWhenEditable: if true then action is only enable in editmode
|
2017-04-02 11:04:39 +02:00
|
|
|
%End
|
2017-04-26 08:22:27 +02:00
|
|
|
|
[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
|
|
|
QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString ¬ificationMessage = QString() );
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Create a new QgsAction
|
2017-04-02 11:04:39 +02:00
|
|
|
|
2017-12-15 10:36:55 -04:00
|
|
|
:param type: The type of this action
|
|
|
|
:param description: A human readable description string
|
|
|
|
:param action: The action text. Its interpretation depends on the type
|
|
|
|
:param icon: Path to an icon for this action
|
|
|
|
:param capture: If this is set to true, the output will be captured when an action is run
|
|
|
|
:param shortTitle: A short string used to label user interface elements like buttons
|
|
|
|
:param actionScopes: A set of scopes in which this action will be available
|
|
|
|
:param notificationMessage: A particular message which reception will trigger the action
|
2018-02-25 08:21:52 +10:00
|
|
|
:param enabledOnlyWhenEditable: if true then action is only enable in editmode
|
2017-04-02 11:04:39 +02:00
|
|
|
%End
|
2017-04-26 08:22:27 +02:00
|
|
|
|
2016-04-18 17:32:58 +02:00
|
|
|
QString name() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
|
|
|
The name of the action. This may be a longer description.
|
|
|
|
%End
|
2016-04-18 17:32:58 +02:00
|
|
|
|
2016-04-29 13:22:11 +02:00
|
|
|
QString shortTitle() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
|
|
|
The short title is used to label user interface elements like buttons
|
|
|
|
%End
|
2016-04-29 13:22:11 +02:00
|
|
|
|
2016-11-03 22:48:19 +01:00
|
|
|
QUuid id() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Returns a unique id for this action.
|
|
|
|
|
2017-04-02 11:04:39 +02:00
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
2016-11-03 19:11:51 +01:00
|
|
|
|
2016-11-03 22:48:19 +01:00
|
|
|
bool isValid() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Returns true if this action was a default constructed one.
|
|
|
|
|
2017-04-02 11:04:39 +02:00
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
2016-11-03 19:11:51 +01:00
|
|
|
|
2016-04-18 17:32:58 +02:00
|
|
|
QString iconPath() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
|
|
|
The path to the icon
|
|
|
|
%End
|
2016-04-18 17:32:58 +02:00
|
|
|
|
|
|
|
QIcon icon() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
|
|
|
The icon
|
|
|
|
%End
|
2016-04-18 17:32:58 +02:00
|
|
|
|
2016-10-31 15:30:29 +01:00
|
|
|
QString command() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Returns the command that is executed by this action.
|
|
|
|
How the content is interpreted depends on the type() and
|
|
|
|
the actionScope().
|
|
|
|
|
[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
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
|
|
|
|
|
|
|
QString notificationMessage() const;
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Returns the notification message that triggers the action
|
|
|
|
|
2017-04-02 11:04:39 +02:00
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
2016-04-18 17:32:58 +02:00
|
|
|
|
|
|
|
ActionType type() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
|
|
|
The action type
|
|
|
|
%End
|
2016-04-18 17:32:58 +02:00
|
|
|
|
|
|
|
bool capture() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
|
|
|
Whether to capture output for display when this action is run
|
|
|
|
%End
|
2016-04-18 17:32:58 +02:00
|
|
|
|
2018-02-25 08:21:52 +10:00
|
|
|
|
|
|
|
bool isEnabledOnlyWhenEditable() const;
|
|
|
|
%Docstring
|
|
|
|
Return whether only enabled in editable mode
|
|
|
|
%End
|
|
|
|
|
|
|
|
|
2016-04-18 17:32:58 +02:00
|
|
|
bool runable() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
|
|
|
Checks if the action is runable on the current platform
|
|
|
|
%End
|
|
|
|
|
|
|
|
void run( QgsVectorLayer *layer, const QgsFeature &feature, const QgsExpressionContext &expressionContext ) const;
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Run this action.
|
2017-04-02 11:04:39 +02:00
|
|
|
|
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
|
|
|
|
|
|
|
void run( const QgsExpressionContext &expressionContext ) const;
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Run this action.
|
2017-04-02 11:04:39 +02:00
|
|
|
|
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
2016-10-31 15:30:29 +01:00
|
|
|
|
|
|
|
QSet<QString> actionScopes() const;
|
2017-04-02 11:04:39 +02:00
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
The action scopes define where an action will be available.
|
|
|
|
Action scopes may offer additional variables like the clicked
|
|
|
|
coordinate.
|
|
|
|
|
2017-12-05 20:04:14 -04:00
|
|
|
.. seealso:: :py:class:`QgsActionScope`
|
2017-12-15 10:36:55 -04:00
|
|
|
|
2017-04-02 11:04:39 +02:00
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
|
|
|
|
|
|
|
void setActionScopes( const QSet<QString> &actionScopes );
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
The action scopes define where an action will be available.
|
|
|
|
Action scopes may offer additional variables like the clicked
|
|
|
|
coordinate.
|
2017-04-02 11:04:39 +02:00
|
|
|
|
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
|
|
|
|
|
|
|
void readXml( const QDomNode &actionNode );
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Reads an XML definition from actionNode
|
|
|
|
into this object.
|
2017-04-02 11:04:39 +02:00
|
|
|
|
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
|
|
|
|
|
|
|
void writeXml( QDomNode &actionsNode ) const;
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Appends an XML definition for this action as a new
|
|
|
|
child node to actionsNode.
|
2017-04-02 11:04:39 +02:00
|
|
|
|
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
2016-10-31 15:30:29 +01:00
|
|
|
|
2017-11-10 15:01:08 +00:00
|
|
|
void setExpressionContextScope( const QgsExpressionContextScope &scope );
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Sets an expression context scope to use for running the action.
|
2017-11-10 15:01:08 +00:00
|
|
|
|
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
|
|
|
|
|
|
|
QgsExpressionContextScope expressionContextScope() const;
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Returns an expression context scope used for running the action.
|
|
|
|
|
2017-11-10 15:01:08 +00:00
|
|
|
.. versionadded:: 3.0
|
|
|
|
%End
|
|
|
|
|
2016-04-18 17:32:58 +02:00
|
|
|
};
|
2017-04-02 11:04:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* This file has been generated automatically from *
|
|
|
|
* *
|
|
|
|
* src/core/qgsaction.h *
|
|
|
|
* *
|
|
|
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
|
|
|
************************************************************************/
|