Explorar el Código

fix: 修复横线撤销后无法再次插入

main
suyu hace 4 semanas
padre
commit
bcd0e1c40b
Se han modificado 2 ficheros con 45 adiciones y 0 borrados
  1. +11
    -0
      app/src/ui/logic_editor_widget.cpp
  2. +34
    -0
      app/tests/main_window_tests.cpp

+ 11
- 0
app/src/ui/logic_editor_widget.cpp Ver fichero

@@ -1124,6 +1124,17 @@ void LogicEditorWidget::reloadLogic()
scene_->setSceneRect(0, 0, kMinimumSceneWidth, 400);
return;
}
const bool current_rung_exists = std::any_of(
logic->rungs.cbegin(), logic->rungs.cend(),
[this](const LadderRung &rung)
{
return rung.id == current_rung_id_;
});
if (!current_rung_id_.empty() && !current_rung_exists)
{
// 撤销或重做可能移除当前网络,不能把过期 ID 继续传给编辑服务
current_rung_id_.clear();
}
if (current_rung_id_.empty() && !logic->rungs.empty())
{
current_rung_id_ = logic->rungs.front().id;


+ 34
- 0
app/tests/main_window_tests.cpp Ver fichero

@@ -1023,6 +1023,39 @@ void testLogicContinuousInsertionConsumesFullWire()
"the toolbar must reject only the eleventh condition after all wires are consumed");
}

void testLogicHorizontalWireCanBeInsertedAgainAfterUndoingFirstAutoRung()
{
TestProjectStorage storage;
ProjectService project_service(storage);
LogicEditorService service(project_service);
const std::string logic_id = service.ensureDefaultLogic().id;
LogicEditorWidget editor(service);
editor.setLogicId(logic_id);
editor.resize(1400, 360);
editor.show();
QApplication::processEvents();

require(editor.addHorizontalWire().succeeded,
"the first horizontal wire must create the initial ladder network");
const ControlLogic *logic = service.findLogic(logic_id);
require(logic != nullptr && logic->rungs.size() == 1U,
"the first horizontal wire must leave one network in the model");

require(service.undo().succeeded,
"undo must remove the automatically created network");
editor.reloadLogic();
logic = service.findLogic(logic_id);
require(logic != nullptr && logic->rungs.empty(),
"undo must restore the initially empty ladder logic");

require(editor.addHorizontalWire().succeeded,
"a horizontal wire must be insertable again after undoing the first one");
logic = service.findLogic(logic_id);
require(logic != nullptr && logic->rungs.size() == 1U
&& logic->rungs.front().condition.has_value(),
"reinserting the horizontal wire must create a fresh network");
}

void testWindowTitleTracksUnsavedProjectChanges()
{
TestProjectStorage storage;
@@ -2446,6 +2479,7 @@ int main(int argc, char *argv[])
testLogicParallelPaddingGridInsertion();
testLogicParallelBranchConnectsShortBranchToRightJoin();
testLogicContinuousInsertionConsumesFullWire();
testLogicHorizontalWireCanBeInsertedAgainAfterUndoingFirstAutoRung();
testWindowTitleTracksUnsavedProjectChanges();
testModeActionsControlEditingAvailability();
testRuntimeMonitorWindowLifecycle();


Cargando…
Cancelar
Guardar