def __init__(self, data: dict, iface: QgisInterface, is_background: bool, alternate_mode: bool = False): # debug for i, v in data.items(): if i in ('qml', 'contacts'): continue if i == 'sublayers': for sublayer in data['sublayers']: for j, u in sublayer.items(): if j in ('qml', 'contacts'): continue dbg_info('*** sublayer {}: {}'.format(j, u)) else: dbg_info('*** {}: {}'.format(i, v)) data = self.reformat_data(data) settings = Settings() loading_mode: LoadingMode = settings.value( 'default_layer_loading_mode') if alternate_mode: loading_mode = loading_mode.alternate_mode() if is_background: loading_mode = LoadingMode.WMS root = iface.layerTreeView().model().rootGroup() pos = len(root.children()) insertion_point = InsertionPoint(root, pos) else: try: insertion_point = iface.layerTreeInsertionPoint() except AttributeError: # backward compatibility for QGIS < 3.10 # TODO: remove insertion_point = layerTreeInsertionPoint( iface.layerTreeView()) dbg_info("insertion point: {} {}".format(insertion_point.group.name(), insertion_point.position)) loading_options = LoadingOptions( wms_load_separate=settings.value('wms_load_separate'), wms_image_format=settings.value('wms_image_format'), loading_mode=loading_mode, pg_auth_id=settings.value('pg_auth_id'), pg_service=settings.value('pg_service')) data.load(insertion_point, loading_options)
def __init__(self, data: dict, iface: QgisInterface, is_background: bool, alternate_mode: bool = False): # debug for i, v in data.items(): if i in ('qml', 'contacts'): continue if i == 'sublayers': for sublayer in data['sublayers']: for j, u in sublayer.items(): if j in ('qml', 'contacts'): continue dbg_info('*** sublayer {}: {}'.format(j, u)) else: dbg_info('*** {}: {}'.format(i, v)) data = self.reformat_data(data, is_background) settings = Settings() loading_mode: LoadingMode = settings.value( 'default_layer_loading_mode') if alternate_mode: loading_mode = loading_mode.alternate_mode() if force_wms(data, is_background): loading_mode = LoadingMode.WMS # if background, insert at bottom of layer tree if is_background: root = QgsProject.instance().layerTreeRoot() pos = len(root.children()) insertion_point = QgsLayerTreeRegistryBridge.InsertionPoint( root, pos) else: insertion_point = iface.layerTreeInsertionPoint() dbg_info("insertion point: {} {}".format(insertion_point.group.name(), insertion_point.position)) loading_options = LoadingOptions( wms_load_separate=settings.value('wms_load_separate'), wms_image_format=settings.value('wms_image_format'), loading_mode=loading_mode, pg_auth_id=settings.value('pg_auth_id'), pg_service=PG_SERVICE) data.load(insertion_point, loading_options)