Qgis db notify channel - Giswater/giswater_dbmodel GitHub Wiki

Giswater has implemented a notification system, which allows communication between database and python in order tu refresh layers on QGIS. It consists of a configuration made on sys_table, field notify_action and a trigger gw_trg_notify, which manages the notification process.

Here there are two examples of tables and it's notify_action:

  • ext_streetaxis: [{"channel":"desktop","name":"refresh_attribute_table", "enabled":"true", "trg_fields":"id","featureType":["arc", "node", "connec","v_ext_plot","v_ext_address"]}]
  • node:[{"channel":"user","name":"set_layer_index", "enabled":"true", "trg_fields":"the_geom","featureType":["arc"]}]

Basically there are two channels of communication: desktop, where information about refreshing the data is being send and user, which activates reseting the index of layer. After a change on field defined as trg_fields the information is being send to python that date needs to be refresh so that comboboxes, tables and layers has all newly inserted or modified data.

Json key explanation:

Key Description Example
channel Notification channel "channel":"desktop"
name Name of the action activated by the notification "name":"refresh_attribute_table"
enabled If true, notification is being used "enabled":"true"
trg_fields Inserting, updating or deleting of which field of the table activates the notification "trg_fields":"id"
featureType List of tables or views which are affected (refreshed) by the notification. If value is arc, node, connec or gully all the parent and chil layers are being refreshed, other layers must be called by their names "featureType":["arc", "node", "connec","v_ext_plot","v_ext_address"]

After configurating the layers it's important to execute a function gw_fct_admin_manage_triggers('notify',null), which creates triggers on each table listed on sys_table that has a value of notify_action. It's being created based on keys trg_fields and featureType of the json. What this trigger does is executing a pg_notify function that gives a signal to python about the changes of data.