def call_changes_per_parcel_panel(self, item):
        with OverrideCursor(Qt.WaitCursor):

            inverse = item.data(Qt.UserRole)['inverse']
            base_db = self.utils._supplies_db if inverse else self.utils._db
            parcel_number = self.tbl_changes_all_parcels.item(item.row(),
                                                              0).text()

            # Obtain t_ids from parcels with NULL or duplicated parcel_number, before calling the per_parcel_panel
            parcels_t_ids = list()
            if parcel_number == QgsApplication.nullRepresentation(
            ):  # TODO: does it make sense if the NULL parcels is only one?
                parcels_t_ids = self.compared_parcels_data[NULL][
                    base_db.names.T_ID_F]
            elif parcel_number in self.compared_parcels_data and self.compared_parcels_data[
                    parcel_number][
                        PARCEL_STATUS] == CHANGE_DETECTION_SEVERAL_PARCELS:
                parcels_t_ids = self.compared_parcels_data[parcel_number][
                    base_db.names.T_ID_F]

        if parcels_t_ids:
            dlg_select_parcel = SelectDuplicateParcelDialog(
                self.utils, parcels_t_ids, self.parent)
            dlg_select_parcel.exec_()

            if dlg_select_parcel.parcel_t_id:  # User selected one of the duplicated parcels
                self.changes_per_parcel_panel_requested.emit(
                    dlg_select_parcel.parcel_number,
                    dlg_select_parcel.parcel_t_id)
        else:
            self.changes_per_parcel_panel_requested.emit(
                parcel_number,
                '')  # 2nd parameter is mandatory for the signal :)
Example #2
0
 def testSetAllowNull(self):
     layer = createLayer()
     w = QgsFeaturePickerWidget()
     w.setLayer(layer)
     w.setAllowNull(True)
     spy = QSignalSpy(w.featureChanged)
     spy.wait()
     self.assertEqual(
         w.findChild(QComboBox).lineEdit().text(),
         QgsApplication.nullRepresentation())
     w.setAllowNull(False)
     spy.wait()
     self.assertEqual(w.findChild(QComboBox).lineEdit().text(), "test1")
Example #3
0
 def testNullRepresentation(self):
     nr = 'my_null_value'
     QgsApplication.setNullRepresentation(nr)
     self.assertEqual(QgsApplication.nullRepresentation(), nr)
 def testNullRepresentation(self):
     nr = 'my_null_value'
     QgsApplication.setNullRepresentation(nr)
     self.assertEqual(QgsApplication.nullRepresentation(), nr)
    def fill_table(self, dict_parcels, types_change_detection):
        num_rows = 0
        for type in types_change_detection:
            # We didn't use COUNT_KEY because for duplicate parcels the count (t_ids) differs from number of parcels
            num_rows += len(
                dict_parcels[type][DICT_KEY_PARCEL_T_PARCEL_NUMBER_F])

        self.tbl_changes_all_parcels.clearContents()
        self.tbl_changes_all_parcels.setRowCount(num_rows)
        self.tbl_changes_all_parcels.setSortingEnabled(False)

        row = 0
        filter_parcels = None
        for type in types_change_detection:
            filter_parcels = dict_parcels[type]

            if filter_parcels[SOURCE_DB] == COLLECTED_DB_SOURCE:
                inverse = False
            else:
                inverse = True  # Take the supplies db as base db

            base_db = self.utils._supplies_db if inverse else self.utils._db
            self.compared_parcels_data = self.utils.get_compared_parcels_data(
                inverse)

            for parcel_number, parcel_attrs in self.compared_parcels_data.items(
            ):
                if filter_parcels and parcel_number in filter_parcels[
                        DICT_KEY_PARCEL_T_PARCEL_NUMBER_F]:
                    item = QTableWidgetItem(
                        parcel_number) if parcel_number else QTableWidgetItem(
                            QgsApplication.nullRepresentation())
                    item.setData(
                        Qt.UserRole, {
                            base_db.names.T_ID_F:
                            parcel_attrs[base_db.names.T_ID_F],
                            'inverse':
                            inverse
                        })
                    self.tbl_changes_all_parcels.setItem(row, 0, item)

                    status = parcel_attrs[PARCEL_STATUS]
                    status_display = parcel_attrs[PARCEL_STATUS_DISPLAY]
                    if filter_parcels:
                        # If we are on the supplies DB, "new" parcels are "missing" parcels from the collected db perspective
                        if filter_parcels[
                                SOURCE_DB] == SUPPLIES_DB_SOURCE and parcel_attrs[
                                    PARCEL_STATUS_DISPLAY] == CHANGE_DETECTION_NEW_PARCEL:
                            status_display = CHANGE_DETECTION_MISSING_PARCEL
                            status = CHANGE_DETECTION_MISSING_PARCEL

                    item = QTableWidgetItem(status_display)
                    item.setData(
                        Qt.UserRole, {
                            base_db.names.T_ID_F:
                            parcel_attrs[base_db.names.T_ID_F],
                            'inverse':
                            inverse
                        })
                    self.tbl_changes_all_parcels.setItem(row, 1, item)
                    color = STATUS_COLORS[status]
                    self.tbl_changes_all_parcels.item(row,
                                                      1).setBackground(color)

                    row += 1

            self.tbl_changes_all_parcels.setSortingEnabled(True)

        # Go for parcel ids and then for plot ids
        parcel_ids_collected = list()
        parcel_ids_supplies = list()
        for type in types_change_detection:
            filter_parcels = dict_parcels[type]
            if filter_parcels:
                if filter_parcels[SOURCE_DB] == COLLECTED_DB_SOURCE:
                    parcel_ids_collected.extend(
                        filter_parcels[self.utils._db.names.T_ID_F])
                else:
                    parcel_ids_supplies.extend(
                        filter_parcels[self.utils._supplies_db.names.T_ID_F])

        plot_ids_collected = list()
        if parcel_ids_collected:
            plot_ids_collected = self.utils.ladm_data.get_plots_related_to_parcels(
                self.utils._db,
                parcel_ids_collected,
                None,  # Get QGIS plot ids
                self.utils._layers[self.utils._db.names.LC_PLOT_T],
                self.utils._layers[self.utils._db.names.COL_UE_BAUNIT_T])

        plot_ids_supplies = list()
        if parcel_ids_supplies:
            plot_ids_supplies = self.utils.ladm_data.get_plots_related_to_parcels_supplies(
                self.utils._supplies_db,
                parcel_ids_supplies,
                None,  # Get QGIS plot ids
                self.utils._supplies_layers[
                    self.utils._supplies_db.names.GC_PLOT_T])

        # Now that we've got plot ids, select them and zoom to them (combining the extent from both plot layers)
        if plot_ids_collected:
            self.utils._layers[self.utils._db.names.LC_PLOT_T].selectByIds(
                plot_ids_collected)

        if plot_ids_supplies:
            self.utils._supplies_layers[
                self.utils._supplies_db.names.GC_PLOT_T].selectByIds(
                    plot_ids_supplies)

        self.zoom_to_selected_plots()
    def fill_table(self, filter_parcels=dict()):
        if not filter_parcels or (filter_parcels and filter_parcels[SOURCE_DB]
                                  == COLLECTED_DB_SOURCE):
            inverse = False
        else:
            inverse = True  # Take the official db as base db

        self.compared_parcels_data = self.utils.get_compared_parcels_data(
            inverse)

        self.tbl_changes_all_parcels.clearContents()
        self.tbl_changes_all_parcels.setRowCount(
            len(filter_parcels[PARCEL_NUMBER_FIELD]
                ) if filter_parcels else len(self.compared_parcels_data))
        self.tbl_changes_all_parcels.setSortingEnabled(False)

        row = 0
        for parcel_number, parcel_attrs in self.compared_parcels_data.items():
            if not filter_parcels or (filter_parcels and parcel_number
                                      in filter_parcels[PARCEL_NUMBER_FIELD]):
                item = QTableWidgetItem(
                    parcel_number) if parcel_number else QTableWidgetItem(
                        QgsApplication.nullRepresentation())
                item.setData(Qt.UserRole, {
                    ID_FIELD: parcel_attrs[ID_FIELD],
                    'inverse': inverse
                })
                self.tbl_changes_all_parcels.setItem(row, 0, item)

                status = parcel_attrs[PARCEL_STATUS]
                status_display = parcel_attrs[PARCEL_STATUS_DISPLAY]
                if filter_parcels:
                    # If we are on the official DB, "new" parcels are "missing" parcels from the collected db perspective
                    if filter_parcels[
                            SOURCE_DB] == OFFICIAL_DB_SOURCE and parcel_attrs[
                                PARCEL_STATUS_DISPLAY] == CHANGE_DETECTION_NEW_PARCEL:
                        status_display = CHANGE_DETECTION_MISSING_PARCEL
                        status = CHANGE_DETECTION_MISSING_PARCEL

                item = QTableWidgetItem(status_display)
                item.setData(Qt.UserRole, {
                    ID_FIELD: parcel_attrs[ID_FIELD],
                    'inverse': inverse
                })
                self.tbl_changes_all_parcels.setItem(row, 1, item)
                color = STATUS_COLORS[status]
                self.tbl_changes_all_parcels.item(row, 1).setBackground(color)

                row += 1

        self.tbl_changes_all_parcels.setSortingEnabled(True)

        # Zoom and flash features
        if filter_parcels:
            plot_layer = None
            if filter_parcels[SOURCE_DB] == COLLECTED_DB_SOURCE:
                plot_layer = self.utils._layers[PLOT_TABLE][LAYER]
            else:
                plot_layer = self.utils._official_layers[PLOT_TABLE][LAYER]

            plot_ids = self.utils.ladm_data.get_plots_related_to_parcels(
                self.utils._db if filter_parcels[SOURCE_DB]
                == COLLECTED_DB_SOURCE else self.utils._official_db,
                filter_parcels[ID_FIELD],
                None,  # Get QGIS plot ids
                plot_layer,
                self.utils._layers[UEBAUNIT_TABLE][LAYER]
                if filter_parcels[SOURCE_DB] == COLLECTED_DB_SOURCE else
                self.utils._official_layers[UEBAUNIT_TABLE][LAYER])
            self.parent.request_zoom_to_features(plot_layer,
                                                 ids=plot_ids,
                                                 duration=3000)

            # plot_layer.select(plot_ids)
        else:
            self.utils.qgis_utils.activate_layer_requested.emit(
                self.utils._layers[PLOT_TABLE][LAYER])
            self.utils.iface.zoomToActiveLayer()

        self.select_related_plots_listed(False)