mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Terminal element can be removed from a terminal strip
This commit is contained in:
@@ -115,3 +115,42 @@ void AddTerminalToStripCommand::redo()
|
||||
|
||||
m_new_strip->addTerminal(m_terminal);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RemoveTerminalFromStripCommand::RemoveTerminalFromStripCommand
|
||||
* @param terminal
|
||||
* @param strip
|
||||
* @param parent
|
||||
*/
|
||||
RemoveTerminalFromStripCommand::RemoveTerminalFromStripCommand(TerminalElement *terminal,
|
||||
TerminalStrip *strip,
|
||||
QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_terminal(terminal),
|
||||
m_strip(strip)
|
||||
{
|
||||
auto t_label = terminal->actualLabel();
|
||||
auto strip_name = strip->name();
|
||||
|
||||
auto str_1 = t_label.isEmpty() ? QObject::tr("Enlever une borne") :
|
||||
QObject::tr("Enlever la borne %1").arg(t_label);
|
||||
|
||||
auto str_2 = strip_name.isEmpty() ? QObject::tr("d'un groupe de bornes") :
|
||||
QObject::tr("du groupe de bornes %1").arg(strip_name);
|
||||
setText(str_1 + " " + str_2);
|
||||
}
|
||||
|
||||
void RemoveTerminalFromStripCommand::undo()
|
||||
{
|
||||
if (m_terminal && m_strip) {
|
||||
m_strip->addTerminal(m_terminal);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveTerminalFromStripCommand::redo()
|
||||
{
|
||||
if (m_terminal && m_strip) {
|
||||
m_strip->removeTerminal(m_terminal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2021 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@@ -57,4 +57,23 @@ class AddTerminalToStripCommand : public QUndoCommand
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The RemoveTerminalFromStripCommand class
|
||||
* Remove a terminal from a terminal strip.
|
||||
* The removed terminal become free.
|
||||
*/
|
||||
class RemoveTerminalFromStripCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
RemoveTerminalFromStripCommand (TerminalElement *terminal, TerminalStrip *strip, QUndoCommand *parent = nullptr);
|
||||
~RemoveTerminalFromStripCommand() override {}
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
QPointer<TerminalElement> m_terminal;
|
||||
QPointer<TerminalStrip> m_strip;
|
||||
};
|
||||
|
||||
#endif // ADDTERMINALTOSTRIPCOMMAND_H
|
||||
|
||||
@@ -83,6 +83,19 @@ void TerminalStripEditor::setUpUndoConnections()
|
||||
m_project->undoStack()->push(undo);
|
||||
});
|
||||
|
||||
connect(ui->m_terminal_strip_tw, &TerminalStripTreeWidget::terminalRemovedFromStrip,
|
||||
[this] (QUuid terminal_uuid, QUuid old_strip_uuid)
|
||||
{
|
||||
auto terminal_ = m_uuid_terminal_H.value(terminal_uuid);
|
||||
auto strip_ = m_uuid_strip_H.value(old_strip_uuid);
|
||||
|
||||
if (!terminal_ || !strip_) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto undo = new RemoveTerminalFromStripCommand(terminal_, strip_);
|
||||
m_project->undoStack()->push(undo);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,9 +122,9 @@ void TerminalStripTreeWidget::dropEvent(QDropEvent *event)
|
||||
if (overred_item->type() == FreeTerminal) //Free terminal
|
||||
{
|
||||
emit terminalRemovedFromStrip(QUuid::fromString(dragged_item->data(0, UUID_USER_ROLE).toString()),
|
||||
QUuid::fromString(overred_item->data(0, UUID_USER_ROLE).toString()));
|
||||
QUuid::fromString(old_parent->data(0, UUID_USER_ROLE).toString()));
|
||||
}
|
||||
else if (overred_item->type() == Strip)
|
||||
else if (overred_item->type() == Strip) //To another strip
|
||||
{
|
||||
emit terminalMovedFromStripToStrip(QUuid::fromString(dragged_item->data(0, UUID_USER_ROLE).toString()),
|
||||
QUuid::fromString(old_parent->data(0, UUID_USER_ROLE).toString()),
|
||||
|
||||
Reference in New Issue
Block a user