13 def __init__(self, initial_columns, parent=None):
15 Initialize the column configurator dialog.
17 \param initial_columns (list[str]): The initial list of customized columns.
18 \param parent (QWidget, optional): Parent widget for this dialog.
20 super(ColumnConfigurator, self).
__init__(parent)
21 self.setWindowTitle(self.tr(
"Configure Table Columns"))
32 self.
ui.cancelButton.clicked.connect(self.
reject)
37 Set up the main table to display and manage the current customized columns.
39 self.
ui.tableWidget.setColumnCount(2)
40 self.
ui.tableWidget.setHorizontalHeaderLabels([self.tr(
"Column Name"),
""])
41 self.
ui.tableWidget.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
42 self.
ui.tableWidget.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Fixed)
43 self.
ui.tableWidget.setColumnWidth(1, 40)
50 Set up a small input table for adding new column names.
52 self.
ui.addTableWidget.setColumnCount(2)
53 self.
ui.addTableWidget.setRowCount(1)
54 self.
ui.addTableWidget.horizontalHeader().setVisible(
False)
55 self.
ui.addTableWidget.verticalHeader().setVisible(
False)
56 self.
ui.addTableWidget.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
57 self.
ui.addTableWidget.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Fixed)
58 self.
ui.addTableWidget.setColumnWidth(1, 40)
60 row_height = self.
ui.addTableWidget.verticalHeader().defaultSectionSize()
61 self.
ui.addTableWidget.setFixedHeight(row_height + 2)
63 self.
ui.addTableWidget.setItem(0, 0, QTableWidgetItem())
65 add_button = QPushButton()
66 add_button.setIcon(QIcon(
":/icons/icons/editadd.svg"))
67 apply_icon_button_style(add_button)
68 add_button.setIconSize(QSize(20, 20))
69 add_button.setFixedSize(24, 24)
70 add_button.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
71 self.
ui.addTableWidget.setCellWidget(0, 1, add_button)
77 Add a new column name from the input field to the main table.
79 item = self.
ui.addTableWidget.item(0, 0)
80 col_name = item.text().strip()
if item
else ""
83 self.
ui.addTableWidget.setItem(0, 0, QTableWidgetItem())
85 QMessageBox.warning(self, self.tr(
"Input Error"), self.tr(
"Please enter a column name."))
89 Insert a new column name as a row into the main table with a delete button.
91 \param column_name (str): The name of the column to insert.
93 row_pos = self.
ui.tableWidget.rowCount()
94 self.
ui.tableWidget.insertRow(row_pos)
95 self.
ui.tableWidget.setItem(row_pos, 0, QTableWidgetItem(column_name))
97 delete_button = QPushButton()
98 delete_button.setIcon(QIcon(
":/icons/icons/editbin.svg"))
99 apply_icon_button_style(delete_button)
100 delete_button.setIconSize(QSize(20, 20))
101 delete_button.setFixedSize(24, 24)
102 delete_button.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
104 self.
ui.tableWidget.setCellWidget(row_pos, 1, delete_button)