mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
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:
parent
a121fbe530
commit
74b55f3bf5
@ -59,7 +59,15 @@ DiagramContent::DiagramContent(Diagram *diagram, bool selected) :
|
||||
{
|
||||
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 Conductor::Type:
|
||||
{
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include <QSet>
|
||||
#include <QVector>
|
||||
|
||||
#include "../qetgraphicsitem/terminalelement.h"
|
||||
|
||||
class QGraphicsItem;
|
||||
class Conductor;
|
||||
class Element;
|
||||
@ -81,6 +83,7 @@ class DiagramContent
|
||||
QList<QGraphicsItem *> m_selected_items;
|
||||
QVector<QetGraphicsTableItem *> m_tables;
|
||||
QVector<TerminalStripItem *> m_terminal_strip;
|
||||
QVector<QPointer<TerminalElement>> m_terminal_elements;
|
||||
|
||||
|
||||
QList<DiagramTextItem *> selectedTexts() const;
|
||||
|
@ -1468,12 +1468,21 @@ void QETDiagramEditor::selectionGroupTriggered(QAction *action)
|
||||
|
||||
if (!dv || value.isEmpty()) return;
|
||||
|
||||
if (value == "delete_selection")
|
||||
{
|
||||
diagram->clearSelection();
|
||||
diagram->undoStack().push(new DeleteQGraphicsItemCommand(diagram, dc));
|
||||
dv->adjustSceneRect();
|
||||
}
|
||||
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->undoStack().push(new DeleteQGraphicsItemCommand(diagram, dc));
|
||||
dv->adjustSceneRect();
|
||||
}
|
||||
}
|
||||
else if (value == "rotate_selection")
|
||||
{
|
||||
RotateSelectionCommand *c = new RotateSelectionCommand(diagram);
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "../qetgraphicsitem/elementtextitemgroup.h"
|
||||
#include "../qetgraphicsitem/terminal.h"
|
||||
#include "addelementtextcommand.h"
|
||||
#include "../TerminalStrip/realterminal.h"
|
||||
#include "../TerminalStrip/physicalterminal.h"
|
||||
|
||||
/**
|
||||
@brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand
|
||||
@ -115,6 +117,36 @@ DeleteQGraphicsItemCommand::~DeleteQGraphicsItemCommand()
|
||||
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
|
||||
This function creates new conductors (if needed) for conserve the electrical potentials
|
||||
|
@ -34,10 +34,10 @@ class DeleteQGraphicsItemCommand : public QUndoCommand
|
||||
public:
|
||||
DeleteQGraphicsItemCommand(Diagram *diagram, const DiagramContent &content, QUndoCommand * parent = nullptr);
|
||||
~DeleteQGraphicsItemCommand() override;
|
||||
static bool hasNonDeletableTerminal(const DiagramContent &content);
|
||||
|
||||
private:
|
||||
DeleteQGraphicsItemCommand(const DeleteQGraphicsItemCommand &);
|
||||
|
||||
void setPotentialsOfRemovedElements();
|
||||
Terminal *terminalInSamePotential(Terminal *terminal, Conductor *conductor_to_exclude);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user