def setValuesFromQSettings(self): """ """ # URL of the file self.config_file_url_edit.blockSignals(True) self.config_file_url_edit.setText( GpicGlobals.Instance().CONFIG_FILE_URLS[0]) self.config_file_url_edit.setCursorPosition(0) self.config_file_url_edit.blockSignals(False) # Download the file at startup self.download_cb.blockSignals(True) self.download_cb.setChecked( GpicGlobals.Instance().CONFIG_FILES_DOWNLOAD_AT_STARTUP) self.download_cb.blockSignals(False) # Hide resources with a warn flag self.hide_resources_with_warn_status_cb.blockSignals(True) self.hide_resources_with_warn_status_cb.setChecked( GpicGlobals.Instance().HIDE_RESOURCES_WITH_WARN_STATUS) self.hide_resources_with_warn_status_cb.blockSignals(False) # Hide empty groups in the resources tree self.hide_empty_groups_cb.blockSignals(True) self.hide_empty_groups_cb.setChecked( GpicGlobals.Instance().HIDE_EMPTY_GROUPS) self.hide_empty_groups_cb.blockSignals(False)
def evaluateFlags(self): """ """ # Detect modifications fileUrlChanged = (self.config_file_url_edit.text() != GpicGlobals.Instance().CONFIG_FILE_URLS[0]) downloadAtStartupChanged = ( self.download_cb.isChecked() != (GpicGlobals.Instance().CONFIG_FILES_DOWNLOAD_AT_STARTUP)) hideResourcesWithWarnStatusChanged = ( self.hide_resources_with_warn_status_cb.isChecked() != (GpicGlobals.Instance().HIDE_RESOURCES_WITH_WARN_STATUS)) hideEmptyGroupsChanged = (self.hide_empty_groups_cb.isChecked() != (GpicGlobals.Instance().HIDE_EMPTY_GROUPS)) # Init flags self.needUpdateVisibilityOfTreeItems = hideEmptyGroupsChanged or hideResourcesWithWarnStatusChanged self.needUpdateOfTreeContents = fileUrlChanged self.needSave = fileUrlChanged or downloadAtStartupChanged or hideResourcesWithWarnStatusChanged or hideEmptyGroupsChanged # Update state of the Apply Button self.buttonBox.button(QtGui.QDialogButtonBox.Apply).setEnabled( self.needSave)
def __init__(self): """ """ # Folder icon QgsApplication.initQgis() style = QgsApplication.style() self.folder_icon = QtGui.QIcon() self.folder_icon.addPixmap(style.standardPixmap(QtGui.QStyle.SP_DirClosedIcon), QtGui.QIcon.Normal, QtGui.QIcon.Off) warn_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path, GpicGlobals.Instance().ICON_WARN_FILE_NAME) self.warn_icon = QtGui.QIcon(warn_icon_path) wms_layer_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path, GpicGlobals.Instance().ICON_WMS_LAYER_FILE_NAME) self.wms_layer_icon = QtGui.QIcon(wms_layer_icon_path) wms_style_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path, GpicGlobals.Instance().ICON_WMS_STYLE_FILE_NAME) self.wms_style_icon = QtGui.QIcon(wms_style_icon_path) wfs_layer_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path, GpicGlobals.Instance().ICON_WFS_LAYER_FILE_NAME) self.wfs_layer_icon = QtGui.QIcon(wfs_layer_icon_path) raster_layer_icon_path = os.path.join(GpicGlobals.Instance().images_dir_path, GpicGlobals.Instance().ICON_RASTER_LAYER_FILE_NAME) self.raster_layer_icon = QtGui.QIcon(raster_layer_icon_path)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) mainLayout = QtGui.QVBoxLayout() logo_file_path = GpicGlobals.Instance().geopic_logo_file_path self.logo = QtGui.QLabel() self.logo.setPixmap(QtGui.QPixmap(logo_file_path)) mainLayout.addWidget(self.logo) title = u"À propos de l'extension Géo2France…" description = u"""Extension pour QGIS donnant un accès simplifié aux ressources géographiques utiles aux partenaires de GéoPicardie Version {0} Plus d'informations à l'adresse suivante : {1} """.format(GpicGlobals.Instance().PLUGIN_VERSION, GpicGlobals.Instance().PLUGIN_SOURCE_REPOSITORY) self.textArea = QtGui.QTextEdit() self.textArea.setReadOnly(True) self.textArea.setText(description) self.textArea.setFrameShape(QtGui.QFrame.NoFrame) mainLayout.addWidget(self.textArea) self.setModal(True) self.setSizeGripEnabled(False) self.setLayout(mainLayout) self.setFixedSize(400, 250) self.setWindowTitle(title)
def updateVisibilityOfTreeItems(self): """ Update the visibility of tree items: - visibility of empty groups - visibility of items with status = warn """ hide_items_with_warn_status = GpicGlobals.Instance( ).HIDE_RESOURCES_WITH_WARN_STATUS hide_empty_groups = GpicGlobals.Instance().HIDE_EMPTY_GROUPS def updateVisibilityOfSubitems(item, hide_empty_groups, hide_items_with_warn_status): if hasattr(item, "gpic_data" ) and item.gpic_data.status == GpicGlobals.Instance( ).NODE_STATUS_WARN: item.setHidden(hide_items_with_warn_status) child_count = item.childCount() if child_count > 0: for i in range(child_count): sub_item = item.child(i) if sub_item.isAnEmptyGroup(): sub_item.setHidden(hide_empty_groups) updateVisibilityOfSubitems(sub_item, hide_empty_groups, hide_items_with_warn_status) updateVisibilityOfSubitems(self.invisibleRootItem(), hide_empty_groups, hide_items_with_warn_status)
def __init__(self, title, node_type=GpicGlobals.Instance().NODE_TYPE_WFS_FEATURE_TYPE, description=None, status=None, metadata_url=None, params=None, parent_node=None): """ """ FavoritesTreeNode.__init__(self, title, node_type, description, status, metadata_url, params, parent_node) self.service_url = params.get("url") self.feature_type_name = params.get("name") self.filter = params.get("filter") self.wfs_version = params.get("version", "1.0.0") self.layer_srs = params.get("srs") self.can_be_added_to_map = True # Icon gpicIcons = GpicIcons.Instance() self.icon = gpicIcons.wfs_layer_icon if self.status == GpicGlobals.Instance().NODE_STATUS_WARN: self.icon = gpicIcons.warn_icon
def __init__(self, title, node_type=GpicGlobals.Instance().NODE_TYPE_WMTS_LAYER, description=None, status=None, metadata_url=None, params=None, parent_node=None): """ """ FavoritesTreeNode.__init__(self, title, node_type, description, status, metadata_url, params, parent_node) self.service_url = params.get("url") self.layer_tilematrixset_name = params.get("tilematrixset_name") self.layer_name = params.get("name") self.layer_format = params.get("format") self.layer_srs = params.get("srs") self.layer_style_name = params.get("style", "") self.can_be_added_to_map = True # Icon gpicIcons = GpicIcons.Instance() self.icon = gpicIcons.wms_style_icon if self.status == GpicGlobals.Instance().NODE_STATUS_WARN: self.icon = gpicIcons.warn_icon
def downloadResourcesTreeFile(file_url): """ Download the resources tree file """ try: # Download the config file http_req = urllib2.Request(file_url) http_req.add_header("Cache-Control", "no-cache") config_file = urllib2.urlopen(http_req) with open(GpicGlobals.Instance().config_file_path, 'wb') as f: f.write(config_file.read()) except Exception as e: short_message = u"Le téléchargement du fichier de configuration du plugin {0} a échoué.".format( GpicGlobals.Instance().PLUGIN_TAG) GpicGlobals.Instance().iface.messageBar().pushMessage( "Erreur", short_message, level=QgsMessageBar.CRITICAL) long_message = u"{0}\nUrl du fichier : {1}\n{2}\n{3}".format( short_message, file_url, e.__doc__, e.message) QgsMessageLog.logMessage(long_message, tag=GpicGlobals.Instance().PLUGIN_TAG, level=QgsMessageLog.CRITICAL)
def restoreDefaultsButtonClicked(self): """ """ # URL of the file self.config_file_url_edit.blockSignals(True) self.config_file_url_edit.setText( GpicGlobals.Instance().getQgisSettingDefaultValue( "CONFIG_FILE_URLS")[0]) self.config_file_url_edit.setCursorPosition(0) self.config_file_url_edit.blockSignals(False) # Download the file at startup self.download_cb.blockSignals(True) self.download_cb.setChecked( GpicGlobals.Instance().getQgisSettingDefaultValue( "CONFIG_FILES_DOWNLOAD_AT_STARTUP")) self.download_cb.blockSignals(False) # Hide resources with a warn flag self.hide_resources_with_warn_status_cb.blockSignals(True) self.hide_resources_with_warn_status_cb.setChecked( GpicGlobals.Instance().getQgisSettingDefaultValue( "HIDE_RESOURCES_WITH_WARN_STATUS")) self.hide_resources_with_warn_status_cb.blockSignals(False) # Hide empty groups in the resources tree self.hide_empty_groups_cb.blockSignals(True) self.hide_empty_groups_cb.setChecked( GpicGlobals.Instance().getQgisSettingDefaultValue( "HIDE_EMPTY_GROUPS")) self.hide_empty_groups_cb.blockSignals(False) self.evaluateFlags()
def needDownloadResourcesTreeFile(self): """ Do we need to download a new version of the resources tree file? 2 possible reasons: - the user wants it to be downloading at plugin start up - the file is currently missing """ return (GpicGlobals.Instance().CONFIG_FILES_DOWNLOAD_AT_STARTUP > 0 or not os.path.isfile(GpicGlobals.Instance().config_file_path))
def runAddToMapAction(self): """ Add the WMS layer with the specified style to the map """ qgis_layer_details = self.getQgisLayerDetails() GpicGlobals.Instance().iface.addRasterLayer( qgis_layer_details["uri"], qgis_layer_details["title"], qgis_layer_details["provider"])
def downloadFileNow(self): """ """ # Download, read the resources tree file and update the GUI downloadResourcesTreeFile(self.config_file_url_edit.text()) self.ressources_tree = FavoriteTreeNodeFactory( GpicGlobals.Instance().config_file_path).root_node self.tree_dock.setTreeContents(self.ressources_tree)
def runAddToMapAction(self): """ Add the WMTS layer to the map """ qgis_layer_details = self.getQgisLayerDetails() if qgis_layer_details != None: GpicGlobals.Instance().iface.addRasterLayer( qgis_layer_details["uri"], qgis_layer_details["title"], qgis_layer_details["provider"])
def runAddToMapAction(self): """ Add the preconfigured TMS layer to the map """ # GpicGlobals.Instance().iface.addRasterLayer(self.gdal_config_file_path, self.title) qgis_layer_details = self.getQgisLayerDetails() if qgis_layer_details != None: GpicGlobals.Instance().iface.addRasterLayer( qgis_layer_details["uri"], qgis_layer_details["title"])
def __init__(self, title, node_type=GpicGlobals.Instance().NODE_TYPE_FOLDER, description=None, status=None, metadata_url=None, params=None, parent_node=None): """ """ FavoritesTreeNode.__init__(self, title, node_type, description, status, metadata_url, params, parent_node) # Icon gpicIcons = GpicIcons.Instance() self.icon = gpicIcons.folder_icon if self.status == GpicGlobals.Instance().NODE_STATUS_WARN: self.icon = gpicIcons.warn_icon
def runAddToMapAction(self): """ Add the WFS feature type to the map with a filter """ qgis_layer_details = self.getQgisLayerDetails() if qgis_layer_details != None: GpicGlobals.Instance().iface.addVectorLayer( qgis_layer_details["uri"], qgis_layer_details["title"], qgis_layer_details["provider"])
def __init__(self, file_path): self.file_path = file_path self.root_node = None if not os.path.isfile(self.file_path): message = u"Le fichier de configuration du plugin {0} n'a pas pu être trouvé.".format( GpicGlobals.Instance().PLUGIN_TAG) GpicGlobals.Instance().iface.messageBar().pushMessage( "Erreur", message, level=QgsMessageBar.CRITICAL) QgsMessageLog.logMessage(message, tag=GpicGlobals.Instance().PLUGIN_TAG, level=QgsMessageLog.CRITICAL) return try: # Read the config file with open(self.file_path) as f: config_string = "".join(f.readlines()) config_struct = json.loads(config_string) self.root_node = self.build_tree(config_struct) except Exception as e: short_message = u"La lecture du fichier de configuration du plugin {0} a produit des erreurs.".format( GpicGlobals.Instance().PLUGIN_TAG) GpicGlobals.Instance().iface.messageBar().pushMessage( "Erreur", short_message, level=QgsMessageBar.CRITICAL) long_message = u"{0}\n{1}\n{2}".format(short_message, e.__doc__, e.message) QgsMessageLog.logMessage(long_message, tag=GpicGlobals.Instance().PLUGIN_TAG, level=QgsMessageLog.CRITICAL)
def saveSettings(self): """ """ # URL of the file new_value = [self.config_file_url_edit.text()] GpicGlobals.Instance().setQgisSettingsValue("config_file_urls", new_value) # Download the file at startup new_value = self.download_cb.isChecked() GpicGlobals.Instance().setQgisSettingsValue( "config_files_download_at_startup", new_value) # Hide resources with a warn flag new_value = self.hide_resources_with_warn_status_cb.isChecked() GpicGlobals.Instance().setQgisSettingsValue( "hide_resources_with_warn_status", new_value) # Hide empty groups in the resources tree new_value = self.hide_empty_groups_cb.isChecked() GpicGlobals.Instance().setQgisSettingsValue("hide_empty_groups", new_value) # Download, read the resources tree file and update the GUI if self.needUpdateOfTreeContents: downloadResourcesTreeFile( GpicGlobals.Instance().CONFIG_FILE_URLS[0]) self.ressources_tree = FavoriteTreeNodeFactory( GpicGlobals.Instance().config_file_path).root_node self.tree_dock.setTreeContents(self.ressources_tree) # Update the visibility of tree items elif self.needUpdateVisibilityOfTreeItems: self.tree_dock.updateVisibilityOfTreeItems()
def __init__(self, title, node_type=GpicGlobals.Instance().NODE_TYPE_WMS_LAYER_STYLE, description=None, status=None, metadata_url=None, params=None, parent_node=None): """ """ FavoritesTreeNode.__init__(self, title, node_type, description, status, metadata_url, params, parent_node) self.layer_style_name = params.get("name") self.can_be_added_to_map = True # Icon gpicIcons = GpicIcons.Instance() self.icon = gpicIcons.wms_style_icon if self.status == GpicGlobals.Instance().NODE_STATUS_WARN: self.icon = gpicIcons.warn_icon
def __init__( self, title, node_type=GpicGlobals.Instance().NODE_TYPE_WFS_FEATURE_TYPE_FILTER, description=None, status=None, metadata_url=None, params=None, parent_node=None): """ """ FavoritesTreeNode.__init__(self, title, node_type, description, status, metadata_url, params, parent_node) self.filter = params.get("filter") self.can_be_added_to_map = True # Icon gpicIcons = GpicIcons.Instance() self.icon = gpicIcons.wfs_layer_icon if self.status == GpicGlobals.Instance().NODE_STATUS_WARN: self.icon = gpicIcons.warn_icon
def __init__(self, iface): """ Plugin initialisation. A json config file is read in order to configure the plugin GUI. """ self.iface = iface GpicGlobals.Instance().setPluginPath( os.path.dirname(os.path.abspath(__file__))) GpicGlobals.Instance().setPluginIFace(self.iface) GpicGlobals.Instance().reloadGlobalsFromQgisSettings() config_struct = None config_string = "" # Download the config if needed if self.needDownloadResourcesTreeFile(): downloadResourcesTreeFile( GpicGlobals.Instance().CONFIG_FILE_URLS[0]) # Read the resources tree file and update the GUI self.ressources_tree = FavoriteTreeNodeFactory( GpicGlobals.Instance().config_file_path).root_node
def __init__( self, title, node_type=GpicGlobals.Instance().NODE_TYPE_GDAL_WMS_CONFIG_FILE, description=None, status=None, metadata_url=None, params=None, parent_node=None): """ """ FavoritesTreeNode.__init__(self, title, node_type, description, status, metadata_url, params, parent_node) self.gdal_config_file_path = os.path.join( GpicGlobals.Instance().config_dir_path, params.get("file_path")) self.can_be_added_to_map = True # Icon gpicIcons = GpicIcons.Instance() self.icon = gpicIcons.raster_layer_icon if self.status == GpicGlobals.Instance().NODE_STATUS_WARN: self.icon = gpicIcons.warn_icon
def isAnEmptyGroup(self): """ Indicates if this tem is an empty group """ child_count = self.childCount() if child_count == 0: return self.gpic_data.node_type == GpicGlobals.Instance( ).NODE_TYPE_FOLDER else: for i in range(child_count): if not self.child(i).isAnEmptyGroup(): return False return True return False
def updateVisibilityOfSubitems(item, hide_empty_groups, hide_items_with_warn_status): if hasattr(item, "gpic_data" ) and item.gpic_data.status == GpicGlobals.Instance( ).NODE_STATUS_WARN: item.setHidden(hide_items_with_warn_status) child_count = item.childCount() if child_count > 0: for i in range(child_count): sub_item = item.child(i) if sub_item.isAnEmptyGroup(): sub_item.setHidden(hide_empty_groups) updateVisibilityOfSubitems(sub_item, hide_empty_groups, hide_items_with_warn_status)
def __init__(self, title, node_type=GpicGlobals.Instance().NODE_TYPE_FOLDER, description=None, status=None, metadata_url=None, params=None, parent_node=None): """ """ self.parent_node = parent_node self.node_type = node_type self.title = title self.description = description self.status = status self.metadata_url = metadata_url self.children = [] self.can_be_added_to_map = False self.icon = None
def build_tree(self, tree_config, parent_node=None): """ Function that do the job """ # Read the node attributes node_title = tree_config.get('title', None) node_description = tree_config.get('description', None) node_type = tree_config.get('type', None) node_status = tree_config.get('status', None) node_metadata_url = tree_config.get('metadata_url', None) node_params = tree_config.get('params', None) if node_title: # Creation of the node if node_type == GpicGlobals.Instance().NODE_TYPE_WMS_LAYER: node = WmsLayerTreeNode(node_title, node_type, node_description, node_status, node_metadata_url, node_params, parent_node) elif node_type == GpicGlobals.Instance().NODE_TYPE_WMS_LAYER_STYLE: node = WmsStyleLayerTreeNode(node_title, node_type, node_description, node_status, node_metadata_url, node_params, parent_node) elif node_type == GpicGlobals.Instance().NODE_TYPE_WMTS_LAYER: node = WmtsLayerTreeNode(node_title, node_type, node_description, node_status, node_metadata_url, node_params, parent_node) elif node_type == GpicGlobals.Instance( ).NODE_TYPE_WFS_FEATURE_TYPE: node = WfsFeatureTypeTreeNode(node_title, node_type, node_description, node_status, node_metadata_url, node_params, parent_node) elif node_type == GpicGlobals.Instance( ).NODE_TYPE_WFS_FEATURE_TYPE_FILTER: node = WfsFeatureTypeFilterTreeNode(node_title, node_type, node_description, node_status, node_metadata_url, node_params, parent_node) elif node_type == GpicGlobals.Instance( ).NODE_TYPE_GDAL_WMS_CONFIG_FILE: node = GdalWmsConfigFileTreeNode(node_title, node_type, node_description, node_status, node_metadata_url, node_params, parent_node) else: node = FolderTreeNode(node_title, node_type, node_description, node_status, node_metadata_url, node_params, parent_node) # Creation of the node children node_children = tree_config.get('children', []) if len(node_children) > 0: for child_config in node_children: child_node = self.build_tree(child_config, node) node.children.append(child_node) return node else: return None