mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Ungroup terminal is now managed by undo stack
This commit is contained in:
parent
c6e3e385ff
commit
7c6fca2aac
@ -46,3 +46,50 @@ void GroupTerminalsCommand::redo() {
|
||||
m_terminal_strip->groupTerminals(m_receiver, m_to_group);
|
||||
}
|
||||
}
|
||||
|
||||
UnGroupTerminalsCommand::UnGroupTerminalsCommand(TerminalStrip *strip,
|
||||
const QVector<RealTerminalData> &to_ungroup,
|
||||
QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_terminal_strip(strip)
|
||||
{
|
||||
setUp(to_ungroup);
|
||||
setText("Dégrouper un ensemble de bornes");
|
||||
}
|
||||
|
||||
void UnGroupTerminalsCommand::undo()
|
||||
{
|
||||
if (m_terminal_strip)
|
||||
{
|
||||
for (const auto &key : m_physical_real_H.keys()) {
|
||||
m_terminal_strip->groupTerminals(key, m_physical_real_H.value(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnGroupTerminalsCommand::redo()
|
||||
{
|
||||
if (m_terminal_strip)
|
||||
{
|
||||
for (const auto &value : qAsConst(m_physical_real_H)) {
|
||||
m_terminal_strip->unGroupTerminals(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnGroupTerminalsCommand::setUp(const QVector<RealTerminalData> &to_ungroup)
|
||||
{
|
||||
for (auto rtd_ : to_ungroup)
|
||||
{
|
||||
auto ptd_ = m_terminal_strip->physicalTerminalData(rtd_);
|
||||
|
||||
//Physical have only one real terminal, no need to ungroup it
|
||||
if (ptd_.real_terminals_vector.size() <= 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto vector_ = m_physical_real_H.value(ptd_);
|
||||
vector_.append(rtd_);
|
||||
m_physical_real_H.insert(ptd_, vector_);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,28 @@ class GroupTerminalsCommand : public QUndoCommand
|
||||
QPointer<TerminalStrip> m_terminal_strip;
|
||||
PhysicalTerminalData m_receiver;
|
||||
QVector <RealTerminalData> m_to_group;
|
||||
QVector <RealTerminalData> m_to_ungroup;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The UnGroupTerminalsCommand class
|
||||
* This class is used to ungroup terminal (remove level of multi level terminal)
|
||||
*/
|
||||
class UnGroupTerminalsCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
UnGroupTerminalsCommand(TerminalStrip *strip,
|
||||
const QVector<RealTerminalData> &to_ungroup,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
void setUp(const QVector<RealTerminalData> &to_ungroup);
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_terminal_strip;
|
||||
QHash <PhysicalTerminalData, QVector<RealTerminalData>> m_physical_real_H;
|
||||
};
|
||||
|
||||
#endif // GROUPTERMINALSCOMMAND_H
|
||||
|
@ -478,15 +478,6 @@ bool TerminalStrip::removeTerminal(Element *terminal)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::haveTerminal
|
||||
* @param terminal
|
||||
* @return true if \p terminal belong to this strip
|
||||
*/
|
||||
bool TerminalStrip::haveTerminal(Element *terminal) {
|
||||
return m_terminal_elements_vector.contains(terminal);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::physicalTerminalCount
|
||||
* @return the number of physical terminal.
|
||||
|
@ -61,6 +61,15 @@ struct PhysicalTerminalData
|
||||
QUuid uuid_;
|
||||
};
|
||||
|
||||
//Code to use PhysicalTerminalData as key for QHash
|
||||
inline bool operator == (const PhysicalTerminalData &phy_1, const PhysicalTerminalData &phy_2) {
|
||||
return phy_1.uuid_ == phy_2.uuid_;
|
||||
}
|
||||
|
||||
inline uint qHash(const PhysicalTerminalData &key, uint seed) {
|
||||
return qHash(key.uuid_, seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The TerminalStrip class
|
||||
* This class hold all the datas and configurations
|
||||
@ -103,7 +112,6 @@ class TerminalStrip : public QObject
|
||||
|
||||
bool addTerminal (Element *terminal);
|
||||
bool removeTerminal (Element *terminal);
|
||||
bool haveTerminal (Element *terminal);
|
||||
|
||||
int physicalTerminalCount() const;
|
||||
PhysicalTerminalData physicalTerminalData(int index) const;
|
||||
|
@ -556,7 +556,7 @@ void TerminalStripEditor::on_m_ungroup_pb_clicked()
|
||||
if (m_model && m_current_strip)
|
||||
{
|
||||
const auto rtd_vector = m_model->realTerminalDataForIndex(ui->m_table_widget->selectionModel()->selectedIndexes());
|
||||
m_current_strip->unGroupTerminals(rtd_vector);
|
||||
m_project->undoStack()->push(new UnGroupTerminalsCommand(m_current_strip, rtd_vector));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user