def populate_trv(self, trv_widget, result, expand=False):

        model = QStandardItemModel()
        trv_widget.setModel(model)
        trv_widget.setUniformRowHeights(False)
        main_parent = QStandardItem('{}'.format('Giswater'))
        font = main_parent.font()
        font.setPointSize(8)
        main_parent.setFont(font)

        self.icon_folder = self.plugin_dir + os.sep + 'icons'
        path_icon_blue = self.icon_folder + os.sep + '36.png'
        path_icon_red = self.icon_folder + os.sep + '100.png'
        if os.path.exists(path_icon_blue):
            icon = QIcon(path_icon_blue)
            main_parent.setIcon(icon)

        for group, functions in result['fields'].items():
            parent1 = QStandardItem(
                f'{group}   [{len(functions)} Giswater algorithm]')
            self.no_clickable_items.append(
                f'{group}   [{len(functions)} Giswater algorithm]')
            functions.sort(key=self.sort_list, reverse=False)
            for function in functions:
                func_name = QStandardItem(str(function['functionname']))
                label = QStandardItem(str(function['alias']))
                font = label.font()
                font.setPointSize(8)
                label.setFont(font)
                row = self.controller.check_function(function['functionname'])
                if not row:
                    if os.path.exists(path_icon_red):
                        icon = QIcon(path_icon_red)
                        label.setIcon(icon)
                        label.setForeground(QColor(255, 0, 0))
                        msg = f"Function {function['functionname']}" \
                            f" configured on the table config_toolbox, but not found in the database"
                        label.setToolTip(msg)
                        self.no_clickable_items.append(str(function['alias']))
                else:
                    if os.path.exists(path_icon_blue):
                        icon = QIcon(path_icon_blue)
                        label.setIcon(icon)
                        label.setToolTip(function['functionname'])
                enable_run = QStandardItem("True")
                if function['input_params'] is not None:
                    if 'btnRunEnabled' in function['input_params']:
                        bool_dict = {True: "True", False: "False"}
                        enable_run = QStandardItem(bool_dict[
                            function['input_params']['btnRunEnabled']])

                parent1.appendRow([label, func_name, enable_run])
            main_parent.appendRow(parent1)
        model.appendRow(main_parent)
        index = model.indexFromItem(main_parent)
        trv_widget.expand(index)
        if expand:
            trv_widget.expandAll()
Example #2
0
    def fillOpenTraverseEndPoints(self):
        """
            Change End Points combo with target points observed
            from the last point selected in Order List
            if open traverse is chosen.
        """
        oldEndPoint = self.ui.EndPointComboBox.itemData(
            self.ui.EndPointComboBox.currentIndex())
        # clear combos
        self.ui.EndPointComboBox.clear()
        self.ui.EndPointComboBox.setEnabled(True)

        # get last angle point from order list
        if self.ui.OrderList.count() == 0:
            return
        lastp = self.ui.OrderList.item(self.ui.OrderList.count() - 1).data(
            Qt.UserRole)
        targets = get_targets(lastp[0], lastp[1], lastp[2])

        # fill end point combo
        combomodel = self.ui.EndPointComboBox.model()
        known_list = get_known()
        if targets is not None:
            for target in targets:
                item = QStandardItem(u"%s (id:%s)" % (target[0], target[2]))
                item.setData(target, Qt.UserRole)
                if known_list is not None and target[0] in known_list:
                    itemfont = item.font()
                    itemfont.setWeight(QFont.Bold)
                    item.setFont(itemfont)
                combomodel.appendRow(item)

        self.ui.EndPointComboBox.setCurrentIndex(
            self.ui.EndPointComboBox.findData(oldEndPoint))
Example #3
0
 def reset(self):
     if self.tile_type == 'wms':
         self.parent.removeRows(0, self.parent.rowCount())
         loading_layer = QStandardItem('loading...')
         f = loading_layer.font()
         f.setItalic(True)
         loading_layer.setFont(f)
         loading_layer.setEnabled(False)
         self.parent.appendRow(loading_layer)
 def addSourceRow(self, nr, plan, keuze_hulp=None):
     '''adds plan to search results widget'''
     if plan["typePlan"] in self.rp_supported_planTypes:
         nr = QStandardItem(str(nr + 1))
         planId = QStandardItem(plan["identificatie"])
         if keuze_hulp:
             planStatus = QStandardItem(self.infoIcon, plan["planStatus"])
             f = planStatus.font()
             f.setUnderline(True)
             planStatus.setFont(f)
             planStatus.setToolTip(
                 '%s: %s' %
                 (keuze_hulp["positieTekst"], keuze_hulp["keuzeHulpTekst"]))
         else:
             planStatus = QStandardItem(plan["planStatus"])
         planNaam = QStandardItem(plan["naam"])
         planType = QStandardItem(plan["typePlan"])
         #planGebiedType = QStandardItem(plan["planGebiedType"])
         # not yet(?) in use by this plugin
         self.sourceModel.appendRow(
             [nr, planId, planStatus, planType, planNaam])
Example #5
0
    def _recurse_tree(self,
                      bl_el=None,
                      proj_el=None,
                      parent: QStandardItem = None):
        if self.business_logic is None:
            return
        if bl_el is None:
            bl_el = self.business_logic.find('Node')

        is_root = proj_el is None
        bl_attr = bl_el.attrib

        if proj_el is None:
            proj_el = self.project

        new_proj_el = proj_el
        if 'xpath' in bl_el.attrib:
            new_proj_el = xpathone_withref(self.project, proj_el,
                                           bl_el.attrib['xpath'])
            if new_proj_el is None:
                # We just ignore layers we can't find. Log them though
                return

        # The label is either explicit or it's an xpath lookup
        curr_label = '<unknown>'
        if 'label' in bl_el.attrib:
            curr_label = bl_el.attrib['label']
        elif 'xpathlabel' in bl_el.attrib:
            found = new_proj_el.xpath(bl_el.attrib['xpathlabel'])
            curr_label = found[0].text if found is not None and len(
                found) > 0 else '<unknown>'

        curr_item = QStandardItem()
        curr_item.setText(curr_label)

        children_container = bl_el.find('Children')

        # If there are children then this is a branch
        if children_container:
            curr_item.setIcon(
                QIcon(':/plugins/qrave_toolbar/BrowseFolder.png'))
            if is_root is True:
                curr_item.setData(
                    ProjectTreeData(QRaveTreeTypes.PROJECT_ROOT,
                                    project=self,
                                    data=dict(children_container.attrib)),
                    Qt.UserRole),
            else:
                curr_item.setData(
                    ProjectTreeData(QRaveTreeTypes.PROJECT_FOLDER,
                                    project=self,
                                    data=dict(children_container.attrib)),
                    Qt.UserRole),

            for child_node in children_container.xpath('*'):
                # Handle any explicit <Node> children
                if child_node.tag == 'Node':
                    self._recurse_tree(child_node, new_proj_el, curr_item)

                # Repeaters are a separate case
                elif child_node.tag == 'Repeater':
                    qrepeater = QStandardItem(
                        QIcon(':/plugins/qrave_toolbar/BrowseFolder.png'),
                        child_node.attrib['label'])
                    qrepeater.setData(
                        ProjectTreeData(QRaveTreeTypes.PROJECT_REPEATER_FOLDER,
                                        project=self,
                                        data=dict(children_container.attrib)),
                        Qt.UserRole),
                    curr_item.appendRow(qrepeater)
                    repeat_xpath = child_node.attrib['xpath']
                    repeat_node = child_node.find('Node')
                    if repeat_node is not None:
                        for repeater_el in new_proj_el.xpath(repeat_xpath):
                            self._recurse_tree(repeat_node, repeater_el,
                                               qrepeater)

        # Otherwise this is a leaf
        else:
            bl_type = bl_el.attrib['type']
            if bl_type == 'polygon':
                curr_item.setIcon(
                    QIcon(':/plugins/qrave_toolbar/layers/Polygon.png'))
            elif bl_type == 'line':
                curr_item.setIcon(
                    QIcon(':/plugins/qrave_toolbar/layers/Polyline.png'))
            elif bl_type == 'point':
                curr_item.setIcon(
                    QIcon(':/plugins/qrave_toolbar/layers/MultiDot.png'))
            elif bl_type == 'raster':
                curr_item.setIcon(
                    QIcon(':/plugins/qrave_toolbar/layers/Raster.png'))
            else:
                curr_item.setIcon(
                    QIcon(':/plugins/qrave_toolbar/RaveAddIn_16px.png'))

            # Couldn't find this node. Ignore it.
            meta = {
                meta.attrib['name']: meta.text
                for meta in new_proj_el.findall('MetaData/Meta')
            }
            new_proj_el.find('Path')

            layer_name = None
            layer_uri = os.path.join(self.project_dir,
                                     new_proj_el.find('Path').text)
            # If this is a geopackage it's special
            if new_proj_el.getparent().tag == 'Layers':
                layer_name = new_proj_el.find('Path').text
                layer_uri = os.path.join(
                    self.project_dir,
                    new_proj_el.getparent().getparent().find('Path').text)

            layer_type = bl_attr['type'] if 'type' in bl_attr else 'unknown'

            map_layer = QRaveMapLayer(curr_label, layer_type, layer_uri,
                                      bl_attr, meta, layer_name)
            curr_item.setData(
                ProjectTreeData(QRaveTreeTypes.LEAF,
                                project=self,
                                data=map_layer), Qt.UserRole)

            if not map_layer.exists:
                curr_item.setData(QBrush(Qt.red), Qt.ForegroundRole)
                curr_item_font = curr_item.font()
                curr_item_font.setItalic(True)
                curr_item.setFont(curr_item_font)

                curr_item.setToolTip('File not found: {}'.format(
                    map_layer.layer_uri))
            elif map_layer.layer_uri:
                curr_item.setToolTip(map_layer.layer_uri)

        if parent:
            parent.appendRow(curr_item)

        return curr_item
Example #6
0
    def load(self, label: str, meta_type: str, meta: dict, show: bool = False):
        # re-initialize our model
        self.model.clear()
        self.meta = meta
        root_item = self.model.invisibleRootItem()
        self.model.setColumnCount(2)
        self.model.setHorizontalHeaderLabels(['Meta Name', 'Meta Value'])

        if meta_type == MetaType.PROJECT:
            self.treeView.setHeaderHidden(False)
            self.setWindowTitle('Project MetaData: {}'.format(label))
            self.treeView.setEnabled(True)
            if meta is not None and len(meta.keys()) > 0:
                if 'project' in meta and len(meta['project'].keys()) > 0:
                    proj_meta = QStandardItem('Project Meta')
                    proj_meta_font = proj_meta.font()
                    proj_meta_font.setBold(True)
                    proj_meta.setFont(proj_meta_font)
                    for k, v in meta['project'].items():
                        proj_meta.appendRow(
                            [QStandardItem(k),
                             QStandardItem(v)])
                    root_item.appendRow(proj_meta)
                if 'warehouse' in meta and len(meta['warehouse'].keys()) > 0:
                    wh_meta = QStandardItem('Warehouse Meta')
                    wh_meta_font = proj_meta.font()
                    wh_meta_font.setBold(True)
                    wh_meta.setFont(wh_meta_font)
                    for k, v in meta['warehouse'].items():
                        wh_meta.appendRow([QStandardItem(k), QStandardItem(v)])
                    root_item.appendRow(wh_meta)

        elif meta_type == MetaType.FOLDER:
            self.setWindowTitle('Folder: {}'.format(label))
            self.treeView.setHeaderHidden(True)
            self.treeView.setEnabled(False)
            self.model.setColumnCount(1)
            self.model.setHorizontalHeaderLabels(['Meta Name'])
            no_item = QStandardItem('Folders have no MetaData')
            no_item.setTextAlignment(Qt.AlignCenter)
            no_f = no_item.font()
            no_f.setItalic(True)
            no_item.setFont(no_f)
            root_item.appendRow(no_item)

        elif meta_type == MetaType.LAYER:
            self.setWindowTitle('Layer MetaData: {}'.format(label))
            self.treeView.setEnabled(True)
            self.treeView.setHeaderHidden(False)
            if meta is not None and len(meta.keys()) > 0:
                for k, v in meta.items():
                    root_item.appendRow([QStandardItem(k), QStandardItem(v)])
            else:
                self.treeView.setHeaderHidden(True)
                self.treeView.setEnabled(False)
                self.model.setColumnCount(1)
                self.model.setHorizontalHeaderLabels(['Meta Name'])
                no_item = QStandardItem('This layer has no MetaData')
                no_item.setTextAlignment(Qt.AlignCenter)
                no_f = no_item.font()
                no_f.setItalic(True)
                no_item.setFont(no_f)
                root_item.appendRow(no_item)
        elif meta_type == MetaType.NONE:
            self.treeView.setHeaderHidden(True)
            self.treeView.setEnabled(False)
            self.model.setColumnCount(1)
            self.setWindowTitle('Riverscapes MetaData: {}'.format(label))
            no_item = QStandardItem('This item cannot have metadata')
            no_item.setTextAlignment(Qt.AlignCenter)
            no_f = no_item.font()
            no_f.setItalic(True)
            no_item.setFont(no_f)
            root_item.appendRow(no_item)
            return

        # self.tree.header().setDefaultSectionSize(180)

        # self._populateTree(self.tree, )
        # Finally expand all levels
        self.treeView.expandAll()
        if show is True:
            self.show()
    def _populate_trv(self, trv_widget, result, expand=False):

        model = QStandardItemModel()
        trv_widget.setModel(model)
        trv_widget.setUniformRowHeights(False)

        icon_folder = self.plugin_dir + os.sep + 'icons' + os.sep + 'dialogs' + os.sep + '20x20' + os.sep
        path_icon_blue = icon_folder + os.sep + '36.png'
        path_icon_red = icon_folder + os.sep + '100.png'

        # Section Processes
        section_processes = QStandardItem('{}'.format('Processes'))
        for group, functions in result['processes']['fields'].items():
            parent1 = QStandardItem(f'{group}   [{len(functions)} Giswater algorithm]')
            self.no_clickable_items.append(f'{group}   [{len(functions)} Giswater algorithm]')
            functions.sort(key=self._sort_list, reverse=False)
            for function in functions:
                func_name = QStandardItem(str(function['functionname']))
                label = QStandardItem(str(function['alias']))
                font = label.font()
                font.setPointSize(8)
                label.setFont(font)
                row = tools_db.check_function(function['functionname'])
                if not row:
                    if os.path.exists(path_icon_red):
                        icon = QIcon(path_icon_red)
                        label.setIcon(icon)
                        label.setForeground(QColor(255, 0, 0))
                        msg = f"Function {function['functionname']}" \
                            f" configured on the table config_toolbox, but not found in the database"
                        label.setToolTip(msg)
                        self.no_clickable_items.append(str(function['alias']))
                else:
                    if os.path.exists(path_icon_blue):
                        icon = QIcon(path_icon_blue)
                        label.setIcon(icon)
                        label.setToolTip(function['functionname'])

                parent1.appendRow([label, func_name])
            section_processes.appendRow(parent1)

        # Section Reports
        reports_processes = QStandardItem('{}'.format('Reports'))
        for group, functions in result['reports']['fields'].items():
            parent1 = QStandardItem(f'{group}   [{len(functions)} Reports functions]')
            self.no_clickable_items.append(f'{group}   [{len(functions)} Reports functions]')
            functions.sort(key=self._sort_list, reverse=False)
            for function in functions:
                func_name = QStandardItem(str(function['listname']))
                label = QStandardItem(str(function['alias']))
                font = label.font()
                font.setPointSize(8)
                label.setFont(font)
                parent1.appendRow([label, func_name])
                if os.path.exists(path_icon_blue):
                    icon = QIcon(path_icon_blue)
                    label.setIcon(icon)

            reports_processes.appendRow(parent1)

        if os.path.exists(path_icon_blue):
            icon = QIcon(path_icon_blue)
            section_processes.setIcon(icon)
            reports_processes.setIcon(icon)

        model.appendRow(section_processes)
        model.appendRow(reports_processes)

        section_index = model.indexFromItem(section_processes)
        reports_index = model.indexFromItem(reports_processes)

        trv_widget.expand(section_index)
        trv_widget.expand(reports_index)

        if expand:
            trv_widget.expandAll()
Example #8
0
    def fillStartEndPointsCombos(self):
        """ Change start and end point combo when an other traversing type selected.
        """
        # get selected stations
        oldStartPoint = self.ui.StartPointComboBox.itemData(
            self.ui.StartPointComboBox.currentIndex())
        oldEndPoint = self.ui.EndPointComboBox.itemData(
            self.ui.EndPointComboBox.currentIndex())
        # clear combos
        self.ui.StartPointComboBox.clear()
        self.ui.EndPointComboBox.clear()
        self.ui.StartPointComboBox.setEnabled(False)
        self.ui.EndPointComboBox.setEnabled(False)

        # get combobox models
        combomodel1 = self.ui.StartPointComboBox.model()
        combomodel2 = self.ui.EndPointComboBox.model()

        # get stations
        known_stations = get_stations(True, False)
        oriented_stations = get_stations(True, True)

        # fill StartPointComboBox and EndPointComboBox
        start_points = []
        end_points = []

        if oriented_stations is not None and self.ui.ClosedRadio.isChecked():
            for stn in oriented_stations:
                start_points.append(
                    [u"%s (%s:%s)" % (stn[0], stn[1], stn[2]), stn])
                end_points.append(
                    [u"%s (%s:%s)" % (stn[0], stn[1], stn[2]), stn])
            self.ui.StartPointComboBox.setEnabled(True)
        elif known_stations is not None and self.ui.LinkRadio.isChecked():
            for stn in known_stations:
                start_points.append(
                    [u"%s (%s:%s)" % (stn[0], stn[1], stn[2]), stn])
                end_points.append(
                    [u"%s (%s:%s)" % (stn[0], stn[1], stn[2]), stn])
            self.ui.StartPointComboBox.setEnabled(True)
            self.ui.EndPointComboBox.setEnabled(True)
        elif oriented_stations is not None and self.ui.OpenRadio.isChecked():
            for stn in oriented_stations:
                start_points.append(
                    [u"%s (%s:%s)" % (stn[0], stn[1], stn[2]), stn])
            self.ui.StartPointComboBox.setEnabled(True)
            self.ui.EndPointComboBox.setEnabled(True)

        known_points = get_known()
        if start_points is not None:
            for startpoint in start_points:
                item = QStandardItem(startpoint[0])
                item.setData(startpoint[1], Qt.UserRole)
                if known_points is not None and startpoint[1][
                        0] in known_points:
                    itemfont = item.font()
                    itemfont.setWeight(QFont.Bold)
                    item.setFont(itemfont)
                combomodel1.appendRow(item)
        if end_points is not None:
            for endpoint in end_points:
                item = QStandardItem(endpoint[0])
                item.setData(endpoint[1], Qt.UserRole)
                if known_points is not None and endpoint[1][0] in known_points:
                    itemfont = item.font()
                    itemfont.setWeight(QFont.Bold)
                    item.setFont(itemfont)
                combomodel2.appendRow(item)

        # select previously selected start/end point if present in the list
        self.ui.StartPointComboBox.setCurrentIndex(
            self.ui.StartPointComboBox.findData(oldStartPoint))
        self.ui.EndPointComboBox.setCurrentIndex(
            self.ui.EndPointComboBox.findData(oldEndPoint))

        # in case of closed traverse ens point must be the same as start point
        if self.ui.ClosedRadio.isChecked():
            self.ui.EndPointComboBox.setCurrentIndex(
                self.ui.StartPointComboBox.currentIndex())
Example #9
0
    def fillStationCombos(self):
        """ Change dialog controls when an other calculation type selected.
        """
        # get selected stations
        oldStation1 = self.ui.Station1Combo.itemData(self.ui.Station1Combo.currentIndex())
        oldStation2 = self.ui.Station2Combo.itemData(self.ui.Station2Combo.currentIndex())
        # clear station combos
        self.ui.Station1Combo.clear()
        self.ui.Station2Combo.clear()
        self.ui.Station1Combo.setEnabled(False)
        self.ui.Station2Combo.setEnabled(False)

        # get combobox models
        combomodel1 = self.ui.Station1Combo.model()
        combomodel2 = self.ui.Station2Combo.model()

        # get stations
        known_stations = get_stations(True, False)
        all_stations = get_stations(False, False)
        oriented_stations = get_stations(True, True)
        # fill Station1Combo and Station2Combo
        stations1 = []
        stations2 = []
        if known_stations is not None and self.ui.OrientRadio.isChecked():
            for stn in known_stations:
                stations1.append([u"%s (%s:%s)" % (stn[0], stn[1], stn[2]), stn])
            self.ui.Station1Combo.setEnabled(True)
        elif oriented_stations is not None and (self.ui.RadialRadio.isChecked() or
                                                self.ui.IntersectRadio.isChecked()):
            for stn in oriented_stations:
                stations1.append([u"%s (%s:%s)" % (stn[0], stn[1], stn[2]), stn])
                if self.ui.IntersectRadio.isChecked():
                    stations2.append([u"%s (%s:%s)" % (stn[0], stn[1], stn[2]), stn])
            self.ui.Station1Combo.setEnabled(True)
            if self.ui.IntersectRadio.isChecked():
                self.ui.Station2Combo.setEnabled(True)
        elif all_stations is not None and (self.ui.ResectionRadio.isChecked() or
                                           self.ui.FreeRadio.isChecked()):
            self.ui.Station1Combo.setEnabled(True)
            for stn in all_stations:
                stations1.append([u"%s (%s:%s)" % (stn[0], stn[1], stn[2]), stn])

        known_points = get_known()
        if stations1 is not None:
            for station in stations1:
                item = QStandardItem(station[0])
                item.setData(station[1], Qt.UserRole)
                if known_points is not None and station[1][0] in known_points:
                    itemfont = item.font()
                    itemfont.setWeight(QFont.Bold)
                    item.setFont(itemfont)
                combomodel1.appendRow(item)
        if self.ui.IntersectRadio.isChecked() and stations2 is not None:
            for station in stations2:
                item = QStandardItem(station[0])
                item.setData(station[1], Qt.UserRole)
                if known_points is not None and station[1][0] in known_points:
                    itemfont = item.font()
                    itemfont.setWeight(QFont.Bold)
                    item.setFont(itemfont)
                combomodel2.appendRow(item)

        # select previously selected stations if present in the list
        self.ui.Station1Combo.setCurrentIndex(self.ui.Station1Combo.findData(oldStation1))
        self.ui.Station2Combo.setCurrentIndex(self.ui.Station2Combo.findData(oldStation2))