perf(ui): bound plan edit work and release finished BOM previews
This commit is contained in:
1 parent
b3883cfca1
commit
84d8f9c7f5
6 files changed
+99
-10
No files matched your search
@@ -276,6 +276,7 @@ class TrialTaskCenterWindow(QMainWindow):
|
||||
def _update_gates(self):
|
||||
busy = bool(self._workers) or self._loading
|
||||
state = execution_state(self._context, busy=busy, dirty=self.plan_panel.table.dirty)
|
||||
group_unsaved = self._group_has_unsaved_plans() if state.editable or state.new_round else False
|
||||
context = self._context
|
||||
self.run_panel.quick_run_button.setText(state.execute_text)
|
||||
self.run_panel.quick_run_button.setEnabled(state.execute)
|
||||
@@ -284,14 +285,14 @@ class TrialTaskCenterWindow(QMainWindow):
|
||||
self.run_panel.recover_button.setVisible(bool(context and context.interrupted))
|
||||
self.run_panel.recover_button.setEnabled(state.recover)
|
||||
self.run_panel.new_round_button.setVisible(bool(context and context.task.status is TaskStatus.COMPLETED))
|
||||
self.run_panel.new_round_button.setEnabled(state.new_round and not self._group_has_unsaved_plans())
|
||||
self.run_panel.new_round_button.setEnabled(state.new_round and not group_unsaved)
|
||||
self.run_panel.history_button.setVisible(bool(context and
|
||||
(context.has_evidence or context.task.status is TaskStatus.COMPLETED or context.task.summary.startswith('new round '))))
|
||||
self.run_panel.history_button.setEnabled(bool(context and not busy))
|
||||
self.run_panel.stop_queue_button.setVisible(self._batch_stop is not None)
|
||||
self.run_panel.stop_queue_button.setEnabled(bool(self._batch_stop and not self._batch_stop.is_set()))
|
||||
self.run_panel.copy_value_check.setEnabled(state.editable)
|
||||
rule_editable = state.editable and not self._group_has_unsaved_plans()
|
||||
rule_editable = state.editable and not group_unsaved
|
||||
self.mapping_table.set_rules_editable(rule_editable)
|
||||
self.plan_panel.set_plan_editable(state.editable, busy=busy)
|
||||
self.add_mapping_button.setEnabled(rule_editable)
|
||||
@@ -313,8 +314,8 @@ class TrialTaskCenterWindow(QMainWindow):
|
||||
self.task_list.delete_button.setText('彻底删除' if deleted else '删除')
|
||||
self.task_list.restore_button.setEnabled(deleted and not busy)
|
||||
grouped = bool(context and not context.legacy and context.task.group_id and not deleted)
|
||||
group_ids = tuple(t.task_id for t in self._tasks if context and t.group_id == context.task.group_id
|
||||
and t.status is not TaskStatus.DELETED)
|
||||
group_ids = {t.task_id for t in self._tasks if context and t.group_id == context.task.group_id
|
||||
and t.status is not TaskStatus.DELETED}
|
||||
group_dirty = self.plan_panel.has_unsaved_plan(group_ids)
|
||||
group_active = any(t.status in {TaskStatus.RUNNING, TaskStatus.PAUSED} for t in self._tasks if t.task_id in group_ids)
|
||||
self.task_list.queue_button.setEnabled(grouped and not busy and not group_dirty and not bool(context.interrupted))
|
||||
|
||||
@@ -343,6 +343,16 @@ class ProjectPlanPanel(QWidget):
|
||||
self._bom_batches.clear()
|
||||
self._orphaned_bom_batches.clear()
|
||||
self.table.dirty = False
|
||||
self._release_bom_previews()
|
||||
|
||||
def _release_bom_previews(self, saved=None):
|
||||
for scope, (report, text, title) in tuple(self._bom_reports.items()):
|
||||
preview = report.preview
|
||||
if preview is not None and (saved is None or all(p.task_id in saved for p in preview.projects)):
|
||||
text = '\n'.join(text.splitlines()[:-1]) + ('\n校验通过,位号计划已保存。' if saved is not None
|
||||
else '\n本次导入预览已放弃,校验报告保留。')
|
||||
self._bom_reports[scope] = (replace(report, preview=None), text, title)
|
||||
self._restore_bom_report(self._report_scope(self.task_id))
|
||||
|
||||
def cancel_operation(self):
|
||||
if self._operation_stop is not None:
|
||||
@@ -372,19 +382,19 @@ class ProjectPlanPanel(QWidget):
|
||||
self.summary.setText(message)
|
||||
|
||||
def _summary(self):
|
||||
rows = self.table.rows()
|
||||
count = self.table.plan_model.rowCount()
|
||||
batch = self._active_bom_batch()
|
||||
self.save_button.setText('保存本批位号计划' if batch else '保存位号计划')
|
||||
if batch:
|
||||
self.summary.setText(f'本批 BOM 已匹配 {len(batch.projects)} 个工程;表格显示当前工程,切换任务可编辑,'
|
||||
'确认后一次保存本批位号计划。')
|
||||
return
|
||||
if not rows:
|
||||
if not count:
|
||||
self.summary.setText('先添加旧、新料号规则,再采集位号;可直接编辑,Excel 导入导出为可选操作。')
|
||||
if rows:
|
||||
selected = sum(row.enabled for row in rows)
|
||||
if count:
|
||||
selected = self.table.plan_model.enabled_count
|
||||
suffix = ';有未保存编辑,请先保存' if self.table.dirty else ''
|
||||
self.summary.setText(f'当前工程:{len(rows)} 个位号,替换 {selected} 个、保留 {len(rows)-selected} 个{suffix}。同步 NC 按行设置。')
|
||||
self.summary.setText(f'当前工程:{count} 个位号,替换 {selected} 个、保留 {count-selected} 个{suffix}。同步 NC 按行设置。')
|
||||
|
||||
def _changed(self):
|
||||
self._summary()
|
||||
@@ -399,7 +409,7 @@ class ProjectPlanPanel(QWidget):
|
||||
if self._active_bom_batch():
|
||||
self.collect_button.setEnabled(False)
|
||||
self.export_button.setEnabled(self._editable and bool(self.task_id)
|
||||
and bool(self.table.rows()) and not self.table.dirty)
|
||||
and bool(self.table.plan_model.rowCount()) and not self.table.dirty)
|
||||
self.export_bom_button.setEnabled(not busy)
|
||||
|
||||
def _dispatch(self, operation, callback, button):
|
||||
@@ -559,6 +569,7 @@ class ProjectPlanPanel(QWidget):
|
||||
self._changed()
|
||||
|
||||
def _saved_bom_batch(self, saved):
|
||||
self._release_bom_previews(saved)
|
||||
for task_id in saved:
|
||||
self._drafts.pop(task_id, None)
|
||||
self._orphaned_bom_batches.pop(task_id, None)
|
||||
|
||||
@@ -12,6 +12,7 @@ class TargetPlanModel(QAbstractTableModel):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.rows = []
|
||||
self.enabled_count = 0
|
||||
self.search_text = []
|
||||
self.editable = True
|
||||
@staticmethod
|
||||
@@ -22,6 +23,7 @@ class TargetPlanModel(QAbstractTableModel):
|
||||
def populate(self, rows):
|
||||
self.beginResetModel()
|
||||
self.rows = list(rows)
|
||||
self.enabled_count = sum(row.enabled for row in self.rows)
|
||||
self.search_text = [self.searchable(row) for row in self.rows]
|
||||
self.endResetModel()
|
||||
def rowCount(self, parent=QModelIndex()):
|
||||
@@ -68,6 +70,7 @@ class TargetPlanModel(QAbstractTableModel):
|
||||
updated = replace(self.rows[number], **change)
|
||||
if updated == self.rows[number]:
|
||||
return False
|
||||
self.enabled_count += int(updated.enabled) - int(self.rows[number].enabled)
|
||||
self.rows[number] = updated
|
||||
self.search_text[number] = self.searchable(updated)
|
||||
self.dataChanged.emit(index, index, [role, Qt.ItemDataRole.DisplayRole])
|
||||
@@ -83,6 +86,7 @@ class TargetPlanModel(QAbstractTableModel):
|
||||
for number in numbers:
|
||||
updated = replace(self.rows[number], **{field: value})
|
||||
if updated != self.rows[number]:
|
||||
self.enabled_count += int(updated.enabled) - int(self.rows[number].enabled)
|
||||
self.rows[number] = updated
|
||||
self.search_text[number] = self.searchable(updated)
|
||||
changed.append(number)
|
||||
|
||||
Reference in new issue
Block a user