Przeglądaj źródła

fix: 保持并联补线选中态横线可见

main
suyu 4 tygodni temu
rodzic
commit
340577abe4
2 zmienionych plików z 41 dodań i 3 usunięć
  1. +15
    -3
      app/src/ui/logic_editor_widget.cpp
  2. +26
    -0
      app/tests/main_window_tests.cpp

+ 15
- 3
app/src/ui/logic_editor_widget.cpp Wyświetl plik

@@ -650,11 +650,13 @@ public:
int column,
const QPointF &center,
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<qreal>(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)};


+ 26
- 0
app/tests/main_window_tests.cpp Wyświetl plik

@@ -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");


Ładowanie…
Anuluj
Zapisz