def selector_date(self):
        """ Button 84: Selector dates """

        self.dlg_selector_date = SelectorDate()
        self.load_settings(self.dlg_selector_date)
        self.widget_date_from = self.dlg_selector_date.findChild(
            QDateEdit, "date_from")
        self.widget_date_to = self.dlg_selector_date.findChild(
            QDateEdit, "date_to")
        self.dlg_selector_date.findChild(QPushButton,
                                         "btn_accept").clicked.connect(
                                             self.update_dates_into_db)
        self.dlg_selector_date.btn_close.clicked.connect(
            partial(self.close_dialog, self.dlg_selector_date))
        self.dlg_selector_date.rejected.connect(
            partial(self.close_dialog, self.dlg_selector_date))
        self.widget_date_from.dateChanged.connect(partial(self.update_date_to))
        self.widget_date_to.dateChanged.connect(partial(self.update_date_from))

        self.get_default_dates()
        qt_tools.setCalendarDate(self.dlg_selector_date, self.widget_date_from,
                                 self.from_date)
        qt_tools.setCalendarDate(self.dlg_selector_date, self.widget_date_to,
                                 self.to_date)
        self.open_dialog(self.dlg_selector_date, dlg_name="selector_date")
示例#2
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 update_date_from(self):
        """ If 'date to' is lower than 'date from' set 'date from' 1 day less than 'date to' """

        from_date = self.widget_date_from.date().toString('yyyy-MM-dd')
        to_date = self.widget_date_to.date().toString('yyyy-MM-dd')
        if to_date <= from_date:
            from_date = self.widget_date_to.date().addDays(-1).toString(
                'yyyy-MM-dd')
            qt_tools.setCalendarDate(self.dlg_selector_date,
                                     self.widget_date_from,
                                     datetime.strptime(from_date, '%Y-%m-%d'))
    def update_date_to(self):
        """ If 'date from' is upper than 'date to' set 'date to' 1 day more than 'date from' """

        from_date = self.widget_date_from.date().toString('yyyy-MM-dd')
        to_date = self.widget_date_to.date().toString('yyyy-MM-dd')
        if from_date >= to_date:
            to_date = self.widget_date_from.date().addDays(1).toString(
                'yyyy-MM-dd')
            qt_tools.setCalendarDate(self.dlg_selector_date,
                                     self.widget_date_to,
                                     datetime.strptime(to_date, '%Y-%m-%d'))
    def set_calendars(self, dialog, widget, table_name, value, parameter):
        """ Executes query and set QDateEdit """

        sql = (f"SELECT {value} FROM {table_name}"
               f" WHERE parameter = '{parameter}' AND cur_user = current_user")
        row = self.controller.get_row(sql)
        if row:
            if row[0]:
                row[0] = row[0].replace('/', '-')
            date = QDate.fromString(row[0], 'yyyy-MM-dd')
        else:
            date = QDate.currentDate()
        qt_tools.setCalendarDate(dialog, widget, date)
    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
示例#7
0
    def new_workcat(self):

        self.dlg_new_workcat = InfoWorkcatUi()
        self.load_settings(self.dlg_new_workcat)

        qt_tools.setCalendarDate(self.dlg_new_workcat,
                                 self.dlg_new_workcat.builtdate, None, True)
        table_object = "cat_work"
        self.set_completer_widget(table_object,
                                  self.dlg_new_workcat.cat_work_id, 'id')

        # Set signals
        self.dlg_new_workcat.btn_accept.clicked.connect(
            partial(self.manage_new_workcat_accept, table_object))
        self.dlg_new_workcat.btn_cancel.clicked.connect(
            partial(self.close_dialog, self.dlg_new_workcat))

        # Open dialog
        self.open_dialog(self.dlg_new_workcat, dlg_name='info_workcat')
示例#8
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)
    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')
示例#10
0
    def manage_document(self,
                        tablename=None,
                        qtable=None,
                        item_id=None,
                        feature=None,
                        geom_type=None,
                        row=None):
        """ Button 34: Add document """

        # Create the dialog and signals
        self.dlg_add_doc = DocUi()
        load_settings(self.dlg_add_doc)
        self.doc_id = None

        # Capture the current layer to return it at the end of the operation
        cur_active_layer = self.iface.activeLayer()

        set_selectionbehavior(self.dlg_add_doc)

        # Get layers of every geom_type

        # Setting lists
        self.ids = []
        self.list_ids = {}
        self.list_ids['arc'] = []
        self.list_ids['node'] = []
        self.list_ids['connec'] = []
        self.list_ids['gully'] = []
        self.list_ids['element'] = []

        # Setting layers
        self.layers = {}
        self.layers['arc'] = []
        self.layers['node'] = []
        self.layers['connec'] = []
        self.layers['gully'] = []
        self.layers['element'] = []

        self.layers['arc'] = self.controller.get_group_layers('arc')
        self.layers['node'] = self.controller.get_group_layers('node')
        self.layers['connec'] = self.controller.get_group_layers('connec')
        self.layers['element'] = self.controller.get_group_layers('element')

        # Remove 'gully' for 'WS'
        self.project_type = self.controller.get_project_type()
        if self.project_type == 'ws':
            self.dlg_add_doc.tab_feature.removeTab(3)
        else:
            self.layers['gully'] = self.controller.get_group_layers('gully')

        # Remove all previous selections
        if self.single_tool_mode:
            self.layers = remove_selection(True, layers=self.layers)
        if feature is not None:
            layer = self.iface.activeLayer()
            layer.selectByIds([feature.id()])

        # Set icons
        set_icon(self.dlg_add_doc.btn_insert, "111")
        set_icon(self.dlg_add_doc.btn_delete, "112")
        set_icon(self.dlg_add_doc.btn_snapping, "137")
        self.dlg_add_doc.tabWidget.setTabEnabled(1, False)
        # Fill combo boxes
        populate_combo(self.dlg_add_doc, "doc_type", "doc_type")

        # Set current/selected date and link
        if row:
            qt_tools.setCalendarDate(self.dlg_add_doc, 'date',
                                     row.value('date'))
            qt_tools.setWidgetText(self.dlg_add_doc, 'path', row.value('path'))
        else:
            qt_tools.setCalendarDate(self.dlg_add_doc, 'date', None)

        # Adding auto-completion to a QLineEdit
        table_object = "doc"
        set_completer_object(self.dlg_add_doc, table_object)

        # Adding auto-completion to a QLineEdit for default feature
        if geom_type is None:
            geom_type = "arc"
        viewname = f"v_edit_{geom_type}"
        set_completer_feature_id(self.dlg_add_doc.feature_id, geom_type,
                                 viewname)

        # Set signals
        self.dlg_add_doc.doc_type.currentIndexChanged.connect(
            self.activate_relations)
        self.dlg_add_doc.btn_path_url.clicked.connect(
            partial(open_web_browser, self.dlg_add_doc, "path"))
        self.dlg_add_doc.btn_path_doc.clicked.connect(
            partial(get_file_dialog, self.dlg_add_doc, "path"))
        self.dlg_add_doc.btn_accept.clicked.connect(
            partial(self.manage_document_accept, table_object, tablename,
                    qtable, item_id))
        # TODO: Set variable  self.layers using return parameters
        self.dlg_add_doc.btn_cancel.clicked.connect(
            partial(manage_close,
                    self.dlg_add_doc,
                    table_object,
                    cur_active_layer,
                    excluded_layers=["v_edit_element"],
                    single_tool_mode=self.single_tool_mode,
                    layers=self.layers))
        # TODO: Set variable  self.layers using return parameters
        self.dlg_add_doc.rejected.connect(
            partial(manage_close,
                    self.dlg_add_doc,
                    table_object,
                    cur_active_layer,
                    excluded_layers=["v_edit_element"],
                    single_tool_mode=self.single_tool_mode,
                    layers=self.layers))
        self.dlg_add_doc.tab_feature.currentChanged.connect(
            partial(tab_feature_changed,
                    self.dlg_add_doc,
                    table_object,
                    excluded_layers=["v_edit_element"]))

        # TODO: Set variables self.ids, self.layers, self.list_ids using return parameters
        self.dlg_add_doc.doc_id.textChanged.connect(
            partial(exist_object,
                    self.dlg_add_doc,
                    table_object,
                    self.single_tool_mode,
                    layers=self.layers,
                    ids=self.ids,
                    list_ids=self.list_ids))
        # TODO: Set variables self.ids, self.layers, self.list_ids using return parameters
        self.dlg_add_doc.btn_insert.clicked.connect(
            partial(insert_feature,
                    self.dlg_add_doc,
                    table_object,
                    geom_type=geom_type,
                    ids=self.ids,
                    layers=self.layers,
                    list_ids=self.list_ids))
        # TODO: Set variables self.ids, self.layers, self.list_ids using return parameters
        self.dlg_add_doc.btn_delete.clicked.connect(
            partial(delete_records,
                    self.dlg_add_doc,
                    table_object,
                    geom_type=geom_type,
                    layers=self.layers,
                    ids=self.ids,
                    list_ids=self.list_ids))
        # TODO: Set variables self.ids, self.layers, self.list_ids using return parameters
        self.dlg_add_doc.btn_snapping.clicked.connect(
            partial(selection_init,
                    self.dlg_add_doc,
                    table_object,
                    geom_type=geom_type,
                    layers=self.layers))
        if feature:
            self.dlg_add_doc.tabWidget.currentChanged.connect(
                partial(self.fill_table_doc, self.dlg_add_doc, geom_type,
                        feature[geom_type + "_id"]))

        # Set default tab 'arc'
        self.dlg_add_doc.tab_feature.setCurrentIndex(0)
        self.geom_type = "arc"
        tab_feature_changed(self.dlg_add_doc,
                            table_object,
                            excluded_layers=["v_edit_element"])

        # Open the dialog
        open_dialog(self.dlg_add_doc, dlg_name='doc', maximize_button=False)

        return self.dlg_add_doc