From 340577abe413d18f97c680f0e946777460c90ad5 Mon Sep 17 00:00:00 2001 From: suyu <1643689728@qq.com> Date: Sat, 22 Aug 2026 14:26:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=9D=E6=8C=81=E5=B9=B6=E8=81=94?= =?UTF-8?q?=E8=A1=A5=E7=BA=BF=E9=80=89=E4=B8=AD=E6=80=81=E6=A8=AA=E7=BA=BF?= =?UTF-8?q?=E5=8F=AF=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/ui/logic_editor_widget.cpp | 18 +++++++++++++++--- app/tests/main_window_tests.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/app/src/ui/logic_editor_widget.cpp b/app/src/ui/logic_editor_widget.cpp index 1f2d413..f054f0a 100644 --- a/app/src/ui/logic_editor_widget.cpp +++ b/app/src/ui/logic_editor_widget.cpp @@ -650,11 +650,13 @@ public: int column, const QPointF ¢er, bool show_label, - std::string branch_expression_id = {}) + std::string branch_expression_id = {}, + bool branch_active = false) : rung_id_(rung_id), branch_expression_id_(std::move(branch_expression_id)), column_(column), - show_label_(show_label) + show_label_(show_label), + branch_active_(branch_active) { setPos(center); setFlag(ItemIsSelectable, true); @@ -686,6 +688,14 @@ public: painter->setPen(QPen(kSelectionBorderColor, 1.4, Qt::DashLine)); painter->drawRect(boundingRect().adjusted(3, 3, -3, -3)); } + if (!branch_expression_id_.empty()) + { + // 选中补线格时仍需把结构横线绘制在选框上层 + painter->setPen(ladderPen(branch_active_)); + painter->drawLine( + QPointF(-kCellWidth / 2.0, 0), + QPointF(kCellWidth / 2.0, 0)); + } if (show_label_) { painter->setPen(kPlaceholderColor); @@ -708,6 +718,7 @@ private: std::string branch_expression_id_; int column_ = 0; bool show_label_ = false; + bool branch_active_ = false; }; class LogicEditorWidget::VerticalConnectorItem final : public QGraphicsItem @@ -1046,7 +1057,8 @@ RenderResult renderExpression( + (static_cast(column) + 0.5) * kCellWidth, branches[index].output.y()), false, - expression.children[index].id)); + expression.children[index].id, + branch_active)); } } return {QPointF(left_join, top_y), QPointF(right_join, top_y)}; diff --git a/app/tests/main_window_tests.cpp b/app/tests/main_window_tests.cpp index b3a74b3..a117d68 100644 --- a/app/tests/main_window_tests.cpp +++ b/app/tests/main_window_tests.cpp @@ -853,6 +853,32 @@ void testLogicParallelPaddingGridInsertion() && editor.scene()->selectedItems().front()->toolTip().startsWith( QStringLiteral("并联空网格")), "clicking a parallel padding line must select its grid cell, not the rung"); + QImage selected_branch_cell(128, 120, QImage::Format_ARGB32_Premultiplied); + selected_branch_cell.fill(Qt::white); + { + QPainter painter(&selected_branch_cell); + const QPointF center = branch_slots.back()->scenePos(); + editor.scene()->render( + &painter, + QRectF(0, 0, 128, 120), + QRectF(center.x() - 64, center.y() - 60, 128, 120)); + } + bool selected_line_visible = false; + for (int x = 12; x < selected_branch_cell.width() - 12 && !selected_line_visible; + ++x) + { + for (int y = 58; y <= 62; ++y) + { + const QColor pixel = selected_branch_cell.pixelColor(x, y); + if (pixel.red() < 100 && pixel.green() < 120 && pixel.blue() < 130) + { + selected_line_visible = true; + break; + } + } + } + require(selected_line_visible, + "selecting a parallel padding cell must keep its horizontal wire visible"); const LogicEditorResult inserted = editor.addCondition(logicContact(12)); require(inserted.succeeded, "the normal condition action must insert into a selected parallel grid cell");