Skip to content

NCS pathway editor

Dialog for creating or editing an NCS pathway entry.

NcsPathwayEditorDialog

NcsPathwayEditorDialog(parent=None, ncs_pathway=None, excluded_names=None)

Bases: QDialog, WidgetUi

Dialog for creating or editing an NCS pathway entry.

Source code in src/cplus_plugin/gui/ncs_pathway_editor_dialog.py
def __init__(self, parent=None, ncs_pathway=None, excluded_names=None):
    super().__init__(parent)
    self.setupUi(self)

    QgsGui.enableAutoGeometryRestore(self)

    self._message_bar = QgsMessageBar()
    self.vl_notification.addWidget(self._message_bar)

    self.txt_description.textChanged.connect(self.description_changed)

    self.buttonBox.accepted.connect(self._on_accepted)
    self.btn_add_layer.clicked.connect(self._on_select_file)

    icon_pixmap = QtGui.QPixmap(ICON_PATH)
    self.icon_la.setPixmap(icon_pixmap)

    help_icon = FileUtils.get_icon("mActionHelpContents_green.svg")
    self.btn_help.setIcon(help_icon)
    self.btn_help.clicked.connect(self.open_help)

    pathways = settings_manager.get_default_layers("ncs_pathway")
    self.cbo_default_layer.addItem("")
    items = sorted([p["metadata"].get("name", p["name"]) for p in pathways])
    self.cbo_default_layer.addItems(items)
    self.cbo_default_layer.setCurrentIndex(0)
    self.cbo_default_layer.currentIndexChanged.connect(
        self._on_default_layer_selection_changed
    )

    # Pathway type
    self._pathway_type_group = QtWidgets.QButtonGroup(self)
    self._pathway_type_group.addButton(
        self.rb_protection, NcsPathwayType.PROTECT.value
    )
    self._pathway_type_group.addButton(
        self.rb_restoration, NcsPathwayType.RESTORE.value
    )
    self._pathway_type_group.addButton(
        self.rb_management, NcsPathwayType.MANAGE.value
    )

    # Data source type
    self._data_source_type_group = QtWidgets.QButtonGroup(self)
    self._data_source_type_group.setExclusive(True)
    self._data_source_type_group.addButton(
        self.rb_local, DataSourceType.LOCAL.value
    )
    self._data_source_type_group.addButton(
        self.rb_online, DataSourceType.ONLINE.value
    )
    self._data_source_type_group.idToggled.connect(self._on_data_source_changed)
    self.rb_local.setChecked(True)

    # Configure map combobox
    self.cbo_layer.setAllowEmptyLayer(True, tr("<Layer not set>"))
    self.cbo_layer.setFilters(QgsMapLayerProxyModel.Filter.RasterLayer)

    self._excluded_names = excluded_names
    if excluded_names is None:
        self._excluded_names = []

    self._edit_mode = False
    self._layer = None
    self._ncs_pathway = ncs_pathway
    if self._ncs_pathway is not None:
        self._edit_mode = True
        self._layer = self._ncs_pathway.to_map_layer()
        self._update_controls()

edit_mode property

edit_mode

Returns the state of the editor.

Returns:

Type Description
bool

True if the editor is editing an existing NcsPathway object, else False if its creating a new object.

layer property

layer

Returns the raster layer specified by the user, either existing layers in the map canvas or from the selected file.

Returns:

Type Description
QgsRasterLayer

The raster layer specified by the user or None if not set.

ncs_pathway property

ncs_pathway

Returns a reference to the NcsPathway object.

Returns:

Type Description
NcsPathway

Reference to the NcsPathway object.

description_changed

description_changed()

Slot to handle description text changes, it currently limits the number of characters to only be 300 characters per description

Source code in src/cplus_plugin/gui/ncs_pathway_editor_dialog.py
def description_changed(self):
    """Slot to handle description text changes, it currently
    limits the number of characters to only be 300 characters
    per description
    """

    description = self.txt_description.toPlainText()
    if len(description) > 300:
        self.txt_description.setPlainText(description[:300])

open_help

open_help(activated)

Opens the user documentation for the plugin in a browser.

Source code in src/cplus_plugin/gui/ncs_pathway_editor_dialog.py
def open_help(self, activated: bool):
    """Opens the user documentation for the plugin in a browser."""
    open_documentation(USER_DOCUMENTATION_SITE)

validate

validate()

Validates if name and layer have been specified.

Returns:

Type Description
True

True if user input (i.e. name and layer) have been set.

Source code in src/cplus_plugin/gui/ncs_pathway_editor_dialog.py
def validate(self) -> bool:
    """Validates if name and layer have been specified.

    :returns: True if user input (i.e. name and layer) have been set.
    :rtype: True
    """
    status = True

    self._message_bar.clearWidgets()

    name = self.txt_name.text()
    if not name:
        msg = tr("NCS pathway name cannot be empty.")
        self._show_warning_message(msg)
        status = False

    if name.lower() in self._excluded_names:
        msg = tr("name has already been used.")
        self._show_warning_message(f"'{name}' {msg}")
        status = False

    if not self.txt_description.toPlainText():
        msg = tr("Description cannot be empty.")
        self._show_warning_message(msg)
        status = False

    if self._pathway_type_group.checkedId() == -1:
        msg = tr("The NCS pathway type is not specified.")
        self._show_warning_message(msg)
        status = False

    layer = self._get_selected_map_layer()
    default_layer = self._get_selected_default_layer()
    data_source_type_id = self._data_source_type_group.checkedId()

    if data_source_type_id == DataSourceType.LOCAL.value and layer is None:
        msg = tr("Local map layer not specified.")
        self._show_warning_message(msg)
        status = False
    elif (
        data_source_type_id == DataSourceType.ONLINE.value
        and len(default_layer) == 0
    ):
        msg = tr("Online default layer not specified.")
        self._show_warning_message(msg)
        status = False

    if (
        data_source_type_id == DataSourceType.LOCAL.value
        and layer
        and not layer.isValid()
    ):
        msg = tr("Local map layer is not valid.")
        self._show_warning_message(msg)
        status = False

    return status

Last update: June 9, 2025
Back to top