def update_labels(self):
        """ Show text in labels from SELECT """

        sql = (
            f"SELECT infiltration, text FROM cat_hydrology"
            f" WHERE name = '{self.dlg_hydrology_selector.hydrology.currentText()}'"
        )
        row = self.controller.get_row(sql)
        if row is not None:
            qt_tools.setText(self.dlg_hydrology_selector,
                             self.dlg_hydrology_selector.infiltration, row[0])
            qt_tools.setText(self.dlg_hydrology_selector,
                             self.dlg_hydrology_selector.descript, row[1])
    def go2epa_options_get_data(self, tablename, dialog):
        """ Get data from selected table """

        sql = f"SELECT * FROM {tablename}"
        row = self.controller.get_row(sql)
        if not row:
            message = "Any data found in table"
            self.controller.show_warning(message, parameter=tablename)
            return None

        # Iterate over all columns and populate its corresponding widget
        columns = []
        for i in range(0, len(row)):
            column_name = self.controller.dao.get_column_name(i)
            widget = dialog.findChild(QWidget, column_name)
            widget_type = qt_tools.getWidgetType(dialog, widget)
            if row[column_name] is not None:
                if widget_type is QCheckBox:
                    qt_tools.setChecked(dialog, widget, row[column_name])
                elif widget_type is QComboBox:
                    qt_tools.set_combo_itemData(widget, row[column_name], 0)
                elif widget_type is QDateEdit:
                    dateaux = row[column_name].replace('/', '-')
                    date = QDate.fromString(dateaux, 'dd-MM-yyyy')
                    qt_tools.setCalendarDate(dialog, widget, date)
                elif widget_type is QTimeEdit:
                    timeparts = str(row[column_name]).split(':')
                    if len(timeparts) < 3:
                        timeparts.append("0")
                    days = int(timeparts[0]) / 24
                    hours = int(timeparts[0]) % 24
                    minuts = int(timeparts[1])
                    seconds = int(timeparts[2])
                    time = QTime(hours, minuts, seconds)
                    qt_tools.setTimeEdit(dialog, widget, time)
                    qt_tools.setText(dialog, column_name + "_day", days)
                else:
                    qt_tools.setWidgetText(dialog, widget,
                                           str(row[column_name]))

            columns.append(column_name)

        return columns
示例#3
0
    def fill_workids(self):
        """ Auto fill descriptions and workid's """

        workcat_id = qt_tools.getWidgetText(self.dlg_work_end,
                                            self.dlg_work_end.workcat_id_end)
        if not workcat_id:
            return
        sql = (f"SELECT descript, builtdate "
               f"FROM cat_work "
               f"WHERE id = '{workcat_id}'")
        row = self.controller.get_row(sql)
        if row:
            qt_tools.setText(self.dlg_work_end, self.dlg_work_end.descript,
                             row['descript'])
            qt_tools.setCalendarDate(self.dlg_work_end,
                                     self.dlg_work_end.builtdate,
                                     row['builtdate'], False)
        else:
            qt_tools.setText(self.dlg_work_end, self.dlg_work_end.descript, '')
            qt_tools.setCalendarDate(self.dlg_work_end,
                                     self.dlg_work_end.builtdate, None, False)
示例#4
0
    def click_button_snapping(self, action, point, btn):

        if not self.layer_dimensions:
            return

        if btn == Qt.RightButton:
            if btn == Qt.RightButton:
                action.setChecked(False)
                self.deactivate_signals(action)
                return

        layer = self.layer_dimensions
        self.iface.setActiveLayer(layer)
        layer.startEditing()

        # Get coordinates
        event_point = self.snapper_manager.get_event_point(point=point)

        # Snapping
        result = self.snapper_manager.snap_to_background_layers(event_point)
        if self.snapper_manager.result_is_valid():

            layer = self.snapper_manager.get_snapped_layer(result)
            # Check feature
            if layer == self.layer_node:
                feat_type = 'node'
            elif layer == self.layer_connec:
                feat_type = 'connec'
            else:
                return

            # Get the point
            snapped_feat = self.snapper_manager.get_snapped_feature(result)
            feature_id = self.snapper_manager.get_snapped_feature_id(result)
            element_id = snapped_feat.attribute(feat_type + '_id')

            # Leave selection
            layer.select([feature_id])

            # Get depth of the feature
            fieldname = None
            self.project_type = self.controller.get_project_type()
            if self.project_type == 'ws':
                fieldname = "depth"
            elif self.project_type == 'ud' and feat_type == 'node':
                fieldname = "ymax"
            elif self.project_type == 'ud' and feat_type == 'connec':
                fieldname = "connec_depth"

            if fieldname is None:
                return

            depth = snapped_feat.attribute(fieldname)
            if depth:
                qt_tools.setText(self.dlg_dim, "depth", depth)
            qt_tools.setText(self.dlg_dim, "feature_id", element_id)
            qt_tools.setText(self.dlg_dim, "feature_type", feat_type.upper())

            self.snapper_manager.recover_snapping_options()
            self.deactivate_signals(action)
            action.setChecked(False)