Esempio n. 1
0
    def __init__(self):
        """
        """

        # Folder icon
        QgsApplication.initQgis()
        style = QgsApplication.style()
        self.folder_icon = style.standardIcon(QStyle.SP_DirClosedIcon)

        warn_icon_path = os.path.join(
            PluginGlobals.instance().images_dir_path,
            PluginGlobals.instance().ICON_WARN_FILE_NAME)
        self.warn_icon = QIcon(warn_icon_path)

        wms_layer_icon_path = os.path.join(
            PluginGlobals.instance().images_dir_path,
            PluginGlobals.instance().ICON_WMS_LAYER_FILE_NAME)
        self.wms_layer_icon = QIcon(wms_layer_icon_path)

        wms_style_icon_path = os.path.join(
            PluginGlobals.instance().images_dir_path,
            PluginGlobals.instance().ICON_WMS_STYLE_FILE_NAME)
        self.wms_style_icon = QIcon(wms_style_icon_path)

        wfs_layer_icon_path = os.path.join(
            PluginGlobals.instance().images_dir_path,
            PluginGlobals.instance().ICON_WFS_LAYER_FILE_NAME)
        self.wfs_layer_icon = QIcon(wfs_layer_icon_path)

        raster_layer_icon_path = os.path.join(
            PluginGlobals.instance().images_dir_path,
            PluginGlobals.instance().ICON_RASTER_LAYER_FILE_NAME)
        self.raster_layer_icon = QIcon(raster_layer_icon_path)
Esempio n. 2
0
    def __init__(self, parent=None):

        QWidget.__init__(self, parent)

        mainLayout = QVBoxLayout()

        logo_file_path = PluginGlobals.instance().logo_file_path
        self.logo = QLabel()
        self.logo.setPixmap(QPixmap(logo_file_path))
        mainLayout.addWidget(self.logo)

        title = u"À propos de l'extension GéoBretagne…"
        description = u"""Extension pour QGIS donnant un accès simplifié aux ressources géographiques utiles aux 
partenaires de GéoBretagne
Version {0}
Plus d'informations à l'adresse suivante :
{1}
        """.format(PluginGlobals.instance().PLUGIN_VERSION,
                   PluginGlobals.instance().PLUGIN_SOURCE_REPOSITORY)

        self.textArea = QTextEdit()
        self.textArea.setReadOnly(True)
        self.textArea.setText(description)
        self.textArea.setFrameShape(QFrame.NoFrame)
        mainLayout.addWidget(self.textArea)

        self.setModal(True)
        self.setSizeGripEnabled(False)

        self.setLayout(mainLayout)

        self.setFixedSize(400, 250)
        self.setWindowTitle(title)
Esempio n. 3
0
    def __init__(self,
                 title,
                 node_type=PluginGlobals.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
        plugin_icons = PluginIcons.instance()
        self.icon = plugin_icons.wfs_layer_icon
        if self.status == PluginGlobals.instance().NODE_STATUS_WARN:
            self.icon = plugin_icons.warn_icon
Esempio n. 4
0
    def __init__(self,
                 title,
                 node_type=PluginGlobals.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
        plugin_icons = PluginIcons.instance()
        self.icon = plugin_icons.wms_style_icon
        if self.status == PluginGlobals.instance().NODE_STATUS_WARN:
            self.icon = plugin_icons.warn_icon
Esempio n. 5
0
    def update_visibility_of_tree_items(self):
        """
        Update the visibility of tree items:
        - visibility of empty groups
        - visibility of items with status = warn
        """
        hide_items_with_warn_status = PluginGlobals.instance(
        ).HIDE_RESOURCES_WITH_WARN_STATUS
        hide_empty_groups = PluginGlobals.instance().HIDE_EMPTY_GROUPS

        def update_visibility_of_subitems(item, hide_empty_groups,
                                          hide_items_with_warn_status):

            if hasattr(item, "item_data"
                       ) and item.item_data.status == PluginGlobals.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.is_an_empty_group():
                        sub_item.setHidden(hide_empty_groups)

                    update_visibility_of_subitems(sub_item, hide_empty_groups,
                                                  hide_items_with_warn_status)

        update_visibility_of_subitems(self.invisibleRootItem(),
                                      hide_empty_groups,
                                      hide_items_with_warn_status)
Esempio n. 6
0
    def save_settings(self):
        """
        """
        # URL of the file
        new_value = [self.config_file_url_edit.text()]
        PluginGlobals.instance().set_qgis_settings_value(
            "config_file_urls", new_value)

        # Download the file at startup
        new_value = self.download_cb.isChecked()
        PluginGlobals.instance().set_qgis_settings_value(
            "config_files_download_at_startup", new_value)

        # Hide resources with a warn flag
        new_value = self.hide_resources_with_warn_status_cb.isChecked()
        PluginGlobals.instance().set_qgis_settings_value(
            "hide_resources_with_warn_status", new_value)

        # Hide empty groups in the resources tree
        new_value = self.hide_empty_groups_cb.isChecked()
        PluginGlobals.instance().set_qgis_settings_value(
            "hide_empty_groups", new_value)

        # Download, read the resources tree file and update the GUI
        if self.need_update_of_tree_content:
            download_tree_config_file(
                PluginGlobals.instance().CONFIG_FILE_URLS[0])
            self.ressources_tree = TreeNodeFactory(
                PluginGlobals.instance().config_file_path).root_node
            self.tree_dock.set_tree_content(self.ressources_tree)

        # Update the visibility of tree items
        elif self.need_update_visibility_of_tree_items and self.tree_dock is not None:
            self.tree_dock.update_visibility_of_tree_items()
Esempio n. 7
0
    def restore_defaults_button_clicked(self):
        """
        """
        # URL of the file
        self.config_file_url_edit.blockSignals(True)
        self.config_file_url_edit.setText(
            PluginGlobals.instance().get_qgis_setting_default_value(
                "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(
            PluginGlobals.instance().get_qgis_setting_default_value(
                "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(
            PluginGlobals.instance().get_qgis_setting_default_value(
                "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(
            PluginGlobals.instance().get_qgis_setting_default_value(
                "HIDE_EMPTY_GROUPS"))
        self.hide_empty_groups_cb.blockSignals(False)

        self.evaluate_flags()
Esempio n. 8
0
    def evaluate_flags(self):
        """
        """
        # Detect modifications
        file_url_changed = (self.config_file_url_edit.text() !=
                            PluginGlobals.instance().CONFIG_FILE_URLS[0])

        download_at_startup_changed = \
            (self.download_cb.isChecked() != PluginGlobals.instance().CONFIG_FILES_DOWNLOAD_AT_STARTUP)

        hide_resources_with_warn_status_changed = \
            (self.hide_resources_with_warn_status_cb.isChecked() !=
             PluginGlobals.instance().HIDE_RESOURCES_WITH_WARN_STATUS)

        hide_empty_groups_changed = \
            (self.hide_empty_groups_cb.isChecked() != PluginGlobals.instance().HIDE_EMPTY_GROUPS)

        # Init flags
        self.need_update_visibility_of_tree_items = hide_empty_groups_changed or hide_resources_with_warn_status_changed
        self.need_update_of_tree_content = file_url_changed
        self.need_save = file_url_changed or download_at_startup_changed or \
                         hide_resources_with_warn_status_changed or \
                         hide_empty_groups_changed

        # Update state of the Apply Button
        self.button_box.button(QDialogButtonBox.Apply).setEnabled(
            self.need_save)
Esempio n. 9
0
    def set_values_from_qsettings(self):
        """
        """
        # URL of the file
        self.config_file_url_edit.blockSignals(True)
        self.config_file_url_edit.setText(
            PluginGlobals.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(
            PluginGlobals.instance().CONFIG_FILES_DOWNLOAD_AT_STARTUP)
        self.download_cb.blockSignals(True)

        # Hide resources with a warn flag
        self.hide_resources_with_warn_status_cb.blockSignals(True)
        self.hide_resources_with_warn_status_cb.setChecked(
            PluginGlobals.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(
            PluginGlobals.instance().HIDE_EMPTY_GROUPS)
        self.hide_empty_groups_cb.blockSignals(False)
Esempio n. 10
0
 def run_add_to_map_action(self):
     """
     Add the WMS layer with the specified style to the map
     """
     qgis_layer_details = self.get_qgis_layer_details()
     PluginGlobals.instance().iface.addRasterLayer(
         qgis_layer_details["uri"], qgis_layer_details["title"],
         qgis_layer_details["provider"])
Esempio n. 11
0
 def run_add_to_map_action(self):
     """
     Add the WFS feature type to the map
     """
     qgis_layer_details = self.get_qgis_layer_details()
     if qgis_layer_details is not None:
         PluginGlobals.instance().iface.addVectorLayer(
             qgis_layer_details["uri"], qgis_layer_details["title"],
             qgis_layer_details["provider"])
Esempio n. 12
0
 def run_add_to_map_action(self):
     """
     Add the preconfigured TMS layer to the map
     """
     # PluginGlobals.instance().iface.addRasterLayer(self.gdal_config_file_path, self.title)
     qgis_layer_details = self.get_qgis_layer_details()
     if qgis_layer_details is not None:
         PluginGlobals.instance().iface.addRasterLayer(
             qgis_layer_details["uri"], qgis_layer_details["title"])
Esempio n. 13
0
    def need_download_tree_config_file(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 (PluginGlobals.instance().CONFIG_FILES_DOWNLOAD_AT_STARTUP > 0
                or
                not os.path.isfile(PluginGlobals.instance().config_file_path))
Esempio n. 14
0
    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(
                PluginGlobals.instance().PLUGIN_TAG)
            PluginGlobals.instance().iface.messageBar().pushMessage("Erreur", message, level=Qgis.Critical)
            QgsMessageLog.logMessage(message, tag=PluginGlobals.instance().PLUGIN_TAG, level=Qgis.Critical)
            return

        try:
            # Read the config file
            # QgsMessageLog.logMessage("Config file path: {}".format(self.file_path,
            #                                                        tag=PluginGlobals.instance().PLUGIN_TAG,
            #                                                        level=Qgis.Info))
            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(
                PluginGlobals.instance().PLUGIN_TAG)
            PluginGlobals.instance().iface.messageBar().pushMessage("Erreur", short_message, level=Qgis.Critical)

            long_message = u"{0}\n{1}\n{2}".format(short_message, e.__doc__, e)
            QgsMessageLog.logMessage(long_message, tag=PluginGlobals.instance().PLUGIN_TAG, level=Qgis.Critical)
Esempio n. 15
0
 def download_file_now(self):
     """
     """
     # Download, read the resources tree file and update the GUI
     download_tree_config_file(self.config_file_url_edit.text())
     self.ressources_tree = TreeNodeFactory(
         PluginGlobals.instance().config_file_path).root_node
     if self.tree_dock is not None:
         self.tree_dock.set_tree_content(self.ressources_tree)
Esempio n. 16
0
    def __init__(self,
                 title,
                 node_type=PluginGlobals.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
        plugin_icons = PluginIcons.instance()
        self.icon = plugin_icons.folder_icon
        if self.status == PluginGlobals.instance().NODE_STATUS_WARN:
            self.icon = plugin_icons.warn_icon
Esempio n. 17
0
    def __init__(self,
                 title,
                 node_type=PluginGlobals.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
        plugin_icons = PluginIcons.instance()
        self.icon = plugin_icons.wfs_layer_icon
        if self.status == PluginGlobals.instance().NODE_STATUS_WARN:
            self.icon = plugin_icons.warn_icon
Esempio n. 18
0
    def __init__(self,
                 title,
                 node_type=PluginGlobals.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
        plugin_icons = PluginIcons.instance()
        self.icon = plugin_icons.wms_style_icon
        if self.status == PluginGlobals.instance().NODE_STATUS_WARN:
            self.icon = plugin_icons.warn_icon
Esempio n. 19
0
    def __init__(
            self,
            title,
            node_type=PluginGlobals.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(
            PluginGlobals.instance().config_dir_path, params.get("file_path"))
        self.can_be_added_to_map = True

        # Icon
        plugin_icons = PluginIcons.instance()
        self.icon = plugin_icons.raster_layer_icon
        if self.status == PluginGlobals.instance().NODE_STATUS_WARN:
            self.icon = plugin_icons.warn_icon
Esempio n. 20
0
    def is_an_empty_group(self):
        """
        Indicates if this tem is an empty group
        """
        child_count = self.childCount()

        if child_count == 0:
            return self.item_data.node_type == PluginGlobals.instance(
            ).NODE_TYPE_FOLDER
        else:
            for i in range(child_count):
                if not self.child(i).is_an_empty_group():
                    return False
            return True
Esempio n. 21
0
def download_tree_config_file(file_url):
    """
    Download the resources tree file
    """
    try:
        # QgsMessageLog.logMessage("Config file URL: {}".format(file_url,
        #                                                       tag=PluginGlobals.instance().PLUGIN_TAG,
        #                                                       level=Qgis.Info))
        # Download the config file
        http_req = Request(file_url)
        http_req.add_header("Cache-Control", "no-cache")

        with urlopen(http_req) as response, open(PluginGlobals.instance().config_file_path, 'wb') as local_config_file:
            data = response.read()
            local_config_file.write(data)

    except Exception as e:
        short_message = u"Le téléchargement du fichier de configuration du plugin {0} a échoué.".format(
            PluginGlobals.instance().PLUGIN_TAG)
        PluginGlobals.instance().iface.messageBar().pushMessage("Erreur", short_message, level=Qgis.Critical)

        long_message = u"{0}\nUrl du fichier : {1}\n{2}\n{3}".format(short_message, file_url, e.__doc__, e)
        QgsMessageLog.logMessage(long_message, tag=PluginGlobals.instance().PLUGIN_TAG, level=Qgis.Critical)
Esempio n. 22
0
    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 == PluginGlobals.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 == PluginGlobals.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 == PluginGlobals.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 == PluginGlobals.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 == PluginGlobals.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 == PluginGlobals.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
Esempio n. 23
0
        def update_visibility_of_subitems(item, hide_empty_groups,
                                          hide_items_with_warn_status):

            if hasattr(item, "item_data"
                       ) and item.item_data.status == PluginGlobals.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.is_an_empty_group():
                        sub_item.setHidden(hide_empty_groups)

                    update_visibility_of_subitems(sub_item, hide_empty_groups,
                                                  hide_items_with_warn_status)
Esempio n. 24
0
    def __init__(self, iface):
        self.iface = iface
        self.dock = None

        PluginGlobals.instance().set_plugin_path(
            os.path.dirname(os.path.abspath(__file__)))
        PluginGlobals.instance().set_plugin_iface(self.iface)
        PluginGlobals.instance().reload_globals_from_qgis_settings()

        config_struct = None
        config_string = ""

        # Download the config if needed
        if self.need_download_tree_config_file():
            download_tree_config_file(
                PluginGlobals.instance().CONFIG_FILE_URLS[0])

        # Read the resources tree file and update the GUI
        self.ressources_tree = TreeNodeFactory(
            PluginGlobals.instance().config_file_path).root_node
Esempio n. 25
0
    def __init__(self,
                 title,
                 node_type=PluginGlobals.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