Example #1
0
    def _load_editor_dialog(self, recid, rownumber):
        '''
        Load editor dialog based on the selected model instance with the given ID.
        '''
        model_obj = self._model_from_id(recid, rownumber)
        # show GPS editor if geometry
        if self._entity.has_geometry_column():
            self.sp_unit_manager.active_layer_source()

            gps_tool = GPSToolDialog(iface,
                                     self._entity,
                                     self._entity.name,
                                     self.sp_unit_manager.active_sp_col,
                                     model=model_obj,
                                     reload=False,
                                     row_number=rownumber,
                                     entity_browser=self)
            editor_trans = self.tr('Editor')
            title = u'{0} {1}'.format(format_name(self._entity.short_name),
                                      editor_trans)
            gps_tool.setWindowTitle(title)

            result = gps_tool.exec_()
        else:
            #Load editor dialog
            edit_entity_dlg = self._editor_dlg(
                self._entity,
                model=model_obj,
                parent=self,
                parent_entity=self.parent_entity)

            result = edit_entity_dlg.exec_()

        if result == QDialog.Accepted:
            if self._entity.has_geometry_column():
                edit_entity_dlg = gps_tool.entity_editor

            updated_model_obj = edit_entity_dlg.model()
            if not edit_entity_dlg.is_valid:
                return
            for i, attr in enumerate(self._entity_attrs):
                prop_idx = self._tableModel.index(rownumber, i)
                attr_val = getattr(updated_model_obj, attr)
                '''
                Check if there are display formatters and apply if
                one exists for the given attribute.
                '''
                if attr in self._cell_formatters:
                    formatter = self._cell_formatters[attr]
                    attr_val = formatter.format_column_value(attr_val)

                self._tableModel.setData(prop_idx, attr_val)
Example #2
0
    def _load_editor_dialog(self, recid, rownumber):
        '''
        Load editor dialog based on the selected model instance with the given ID.
        '''
        model_obj = self._model_from_id(recid, rownumber)
        # show GPS editor if geometry
        if self._entity.has_geometry_column():
            self.sp_unit_manager.active_layer_source()

            gps_tool = GPSToolDialog(
                iface,
                self._entity,
                self._entity.name,
                self.sp_unit_manager.active_sp_col,
                model=model_obj,
                reload=False,
                row_number=rownumber,
                entity_browser=self
            )

            result = gps_tool.exec_()
        else:
            #Load editor dialog
            edit_entity_dlg = self._editor_dlg(self._entity, model=model_obj,
                                             parent=self, parent_entity=self.parent_entity, plugin=self.plugin)

            result = edit_entity_dlg.exec_()

        if result == QDialog.Accepted:

            if self._entity.has_geometry_column():
                edit_entity_dlg = gps_tool.entity_editor

            updated_model_obj = edit_entity_dlg.model()
            if not edit_entity_dlg.is_valid:
                return
            for i, attr in enumerate(self._entity_attrs):
                prop_idx = self._tableModel.index(rownumber, i)
                attr_val = getattr(updated_model_obj, attr)

                '''
                Check if there are display formatters and apply if
                one exists for the given attribute.
                '''
                if attr in self._cell_formatters:
                    formatter = self._cell_formatters[attr]
                    attr_val = formatter.format_column_value(attr_val)

                self._tableModel.setData(prop_idx, attr_val)
Example #3
0
    def onNewEntity(self):
        '''
        Load editor dialog for adding a new record.
        '''
        self._notifBar.clear()

        if not self._can_add_edit():
            msg = QApplication.translate(
                'EntityBrowserWithEditor',
                'There are no user-defined columns for this entity.')
            self._notifBar.insertErrorNotification(msg)

            return
        if self._entity.has_geometry_column():
            self.sp_unit_manager.active_layer_source()

            gps_tool = GPSToolDialog(iface,
                                     self._entity,
                                     self._entity.name,
                                     self.sp_unit_manager.active_sp_col,
                                     reload=False,
                                     entity_browser=self)
            editor_trans = self.tr('Editor')
            title = u'{0} {1}'.format(format_name(self._entity.short_name),
                                      editor_trans)
            gps_tool.setWindowTitle(title)

            result = gps_tool.exec_()
            result = False  # a workaround to avoid duplicate model insert
            self.addEntityDlg = gps_tool.entity_editor
        else:
            self.addEntityDlg = self._editor_dlg(
                self._entity, parent=self, parent_entity=self.parent_entity)

            self.addEntityDlg.addedModel.connect(self.on_save_and_new)

            result = self.addEntityDlg.exec_()

        if result == QDialog.Accepted:
            model_obj = self.addEntityDlg.model()
            if self.addEntityDlg.is_valid:
                if self.parent_entity is None:
                    self.addModelToView(model_obj)
                    self.recomputeRecordCount()
Example #4
0
    def onNewEntity(self):
        '''
        Load editor dialog for adding a new record.
        '''
        self._notifBar.clear()

        if not self._can_add_edit():
            msg = QApplication.translate(
                'EntityBrowserWithEditor',
                'There are no user-defined columns for this entity.'
            )
            self._notifBar.insertErrorNotification(msg)

            return
        if self._entity.has_geometry_column():
            self.sp_unit_manager.active_layer_source()

            gps_tool = GPSToolDialog(
                iface,
                self._entity,
                self._entity.name,
                self.sp_unit_manager.active_sp_col,
                reload=False,
                entity_browser=self
            )

            result = gps_tool.exec_()
            result = False # a workaround to avoid duplicate model insert
            self.addEntityDlg = gps_tool.entity_editor
        else:
            self.addEntityDlg = self._editor_dlg(
                self._entity, parent=self, parent_entity=self.parent_entity, plugin=self.plugin
            )

            self.addEntityDlg.addedModel.connect(self.on_save_and_new)

            result = self.addEntityDlg.exec_()

        if result == QDialog.Accepted:
            model_obj = self.addEntityDlg.model()
            if self.addEntityDlg.is_valid:
                if self.parent_entity is None:
                    self.addModelToView(model_obj)
                    self.recomputeRecordCount()