def vector_layer(self): """ Returns a QgsVectorLayer based on the configuration information specified in the mapper including the system-wide data connection properties. """ from stdm.data import vector_layer if self._dbModel is None: msg = QApplication.translate("ForeignKeyMapper", "Primary database model object not defined.") return None, msg filter_layer = vector_layer(self._ds_name) if filter_layer is None: msg = QApplication.translate("ForeignKeyMapper", "Vector layer could not be constructed from the database table.") return None, msg if not filter_layer.isValid(): trans_msg = QApplication.translate("ForeignKeyMapper", u"The vector layer for '{0}' table is invalid.") msg = trans_msg.format(self._ds_name) return None, msg return filter_layer, ""
def load_table_layers(config_collection): """ In order to be able to use attribute tables in the composition, the corresponding vector layers need to be added to the layer registry. This method creates vector layers from the linked tables in the configuration items. This is required prior to creating the composition from file. :param config_collection: Table configuration collection built from the template file. :type config_collection: TableConfigurationCollection :returns: Valid layers that have been successfully added to the registry. :rtype: list """ table_configs = config_collection.items().values() v_layers = [] for conf in table_configs: layer_name = conf.linked_table() v_layer = vector_layer(layer_name) if v_layer is None: return if not v_layer.isValid(): return v_layers.append(v_layer) QgsMapLayerRegistry.instance().addMapLayers(v_layers, False) return v_layers
def set_table_vector_layer(self, table_name): """ Creates a vector layer and appends it to the composer table item. :param table_name: Name of the linked table containing tabular information. :type table_name: str """ self._notif_bar.clear() if not table_name: return v_layer = vector_layer(table_name) if v_layer is None: msg = QApplication.translate("ComposerTableDataSourceEditor", "A vector layer could not be created from the table.") self._notif_bar.insertErrorNotification(msg) return if not v_layer.isValid(): msg = QApplication.translate("ComposerTableDataSourceEditor", "Invalid vector layer, the table will not be added.") self._notif_bar.insertErrorNotification(msg) return #No need to add the layer in the legend QgsMapLayerRegistry.instance().addMapLayer(v_layer, False) self._composer_table_item.setVectorLayer(v_layer) self._composer_table_item.update()