2021-12-01 21:27:04 +01:00
|
|
|
/*
|
2024-03-29 10:09:48 +01:00
|
|
|
Copyright 2006-2024 The QElectroTech Team
|
2021-12-01 21:27:04 +01:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "bridgeterminalscommand.h"
|
2022-11-14 21:10:38 +01:00
|
|
|
#include "../terminalstripbridge.h"
|
2021-12-01 21:27:04 +01:00
|
|
|
|
|
|
|
BridgeTerminalsCommand::BridgeTerminalsCommand(TerminalStrip *strip,
|
2021-12-26 17:26:00 +01:00
|
|
|
QVector<QSharedPointer<RealTerminal>> real_terminal,
|
2021-12-01 21:27:04 +01:00
|
|
|
QUndoCommand *parent):
|
|
|
|
QUndoCommand(parent),
|
|
|
|
m_strip(strip),
|
2021-12-19 14:55:02 +01:00
|
|
|
m_real_terminal_vector(real_terminal)
|
2021-12-01 21:27:04 +01:00
|
|
|
{
|
|
|
|
setText(QObject::tr("Ponter des bornes entre-elles"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BridgeTerminalsCommand::undo()
|
|
|
|
{
|
|
|
|
if (m_strip) {
|
2021-12-19 14:55:02 +01:00
|
|
|
m_strip->unBridge(m_real_terminal_vector);
|
2021-12-01 21:27:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BridgeTerminalsCommand::redo()
|
|
|
|
{
|
2022-01-27 20:00:46 +01:00
|
|
|
if (m_strip)
|
|
|
|
{
|
|
|
|
if (m_bridge) {
|
|
|
|
m_strip->setBridge(m_bridge, m_real_terminal_vector);
|
|
|
|
} else {
|
|
|
|
m_strip->setBridge(m_real_terminal_vector);
|
|
|
|
m_bridge = m_strip->isBridged(m_real_terminal_vector.first());
|
|
|
|
}
|
2021-12-01 21:27:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UnBridgeTerminalsCommand::UnBridgeTerminalsCommand(TerminalStrip *strip,
|
2021-12-26 17:26:00 +01:00
|
|
|
QVector<QSharedPointer<RealTerminal>> real_terminal,
|
2021-12-01 21:27:04 +01:00
|
|
|
QUndoCommand *parent):
|
|
|
|
QUndoCommand(parent),
|
|
|
|
m_strip(strip)
|
|
|
|
{
|
|
|
|
setText(QObject::tr("Supprimer des ponts de bornes"));
|
|
|
|
|
2021-12-22 19:21:54 +01:00
|
|
|
if (strip->canUnBridge(real_terminal))
|
2021-12-01 21:27:04 +01:00
|
|
|
{
|
2022-11-14 21:10:38 +01:00
|
|
|
m_bridge = strip->isBridged(real_terminal.first());
|
|
|
|
|
|
|
|
//If bridge have one more terminals than @real_terminal
|
|
|
|
//that mean every terminals of the bridge must be unbridged by this undo command,
|
|
|
|
//else the single terminal who's not umbridged by this undo command
|
|
|
|
//continue to have a bridge (to nothing) and this nowhere bridge is visible
|
|
|
|
//in the terminal strip graphic item and terminal strip editor dialog.
|
|
|
|
if (m_bridge->realTerminals().size() == real_terminal.size() + 1) {
|
|
|
|
m_terminals = m_bridge->realTerminals();
|
|
|
|
} else {
|
|
|
|
m_terminals = real_terminal;
|
|
|
|
}
|
2021-12-01 21:27:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnBridgeTerminalsCommand::undo()
|
|
|
|
{
|
2021-12-22 19:21:54 +01:00
|
|
|
if (m_strip && m_bridge) {
|
2021-12-26 17:26:00 +01:00
|
|
|
m_strip->setBridge(m_bridge, m_terminals);
|
2021-12-01 21:27:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnBridgeTerminalsCommand::redo()
|
|
|
|
{
|
|
|
|
if (m_strip) {
|
2021-12-22 19:21:54 +01:00
|
|
|
m_strip->unBridge(m_terminals);
|
2021-12-01 21:27:04 +01:00
|
|
|
}
|
|
|
|
}
|