def create_str_type_table(self): """ Creates social tenure type table that is composed of each selected party rows with a combobox for social tenure type. """ headers = self.add_str_type_headers() self.str_type_table = FreezeTableWidget(self.str_type_data, headers, self.container_widget) self.str_type_table.setEditTriggers(QAbstractItemView.NoEditTriggers) grid_layout = QGridLayout(self.container_widget) grid_layout.setHorizontalSpacing(5) grid_layout.setColumnStretch(4, 5) grid_layout.setMargin(5) grid_layout.addWidget(self.str_type_table)
def create_str_type_table(self): """ Creates social tenure type table that is composed of each selected party rows with a combobox for social tenure type. """ headers = self.add_str_type_headers() self.str_type_table = FreezeTableWidget( self.str_type_data, headers, self.container_widget ) self.str_type_table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.container_box.setSpacing(4) self.container_box.setMargin(5) grid_layout = QGridLayout(self.container_widget) grid_layout.setHorizontalSpacing(5) grid_layout.setColumnStretch(4, 5) self.container_box.addLayout(grid_layout) self.container_box.addWidget(self.str_type_table)
class STRType(ComponentUtility): def __init__(self, container_widget, box, notification_bar, party=None): """ Handles the STR type component for loading tenure type and share widgets in a QTableView. :param container_widget: The container widget for the component. :type container_widget: QWidget :param box: The layout holding the container widget. :type box: QVBoxLayout :param notification_bar: The NotificationBar object that displays notification. :type notification_bar: Object :param party: The party entity from with STR type component rows are populated. By default, if None, the first party component is used. :type party: Object """ ComponentUtility.__init__(self) self.container_widget = container_widget self.container_box = box self.notification_bar = notification_bar self.str_type_data = [] self.selected_party = party self.create_str_type_table() def add_str_type_data(self, spatial_unit, row_data, insert_row): """ Adds str type date into STR Type table view. :param row_data: The table data :type row_data: List :param insert_row: The row in which the STR type row is is added. :type insert_row: Integer """ data = [None, None] + row_data self.str_type_data.append(data) self.str_type_table.add_widgets(spatial_unit, insert_row) self.update_table_view(self.str_type_table, True) self.str_type_table.model().layoutChanged.emit() # select the first column (STR Type) self.str_type_table.frozen_table_view.selectColumn(0) def copy_party_table(self, table_view, row): """ Copy rows from party table view. :param row: The row to be copied :type row: Integer :param table_view: The party table view :type table_view: QTableView :return: List of row data :rtype: List """ party_row_data = [] model = table_view.model() for col in range(model.columnCount()): party_id_idx = model.index(row, col) party_row_data.append(model.data(party_id_idx, Qt.DisplayRole)) return party_row_data def add_str_type_headers(self): """ Adds headers data for QTableView columns. The headers comes from the selected entity. :param entity: The entity for which the table header is created for. :return: List of Table headers :rtype: List """ if not self.selected_party is None: self.party_1 = self.selected_party db_model = entity_model(self.party_1, True) headers = [] # Load headers if db_model is not None: # Append str type if the method # is used for str_type str_type_header = QApplication.translate('STRType', 'Social Tenure Type') share_header = QApplication.translate('STRType', 'Share ') # First (ID) column will always be hidden headers.append(str_type_header) headers.append(share_header) display_columns = entity_display_columns(self.party_1, True) for col in display_columns.values(): headers.append(col) return headers def create_str_type_table(self): """ Creates social tenure type table that is composed of each selected party rows with a combobox for social tenure type. """ headers = self.add_str_type_headers() self.str_type_table = FreezeTableWidget(self.str_type_data, headers, self.container_widget) self.str_type_table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.container_box.setSpacing(4) self.container_box.setMargin(5) grid_layout = QGridLayout(self.container_widget) grid_layout.setHorizontalSpacing(5) grid_layout.setColumnStretch(4, 5) self.container_box.addLayout(grid_layout) self.container_box.addWidget(self.str_type_table) def enable_str_type_widgets(self, row): """ Makes the STR Type combobox editable. :param row: The row of STR Type combobox :type row: Integer """ frozen_table = self.str_type_table.frozen_table_view model = frozen_table.model() for i in range(0, 1): frozen_table.openPersistentEditor(model.index(row, i)) def str_type_data(self): """ Gets party and str_type data from str_type page (page 3 of the wizard). It uses get_table_data() method. :return: A list containing a list of ids of the selected str related table or str_type value. :rtype: List """ str_types = [] frozen_table = self.str_type_table.frozen_table_view combo_boxes = frozen_table.findChildren(QComboBox) for combo in combo_boxes: index = combo.currentIndex() str_type = combo.itemData(index) str_types.append(str_type) return str_types def str_type_combobox(self): """ Gets str type QComboBox. :return: A list containing a STR type QComboBox :rtype: List """ frozen_table = self.str_type_table.frozen_table_view combo_boxes = frozen_table.findChildren(QComboBox) return combo_boxes def ownership_share(self): """ Gets ownership_share double spin box widgets. :return: A list containing a list double spin boxes :rtype: List """ frozen_table = self.str_type_table.frozen_table_view spinboxes = frozen_table.findChildren(QDoubleSpinBox) return spinboxes def remove_str_type_row(self, rows=[0]): """ Removes corresponding social tenure type row when a party row is removed. :param rows: List of party row position that is removed. :type rows: List """ for row in rows: self.str_type_table.model().removeRow(row)
class STRType(ComponentUtility): def __init__(self, container_widget, box, notification_bar, party=None): """ Handles the STR type component for loading tenure type and share widgets in a QTableView. :param container_widget: The container widget for the component. :type container_widget: QWidget :param box: The layout holding the container widget. :type box: QVBoxLayout :param notification_bar: The NotificationBar object that displays notification. :type notification_bar: Object :param party: The party entity from with STR type component rows are populated. By default, if None, the first party component is used. :type party: Object """ ComponentUtility.__init__(self) self.container_widget = container_widget self.container_box = box self.notification_bar = notification_bar self.str_type_data = [] self.selected_party = party self.create_str_type_table() def add_str_type_data(self, spatial_unit, row_data, insert_row): """ Adds str type date into STR Type table view. :param row_data: The table data :type row_data: List :param insert_row: The row in which the STR type row is is added. :type insert_row: Integer """ data = [None, None] + row_data self.str_type_data.append(data) self.str_type_table.add_widgets(spatial_unit, insert_row) self.update_table_view(self.str_type_table, True) self.str_type_table.model().layoutChanged.emit() # select the first column (STR Type) self.str_type_table.frozen_table_view.selectColumn(0) def copy_party_table(self, table_view, row): """ Copy rows from party table view. :param row: The row to be copied :type row: Integer :param table_view: The party table view :type table_view: QTableView :return: List of row data :rtype: List """ party_row_data = [] model = table_view.model() for col in range(model.columnCount()): party_id_idx = model.index(row, col) party_row_data.append(model.data(party_id_idx, Qt.DisplayRole)) return party_row_data def add_str_type_headers(self): """ Adds headers data for QTableView columns. The headers comes from the selected entity. :param entity: The entity for which the table header is created for. :return: List of Table headers :rtype: List """ if not self.selected_party is None: self.party_1 = self.selected_party db_model = entity_model(self.party_1, True) headers = [] # Load headers if db_model is not None: # Append str type if the method # is used for str_type str_type_header = QApplication.translate( 'STRType', 'Social Tenure Type' ) share_header = QApplication.translate( 'STRType', 'Share ' ) # First (ID) column will always be hidden headers.append(str_type_header) headers.append(share_header) display_columns = entity_display_columns(self.party_1, True) for col in display_columns.values(): headers.append(col) return headers def create_str_type_table(self): """ Creates social tenure type table that is composed of each selected party rows with a combobox for social tenure type. """ headers = self.add_str_type_headers() self.str_type_table = FreezeTableWidget( self.str_type_data, headers, self.container_widget ) self.str_type_table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.container_box.setSpacing(4) self.container_box.setMargin(5) grid_layout = QGridLayout(self.container_widget) grid_layout.setHorizontalSpacing(5) grid_layout.setColumnStretch(4, 5) self.container_box.addLayout(grid_layout) self.container_box.addWidget(self.str_type_table) def enable_str_type_widgets(self, row): """ Makes the STR Type combobox editable. :param row: The row of STR Type combobox :type row: Integer """ frozen_table = self.str_type_table.frozen_table_view model = frozen_table.model() for i in range(0, 1): frozen_table.openPersistentEditor( model.index(row, i) ) def str_type_data(self): """ Gets party and str_type data from str_type page (page 3 of the wizard). It uses get_table_data() method. :return: A list containing a list of ids of the selected str related table or str_type value. :rtype: List """ str_types = [] frozen_table = self.str_type_table.frozen_table_view combo_boxes = frozen_table.findChildren(QComboBox) for combo in combo_boxes: index = combo.currentIndex() str_type = combo.itemData(index) str_types.append(str_type) return str_types def str_type_combobox(self): """ Gets str type QComboBox. :return: A list containing a STR type QComboBox :rtype: List """ frozen_table = self.str_type_table.frozen_table_view combo_boxes = frozen_table.findChildren(QComboBox) return combo_boxes def ownership_share(self): """ Gets ownership_share double spin box widgets. :return: A list containing a list double spin boxes :rtype: List """ frozen_table = self.str_type_table.frozen_table_view spinboxes = frozen_table.findChildren(QDoubleSpinBox) return spinboxes def remove_str_type_row(self, rows=[0]): """ Removes corresponding social tenure type row when a party row is removed. :param rows: List of party row position that is removed. :type rows: List """ for row in rows: self.str_type_table.model().removeRow(row)