重构SA打标界面事件索引处理逻辑,优化数据过滤和显示功能

This commit is contained in:
marques
2025-08-31 21:06:59 +08:00
parent 728b020db6
commit 95d58b94a7

View File

@ -528,8 +528,6 @@ class DataFrameModel(QAbstractTableModel):
# 当isLabeled列为1时整行前景变色
if role == Qt.ForegroundRole and "isLabeled" in self._dataframe.columns:
try:
print(self._showdata.iloc[row]["Index"])
event_index = self._showdata.iloc[row]["Index"]
is_labeled_value = self._dataframe[self._dataframe["Index"] == event_index]["isLabeled"]
if is_labeled_value.empty:
@ -570,7 +568,7 @@ class DataFrameModel(QAbstractTableModel):
return self._header_mapping.get(self._display_columns[section], self._display_columns[section])
return str(section + 1)
def get_data(self, index):
def get_event_index(self, index):
if not index.isValid():
return None
row = index.row()
@ -591,6 +589,7 @@ class DataFrameModel(QAbstractTableModel):
# Filter the DataFrame based on the filter text
filtered_df = self._dataframe[
self._dataframe.apply(lambda row: row.astype(str).str.contains(filter_text, case=False).any(), axis=1)]
filtered_df.reset_index(drop=True, inplace=True)
self._showdata = filtered_df[self._display_columns].copy()
self.layoutChanged.emit() # Notify the view that the data has changed
@ -852,7 +851,7 @@ class MainWindow_SA_label(QMainWindow):
self.ui.pushButton_quick_remark_input_changeOnMiddle.setShortcut(
QCoreApplication.translate("MainWindow", Params. SA_LABEL_BTN_CHANGED_ON_MIDDLE_SHORTCUT_KEY)
)
self.ui.pushButton_quick_remark_input_noNormalRespBetweenArtifact(
self.ui.pushButton_quick_remark_input_noNormalRespBetweenArtifact.setShortcut(
).setShortcut(
QCoreApplication.translate("MainWindow", Params. SA_LABEL_BTN_BETWEEN_ARTIFACT_SHORTCUT_KEY)
)
@ -912,27 +911,45 @@ class MainWindow_SA_label(QMainWindow):
if self.sender() == self.debounce_timer1:
self.data_model_origin.filter_data(self.ui.lineEdit_filter_label_origin.text())
elif self.sender() == self.debounce_timer2:
self.data_model_revised.filter_data(self.ui.lineEdit_filter_label_revised.text())
def show_selected_event(self, index):
# 通过点击选中
if isinstance(index, int):
table_index = index
event_index = index
keep_xlim = True
# 从左侧列表中直接获取当前表中选中行的事件编号列的内容
elif hasattr(index, "model"):
if index.model() == self.data_model_origin:
table_index = self.data_model_origin.get_data(index)
event_index = self.data_model_origin.get_event_index(index)
elif index.model() == self.data_model_revised:
table_index = self.data_model_revised.get_data(index)
event_index = self.data_model_revised.get_event_index(index)
else:
return
keep_xlim = False
else:
return
self.show_event_info(table_index)
self.__jump_to__event__(table_index, keep_xlim=keep_xlim)
print(index, event_index)
# 表格移动到指定行
row_list = self.data_model_revised._showdata[self.data_model_revised._showdata["Index"] == event_index].index.tolist()
if row_list:
row = row_list[0]
model_index = self.data_model_revised.index(row, 0)
self.ui.tableView_label_revised.scrollTo(model_index, self.ui.tableView_label_revised.ScrollHint.PositionAtCenter)
# 显示事件信息
row_list = self.data_model_origin._showdata[self.data_model_origin._showdata["Index"] == event_index].index.tolist()
if row_list:
row = row_list[0]
model_index = self.data_model_origin.index(row, 0)
self.ui.tableView_label.scrollTo(model_index, self.ui.tableView_label.ScrollHint.PositionAtCenter)
self.show_event_info(event_index)
self.__jump_to__event__(event_index, keep_xlim=keep_xlim)
def on_press(self, event):
# 只在编辑模式下响应左键按下事件