Beispiel #1
0
    def fill_fields(self):
        """ Fill dates and combos cat_work/state type end """

        sql = 'SELECT id as id, name as idval FROM value_state_type WHERE id IS NOT NULL AND state = 0'
        rows = self.controller.get_rows(sql)
        qt_tools.set_item_data(self.dlg_work_end.cmb_statetype_end, rows, 1)
        row = self.controller.get_config('statetype_end_vdefault')

        if row:
            qt_tools.set_combo_itemData(self.dlg_work_end.cmb_statetype_end,
                                        row[0], 0)
        row = self.controller.get_config('edit_enddate_vdefault')

        if row:
            enddate = self.manage_dates(row[0]).date()
            self.dlg_work_end.enddate.setDate(enddate)
        else:
            enddate = QDate.currentDate()
        qt_tools.setCalendarDate(self.dlg_work_end, "enddate", enddate)

        sql = "SELECT id FROM cat_work"
        rows = self.controller.get_rows(sql)
        qt_tools.fillComboBox(self.dlg_work_end,
                              self.dlg_work_end.workcat_id_end,
                              rows,
                              allow_nulls=False)
        qt_tools.set_autocompleter(self.dlg_work_end.workcat_id_end)
        row = self.controller.get_config('edit_workcat_end_vdefault')
        if row:
            qt_tools.setWidgetText(self.dlg_work_end,
                                   self.dlg_work_end.workcat_id_end, row[0])
    def change_elem_type(self, feature):

        # Create the dialog, fill node_type and define its signals
        self.dlg_chg_node_type = NodeTypeChange()
        load_settings(self.dlg_chg_node_type)

        # Get nodetype_id from current node
        node_type = ""
        project_type = self.controller.get_project_type()
        if project_type == 'ws':
            node_type = feature.attribute('nodetype_id')
            self.dlg_chg_node_type.node_node_type_new.currentIndexChanged.connect(partial(self.filter_catalog))
        elif project_type == 'ud':
            node_type = feature.attribute('node_type')
            sql = "SELECT DISTINCT(id), id FROM cat_node  ORDER BY id"
            rows = self.controller.get_rows(sql)
            qt_tools.set_item_data(self.dlg_chg_node_type.node_nodecat_id, rows, 1)

        self.dlg_chg_node_type.node_node_type.setText(node_type)
        self.dlg_chg_node_type.btn_catalog.clicked.connect(partial(self.open_catalog))
        self.dlg_chg_node_type.btn_accept.clicked.connect(self.edit_change_elem_type_accept)
        self.dlg_chg_node_type.btn_cancel.clicked.connect(partial(close_dialog, self.dlg_chg_node_type))

        # Fill 1st combo boxes-new system node type
        sql = ("SELECT DISTINCT(id) FROM cat_feature WHERE active is True "
               "AND feature_type = 'NODE' ORDER BY id")
        rows = self.controller.get_rows(sql)
        qt_tools.fillComboBox(self.dlg_chg_node_type, "node_node_type_new", rows)

        # Open dialog
        open_dialog(self.dlg_chg_node_type, dlg_name='nodetype_change', maximize_button=False)
    def populate_combo(self, dialog, widget, table_name, field_name="id"):
        """ Executes query and fill combo box """

        sql = (f"SELECT {field_name}"
               f" FROM {table_name}"
               f" ORDER BY {field_name}")
        rows = self.controller.get_rows(sql)
        qt_tools.fillComboBox(dialog, widget, rows)
        if rows:
            qt_tools.setCurrentIndex(dialog, widget, 0)
    def canvasReleaseEvent(self, event):

        if event.button() == Qt.RightButton:
            self.cancel_map_tool()
            return

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

        # Snapping
        snapped_feat = None
        result = self.snapper_manager.snap_to_current_layer(event_point)
        if self.snapper_manager.result_is_valid():
            snapped_feat = self.snapper_manager.get_snapped_feature(result)

        if snapped_feat:
            self.node_id = snapped_feat.attribute('node_id')
            self.dlg_fusion = ArcFusionUi()
            load_settings(self.dlg_fusion, self.controller)

            # Fill ComboBox workcat_id_end
            sql = "SELECT id FROM cat_work ORDER BY id"
            rows = self.controller.get_rows(sql)
            qt_tools.fillComboBox(self.dlg_fusion, "workcat_id_end", rows,
                                  False)

            # Set QDateEdit to current date
            current_date = QDate.currentDate()
            qt_tools.setCalendarDate(self.dlg_fusion, "enddate", current_date)

            # Set signals
            self.dlg_fusion.btn_accept.clicked.connect(self.exec_fusion)
            self.dlg_fusion.btn_cancel.clicked.connect(
                partial(close_dialog, self.dlg_fusion, self.controller))

            open_dialog(self.dlg_fusion,
                        self.controller,
                        dlg_name='arc_fusion')
Beispiel #5
0
    def manage_new_workcat_accept(self, table_object):
        """ Insert table 'cat_work'. Add cat_work """

        # Get values from dialog
        values = ""
        fields = ""

        cat_work_id = qt_tools.getWidgetText(self.dlg_new_workcat,
                                             self.dlg_new_workcat.cat_work_id)
        if cat_work_id != "null":
            fields += 'id, '
            values += f"'{cat_work_id}', "
        descript = qt_tools.getWidgetText(self.dlg_new_workcat, "descript")
        if descript != "null":
            fields += 'descript, '
            values += f"'{descript}', "
        link = qt_tools.getWidgetText(self.dlg_new_workcat, "link")
        if link != "null":
            fields += 'link, '
            values += f"'{link}', "
        workid_key_1 = qt_tools.getWidgetText(self.dlg_new_workcat,
                                              "workid_key_1")
        if workid_key_1 != "null":
            fields += 'workid_key1, '
            values += f"'{workid_key_1}', "
        workid_key_2 = qt_tools.getWidgetText(self.dlg_new_workcat,
                                              "workid_key_2")
        if workid_key_2 != "null":
            fields += 'workid_key2, '
            values += f"'{workid_key_2}', "
        builtdate = self.dlg_new_workcat.builtdate.dateTime().toString(
            'yyyy-MM-dd')

        if builtdate != "null":
            fields += 'builtdate, '
            values += f"'{builtdate}', "

        if values == "":
            return

        fields = fields[:-2]
        values = values[:-2]
        if cat_work_id == 'null':
            msg = "Work_id field is empty"
            self.controller.show_info_box(msg, "Warning")
        else:
            # Check if this element already exists
            sql = (f"SELECT DISTINCT(id)"
                   f" FROM {table_object}"
                   f" WHERE id = '{cat_work_id}'")
            row = self.controller.get_row(sql, log_info=False, log_sql=True)
            if row is None:
                sql = f"INSERT INTO cat_work ({fields}) VALUES ({values})"
                self.controller.execute_sql(sql, log_sql=True)
                sql = "SELECT id FROM cat_work ORDER BY id"
                rows = self.controller.get_rows(sql)
                if rows:
                    qt_tools.fillComboBox(self.dlg_work_end,
                                          self.dlg_work_end.workcat_id_end,
                                          rows)
                    aux = self.dlg_work_end.workcat_id_end.findText(
                        str(cat_work_id))
                    self.dlg_work_end.workcat_id_end.setCurrentIndex(aux)

                self.close_dialog(self.dlg_new_workcat)

            else:
                msg = "This Workcat already exist"
                self.controller.show_info_box(msg, "Warning")
    def fill_combo_result_id(self):

        sql = "SELECT result_id FROM v_ui_rpt_cat_result ORDER BY result_id"
        rows = self.controller.get_rows(sql)
        qt_tools.fillComboBox(self.dlg_manager, self.dlg_manager.txt_result_id,
                              rows)