15 Commits

Author SHA1 Message Date
Vincent Mora
02e3916bf5 [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-22 12:51:51 +02:00
Matthias Kuhn
28a21209b9 [sipify] seealso 2017-04-30 16:52:05 +02:00
Denis Rouzaud
45266cd03e [sipify] improvements
* add In annotation
 * remove struct forward declarations
 * fix members initialization list in header
 * merge removal code for function bodies and constructor definition
2017-04-26 10:25:50 +02:00
Denis Rouzaud
1bfa539df1 [sipify] remove extra blank line 2017-04-24 07:39:30 +02:00
Denis Rouzaud
8f2a5c7c00 sipify all 2017-04-20 14:21:36 +02:00
Nyall Dawson
bfd37e1122 [sipify] Add return types for functions in docstrings
and change \return -> :return: in docystrings
2017-04-08 09:48:48 +10:00
Nyall Dawson
9b3539ab07 Update sip files 2017-04-03 13:18:36 +10:00
Matthias Kuhn
f4f45bf6c6 Autogenerate more sip files 2017-04-02 23:37:17 +02:00
Matthias Kuhn
a6eb7b6281 Convert action ids to uuid 2016-11-16 09:33:19 +01:00
Matthias Kuhn
08d350c0cb Fix bindings and docs 2016-11-16 09:33:19 +01:00
Matthias Kuhn
5b4a88f8e0 [feature] Add layer scoped actions
Within the attribute table, there is a new button to trigger actions
which are not based on individual features but instead on the whole layer.
Normally they will perform actions based on all features or the selection.

In addition to this, a lot of cleanup has been done.
2016-11-16 09:33:19 +01:00
Juergen E. Fischer
840022d772 fix indentation and some typos 2016-06-02 21:29:35 +02:00
Matthias Kuhn
8b4cb049ae Allow controlling action visibility on attribute table 2016-05-02 18:25:58 +02:00
Matthias Kuhn
f03a94f650 Fix crash 2016-05-02 18:25:58 +02:00
Matthias Kuhn
2faaf1cd9c Rename QgsAttributeAction to QgsActionManager
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.
2016-05-02 18:25:57 +02:00