Improve undo command when remove a terminal strip

This commit is contained in:
joshua
2021-04-30 19:15:10 +02:00
parent 2572e1c25d
commit d551c8e6b9
4 changed files with 45 additions and 15 deletions

View File

@@ -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,25 +273,33 @@ bool TerminalStrip::addTerminal(Element *terminal)
*/
bool TerminalStrip::removeTerminal(Element *terminal)
{
if (auto real_terminal = realTerminal(terminal))
if (m_terminal_elements_vector.contains(terminal))
{
if (auto physical_terminal = physicalTerminal(real_terminal))
m_terminal_elements_vector.removeOne(terminal);
//Get the real and physical terminal associated to @terminal
if (auto real_terminal = realTerminal(terminal))
{
if (physical_terminal->levelCount() == 1) {
m_physical_terminals.removeOne(physical_terminal);
} else {
auto v = physical_terminal->terminals();
v.removeOne(real_terminal);
physical_terminal->setTerminals(v);
if (auto physical_terminal = physicalTerminal(real_terminal))
{
if (physical_terminal->levelCount() == 1) {
m_physical_terminals.removeOne(physical_terminal);
} else {
auto v = physical_terminal->terminals();
v.removeOne(real_terminal);
physical_terminal->setTerminals(v);
}
}
m_real_terminals.removeOne(real_terminal);
static_cast<TerminalElement *>(terminal)->setParentTerminalStrip(nullptr);
return true;
}
m_real_terminals.removeOne(real_terminal);
static_cast<TerminalElement *>(terminal)->setParentTerminalStrip(nullptr);
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