Disable deletion if a terminal can't be deleted.

In case of user try to delete a terminal element who is bridged
or belong to a physical terminal with more than one level, the deletion
is aborted to avoid mistake in the terminal strip parent of the terminal
element. A dialog is opened when the deletion can't be to explain to
user what to do for enable the deletion.
This commit is contained in:
joshua
2025-07-24 22:24:15 +02:00
parent a121fbe530
commit 74b55f3bf5
5 changed files with 60 additions and 8 deletions

View File

@@ -59,7 +59,15 @@ DiagramContent::DiagramContent(Diagram *diagram, bool selected) :
{ {
switch (item->type()) switch (item->type())
{ {
case Element::Type: { m_elements << qgraphicsitem_cast<Element *>(item); break;} case Element::Type:
{
auto element = qgraphicsitem_cast<Element *>(item);
m_elements << element;
if (element->elementData().m_type == ElementData::Terminale) {
m_terminal_elements << static_cast<TerminalElement*>(element);
}
break;
}
case IndependentTextItem::Type: { m_text_fields << qgraphicsitem_cast<IndependentTextItem *>(item); break;} case IndependentTextItem::Type: { m_text_fields << qgraphicsitem_cast<IndependentTextItem *>(item); break;}
case Conductor::Type: case Conductor::Type:
{ {

View File

@@ -21,6 +21,8 @@
#include <QSet> #include <QSet>
#include <QVector> #include <QVector>
#include "../qetgraphicsitem/terminalelement.h"
class QGraphicsItem; class QGraphicsItem;
class Conductor; class Conductor;
class Element; class Element;
@@ -81,6 +83,7 @@ class DiagramContent
QList<QGraphicsItem *> m_selected_items; QList<QGraphicsItem *> m_selected_items;
QVector<QetGraphicsTableItem *> m_tables; QVector<QetGraphicsTableItem *> m_tables;
QVector<TerminalStripItem *> m_terminal_strip; QVector<TerminalStripItem *> m_terminal_strip;
QVector<QPointer<TerminalElement>> m_terminal_elements;
QList<DiagramTextItem *> selectedTexts() const; QList<DiagramTextItem *> selectedTexts() const;

View File

@@ -1470,10 +1470,19 @@ void QETDiagramEditor::selectionGroupTriggered(QAction *action)
if (value == "delete_selection") if (value == "delete_selection")
{ {
if (DeleteQGraphicsItemCommand::hasNonDeletableTerminal(dc)) {
QET::QetMessageBox::information(this,
tr("Suppression de borne impossible"),
tr("La suppression ne peut être effectué car la selection "
"possède une ou plusieurs bornes ponté et/ou appartenant à une borne à niveau multiple.\n"
"Déponter et/ou supprimer les niveaux des bornes concerné "
"afin de pouvoir les supprimer"));
} else {
diagram->clearSelection(); diagram->clearSelection();
diagram->undoStack().push(new DeleteQGraphicsItemCommand(diagram, dc)); diagram->undoStack().push(new DeleteQGraphicsItemCommand(diagram, dc));
dv->adjustSceneRect(); dv->adjustSceneRect();
} }
}
else if (value == "rotate_selection") else if (value == "rotate_selection")
{ {
RotateSelectionCommand *c = new RotateSelectionCommand(diagram); RotateSelectionCommand *c = new RotateSelectionCommand(diagram);

View File

@@ -28,6 +28,8 @@
#include "../qetgraphicsitem/elementtextitemgroup.h" #include "../qetgraphicsitem/elementtextitemgroup.h"
#include "../qetgraphicsitem/terminal.h" #include "../qetgraphicsitem/terminal.h"
#include "addelementtextcommand.h" #include "addelementtextcommand.h"
#include "../TerminalStrip/realterminal.h"
#include "../TerminalStrip/physicalterminal.h"
/** /**
@brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand @brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand
@@ -115,6 +117,36 @@ DeleteQGraphicsItemCommand::~DeleteQGraphicsItemCommand()
m_diagram->qgiManager().release(m_removed_contents.items(DiagramContent::All)); m_diagram->qgiManager().release(m_removed_contents.items(DiagramContent::All));
} }
/**
* @brief DeleteQGraphicsItemCommand::hasNonDeletableTerminal
* Return true if @content have terminal element which can't be deleted.
* The reason why a terminal can't be deleted is because they have bridge
* or belong to a physical terminal with more than one level.
* @param diagram
* @param content
* @param dialog
* @return
*/
bool DeleteQGraphicsItemCommand::hasNonDeletableTerminal(const DiagramContent &content)
{
if (!content.m_terminal_elements.isEmpty())
{
for (const auto &terminal : content.m_terminal_elements)
{
if (!terminal.isNull())
{
if (terminal->parentTerminalStrip()
&& (terminal->realTerminal()->isBridged()
|| terminal->realTerminal()->physicalTerminal()->levelCount() != 1)) {
return true;
}
}
}
}
return false;
}
/** /**
@brief DeleteQGraphicsItemCommand::setPotentialsOfRemovedElements @brief DeleteQGraphicsItemCommand::setPotentialsOfRemovedElements
This function creates new conductors (if needed) for conserve the electrical potentials This function creates new conductors (if needed) for conserve the electrical potentials

View File

@@ -34,10 +34,10 @@ class DeleteQGraphicsItemCommand : public QUndoCommand
public: public:
DeleteQGraphicsItemCommand(Diagram *diagram, const DiagramContent &content, QUndoCommand * parent = nullptr); DeleteQGraphicsItemCommand(Diagram *diagram, const DiagramContent &content, QUndoCommand * parent = nullptr);
~DeleteQGraphicsItemCommand() override; ~DeleteQGraphicsItemCommand() override;
static bool hasNonDeletableTerminal(const DiagramContent &content);
private: private:
DeleteQGraphicsItemCommand(const DeleteQGraphicsItemCommand &); DeleteQGraphicsItemCommand(const DeleteQGraphicsItemCommand &);
void setPotentialsOfRemovedElements(); void setPotentialsOfRemovedElements();
Terminal *terminalInSamePotential(Terminal *terminal, Conductor *conductor_to_exclude); Terminal *terminalInSamePotential(Terminal *terminal, Conductor *conductor_to_exclude);