Deletes Cable if Node gets deleted
Some checks failed
Build Skui / Build on ubuntu-latest (pull_request) Successful in 1m22s
Validate format using clang / Formatting Check (pull_request) Failing after 28s

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-23 21:24:38 +02:00
parent c68cbe92d5
commit e683a64393
2 changed files with 6 additions and 4 deletions

View File

@@ -8,6 +8,9 @@ Cable::Cable(QGraphicsItem *parent, const Pad *start_pad)
setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::LeftButton);
// Delete the cable if the start pad is deleted.
connect(m_start_pad, &QObject::destroyed, this, &Cable::deleteLater);
connect(m_start_pad, &Pad::positionChanged, this, &Cable::updateStartCablePosition);
// Init cable
@@ -34,7 +37,6 @@ void Cable::updateStartCablePosition()
first_segment.end_point.setX(dock_point.x());
second_segment.start_point = first_segment.end_point;
}
setEditable(restore_enable);
update();
@@ -62,7 +64,6 @@ void Cable::updateEndCablePosition()
last_segment.start_point.setX(dock_point.x());
second_last_segment.end_point = last_segment.start_point;
}
setEditable(restore_enable);
update();
@@ -119,7 +120,6 @@ void Cable::previewCable(QPoint point)
}
// Preview Segements are part of the cable segments and counted backwards.
CableSegment &first_preview_segment = m_cable_segments.last();
CableSegment &second_preview_segment = m_cable_segments[m_cable_segments.size() - 2];
@@ -224,6 +224,7 @@ void Cable::mousePressEvent(QGraphicsSceneMouseEvent *event)
bool is_end_pad = current_pad && current_pad != m_start_pad;
if (is_end_pad) {
m_end_pad = current_pad;
connect(m_end_pad, &QObject::destroyed, this, &Cable::deleteLater);
connect(m_end_pad, &Pad::positionChanged, this, &Cable::updateEndCablePosition);
endCorner(m_end_pad->getSceneDockPoint());

View File

@@ -4,6 +4,7 @@
#include <QGraphicsScene>
#include <QGuiApplication>
#include <QLoggingCategory>
#include <QPointer>
#include "./graphicsitems/cable.h"
#include "./graphicsitems/node_graphicsitem.h"
@@ -27,7 +28,7 @@ private:
int m_debug_x = 0;
QList<Node *> m_nodes;
QCursor m_cursor_before_pad;
Cable *m_last_cable = nullptr;
QPointer<Cable> m_last_cable = nullptr;
};
#endif // NODEEDITOR_SCENE_H