mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 09:40:52 +01:00
Improve undo command when remove a terminal strip
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "addterminalstripcommand.h"
|
||||
#include "../../qetproject.h"
|
||||
#include "../terminalstrip.h"
|
||||
#include "../qetgraphicsitem/element.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
@@ -56,7 +57,8 @@ RemoveTerminalStripCommand::RemoveTerminalStripCommand(TerminalStrip *strip,
|
||||
QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_strip(strip),
|
||||
m_project(project)
|
||||
m_project(project),
|
||||
m_elements(strip->terminalElement())
|
||||
{
|
||||
setText(QObject::tr("Supprimer un groupe de bornes"));
|
||||
}
|
||||
@@ -67,6 +69,9 @@ RemoveTerminalStripCommand::~RemoveTerminalStripCommand()
|
||||
void RemoveTerminalStripCommand::undo()
|
||||
{
|
||||
if (m_project && m_strip) {
|
||||
for (auto elmt : m_elements) {
|
||||
m_strip->addTerminal(elmt);
|
||||
}
|
||||
m_project->addTerminalStrip(m_strip);
|
||||
}
|
||||
}
|
||||
@@ -74,6 +79,9 @@ void RemoveTerminalStripCommand::undo()
|
||||
void RemoveTerminalStripCommand::redo()
|
||||
{
|
||||
if (m_project && m_strip) {
|
||||
for (auto elmt : m_elements) {
|
||||
m_strip->removeTerminal(elmt);
|
||||
}
|
||||
m_project->removeTerminalStrip(m_strip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
class TerminalStrip;
|
||||
class QETProject;
|
||||
class Element;
|
||||
|
||||
class AddTerminalStripCommand : public QUndoCommand
|
||||
{
|
||||
@@ -50,6 +51,7 @@ class RemoveTerminalStripCommand : public QUndoCommand
|
||||
private:
|
||||
QPointer<TerminalStrip> m_strip;
|
||||
QPointer<QETProject> m_project;
|
||||
QVector<QPointer<Element>> m_elements;
|
||||
};
|
||||
|
||||
#endif // ADDTERMINALSTRIPCOMMAND_H
|
||||
|
||||
@@ -247,6 +247,8 @@ bool TerminalStrip::addTerminal(Element *terminal)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_terminal_elements_vector.append(terminal);
|
||||
|
||||
//Create the real terminal
|
||||
shared_real_terminal real_terminal(new RealTerminal(this, terminal));
|
||||
m_real_terminals.append(real_terminal);
|
||||
@@ -271,6 +273,11 @@ bool TerminalStrip::addTerminal(Element *terminal)
|
||||
*/
|
||||
bool TerminalStrip::removeTerminal(Element *terminal)
|
||||
{
|
||||
if (m_terminal_elements_vector.contains(terminal))
|
||||
{
|
||||
m_terminal_elements_vector.removeOne(terminal);
|
||||
|
||||
//Get the real and physical terminal associated to @terminal
|
||||
if (auto real_terminal = realTerminal(terminal))
|
||||
{
|
||||
if (auto physical_terminal = physicalTerminal(real_terminal))
|
||||
@@ -290,6 +297,9 @@ bool TerminalStrip::removeTerminal(Element *terminal)
|
||||
return true;
|
||||
}
|
||||
|
||||
//There is no reason to be here, but in case of....
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -332,6 +342,14 @@ TerminalStripIndex TerminalStrip::index(int index)
|
||||
return tsi_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::terminalElement
|
||||
* @return A vector of all terminal element owned by this strip
|
||||
*/
|
||||
QVector<QPointer<Element> > TerminalStrip::terminalElement() const {
|
||||
return m_terminal_elements_vector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::realTerminal
|
||||
* @param terminal
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2021 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@@ -58,6 +58,8 @@ class TerminalStrip : public QObject
|
||||
int physicalTerminalCount() const;
|
||||
TerminalStripIndex index(int index = 0);
|
||||
|
||||
QVector<QPointer<Element>> terminalElement() const;
|
||||
|
||||
private:
|
||||
QSharedPointer<RealTerminal> realTerminal(Element *terminal);
|
||||
QSharedPointer<PhysicalTerminal> physicalTerminal(QSharedPointer<RealTerminal> terminal);
|
||||
|
||||
Reference in New Issue
Block a user