mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-17 08:19:59 +01:00
Make code less spaghetti
Not finished yet.
This commit is contained in:
@@ -16,14 +16,13 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "bridgeterminalscommand.h"
|
||||
#include "../terminalstrip.h"
|
||||
|
||||
BridgeTerminalsCommand::BridgeTerminalsCommand(TerminalStrip *strip,
|
||||
QVector<QUuid> real_terminal_uuid,
|
||||
QVector<QWeakPointer<RealTerminal>> real_terminal,
|
||||
QUndoCommand *parent):
|
||||
QUndoCommand(parent),
|
||||
m_strip(strip),
|
||||
m_uuid_vector(real_terminal_uuid)
|
||||
m_real_terminal_vector(real_terminal)
|
||||
{
|
||||
setText(QObject::tr("Ponter des bornes entre-elles"));
|
||||
}
|
||||
@@ -31,40 +30,44 @@ BridgeTerminalsCommand::BridgeTerminalsCommand(TerminalStrip *strip,
|
||||
void BridgeTerminalsCommand::undo()
|
||||
{
|
||||
if (m_strip) {
|
||||
m_strip->unBridge(m_uuid_vector);
|
||||
m_strip->unBridge(m_real_terminal_vector);
|
||||
}
|
||||
}
|
||||
|
||||
void BridgeTerminalsCommand::redo()
|
||||
{
|
||||
if (m_strip) {
|
||||
m_strip->setBridge(m_uuid_vector);
|
||||
m_strip->setBridge(m_real_terminal_vector);
|
||||
}
|
||||
}
|
||||
|
||||
UnBridgeTerminalsCommand::UnBridgeTerminalsCommand(TerminalStrip *strip,
|
||||
QVector<QUuid> real_terminal_uuid,
|
||||
QVector<QWeakPointer<RealTerminal>> real_terminal,
|
||||
QUndoCommand *parent):
|
||||
QUndoCommand(parent),
|
||||
m_strip(strip)
|
||||
{
|
||||
setText(QObject::tr("Supprimer des ponts de bornes"));
|
||||
|
||||
for (const auto &t_uuid : real_terminal_uuid)
|
||||
for (const auto &real_t : real_terminal)
|
||||
{
|
||||
auto bridge = m_strip->bridgeFor(t_uuid);
|
||||
if (bridge) {
|
||||
m_bridge_terminal_map.insert(bridge->uuid_, t_uuid);
|
||||
auto bridge_ = strip->bridgeFor(real_t);
|
||||
if (bridge_) {
|
||||
m_bridge_terminal_hash.insert(bridge_.toWeakRef(), real_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnBridgeTerminalsCommand::undo()
|
||||
{
|
||||
if (m_strip) {
|
||||
for (const auto &bridge_uuid : m_bridge_terminal_map.uniqueKeys()) {
|
||||
auto terminal_list = m_bridge_terminal_map.values(bridge_uuid);
|
||||
m_strip->setBridge(bridge_uuid, terminal_list.toVector());
|
||||
if (m_strip)
|
||||
{
|
||||
for (const auto &bridge_ : m_bridge_terminal_hash.uniqueKeys())
|
||||
{
|
||||
if (!bridge_.isNull()) {
|
||||
auto terminal_list = m_bridge_terminal_hash.values(bridge_);
|
||||
m_strip->setBridge(bridge_.toStrongRef() , terminal_list.toVector());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +75,6 @@ void UnBridgeTerminalsCommand::undo()
|
||||
void UnBridgeTerminalsCommand::redo()
|
||||
{
|
||||
if (m_strip) {
|
||||
m_strip->unBridge(m_bridge_terminal_map.values().toVector());
|
||||
m_strip->unBridge(m_bridge_terminal_hash.values().toVector());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,10 @@
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include <QVector>
|
||||
#include <QUuid>
|
||||
#include <QPointer>
|
||||
#include <QMultiMap>
|
||||
|
||||
class TerminalStrip;
|
||||
#include "../terminalstrip.h"
|
||||
|
||||
/**
|
||||
* @brief The BridgeTerminalsCommand class
|
||||
@@ -34,7 +33,7 @@ class TerminalStrip;
|
||||
class BridgeTerminalsCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
BridgeTerminalsCommand(TerminalStrip *strip, QVector<QUuid> real_terminal_uuid, QUndoCommand *parent = nullptr);
|
||||
BridgeTerminalsCommand(TerminalStrip *strip, QVector<QWeakPointer<RealTerminal>> real_terminal, QUndoCommand *parent = nullptr);
|
||||
~BridgeTerminalsCommand() override {}
|
||||
|
||||
void undo() override;
|
||||
@@ -42,7 +41,7 @@ class BridgeTerminalsCommand : public QUndoCommand
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_strip;
|
||||
QVector<QUuid> m_uuid_vector;
|
||||
QVector<QWeakPointer<RealTerminal>> m_real_terminal_vector;
|
||||
};
|
||||
|
||||
|
||||
@@ -54,7 +53,7 @@ class BridgeTerminalsCommand : public QUndoCommand
|
||||
class UnBridgeTerminalsCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
UnBridgeTerminalsCommand(TerminalStrip *strip, QVector<QUuid> real_terminal_uuid, QUndoCommand *parent = nullptr);
|
||||
UnBridgeTerminalsCommand(TerminalStrip *strip, QVector<QWeakPointer<RealTerminal>> real_terminal, QUndoCommand *parent = nullptr);
|
||||
~UnBridgeTerminalsCommand() override{}
|
||||
|
||||
void undo() override;
|
||||
@@ -62,7 +61,7 @@ class UnBridgeTerminalsCommand : public QUndoCommand
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_strip;
|
||||
QMultiMap<QUuid, QUuid> m_bridge_terminal_map; ///Key is bridge uuid, value is real terminal uuid
|
||||
QMultiHash<QWeakPointer<TerminalStripBridge>, QWeakPointer<RealTerminal>> m_bridge_terminal_hash; ///Key a is bridge, value is real terminal
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -18,14 +18,14 @@
|
||||
#include "changeterminallevel.h"
|
||||
|
||||
ChangeTerminalLevel::ChangeTerminalLevel(TerminalStrip *strip,
|
||||
const RealTerminalData &real_terminal,
|
||||
const QWeakPointer<RealTerminal> &real_terminal,
|
||||
int level,
|
||||
QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_strip(strip),
|
||||
m_real_terminal(real_terminal),
|
||||
m_new_level(level),
|
||||
m_old_level(real_terminal.level_)
|
||||
m_old_level(m_strip->realTerminalDataFor(real_terminal).level())
|
||||
{}
|
||||
|
||||
void ChangeTerminalLevel::undo()
|
||||
|
||||
@@ -26,7 +26,7 @@ class ChangeTerminalLevel : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
ChangeTerminalLevel(TerminalStrip *strip,
|
||||
const RealTerminalData &real_terminal,
|
||||
const QWeakPointer<RealTerminal> &real_terminal,
|
||||
int level,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
@@ -35,7 +35,7 @@ class ChangeTerminalLevel : public QUndoCommand
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_strip;
|
||||
RealTerminalData m_real_terminal;
|
||||
QWeakPointer<RealTerminal> m_real_terminal;
|
||||
int m_new_level, m_old_level;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
GroupTerminalsCommand::GroupTerminalsCommand(TerminalStrip *strip,
|
||||
const PhysicalTerminalData &receiver_,
|
||||
const QVector<RealTerminalData> &to_group,
|
||||
const QVector<QWeakPointer<RealTerminal>> &to_group,
|
||||
QUndoCommand *parent):
|
||||
QUndoCommand(parent),
|
||||
m_terminal_strip(strip),
|
||||
@@ -48,7 +48,7 @@ void GroupTerminalsCommand::redo() {
|
||||
}
|
||||
|
||||
UnGroupTerminalsCommand::UnGroupTerminalsCommand(TerminalStrip *strip,
|
||||
const QVector<RealTerminalData> &to_ungroup,
|
||||
const QVector<QWeakPointer<RealTerminal>> &to_ungroup,
|
||||
QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_terminal_strip(strip)
|
||||
@@ -77,11 +77,11 @@ void UnGroupTerminalsCommand::redo()
|
||||
}
|
||||
}
|
||||
|
||||
void UnGroupTerminalsCommand::setUp(const QVector<RealTerminalData> &to_ungroup)
|
||||
void UnGroupTerminalsCommand::setUp(const QVector<QWeakPointer<RealTerminal>> &to_ungroup)
|
||||
{
|
||||
for (auto rtd_ : to_ungroup)
|
||||
for (const auto &rt_ : to_ungroup)
|
||||
{
|
||||
auto ptd_ = m_terminal_strip->physicalTerminalData(rtd_);
|
||||
auto ptd_ = m_terminal_strip->physicalTerminalData(rt_);
|
||||
|
||||
//Physical have only one real terminal, no need to ungroup it
|
||||
if (ptd_.real_terminals_vector.size() <= 1) {
|
||||
@@ -89,7 +89,7 @@ void UnGroupTerminalsCommand::setUp(const QVector<RealTerminalData> &to_ungroup)
|
||||
}
|
||||
|
||||
auto vector_ = m_physical_real_H.value(ptd_);
|
||||
vector_.append(rtd_);
|
||||
vector_.append(rt_);
|
||||
m_physical_real_H.insert(ptd_, vector_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class GroupTerminalsCommand : public QUndoCommand
|
||||
public:
|
||||
GroupTerminalsCommand(TerminalStrip *strip,
|
||||
const PhysicalTerminalData &receiver_,
|
||||
const QVector<RealTerminalData> &to_group,
|
||||
const QVector<QWeakPointer<RealTerminal>> &to_group,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
@@ -41,7 +41,7 @@ class GroupTerminalsCommand : public QUndoCommand
|
||||
private:
|
||||
QPointer<TerminalStrip> m_terminal_strip;
|
||||
PhysicalTerminalData m_receiver;
|
||||
QVector <RealTerminalData> m_to_group;
|
||||
QVector<QWeakPointer<RealTerminal>> m_to_group;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -52,18 +52,18 @@ class UnGroupTerminalsCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
UnGroupTerminalsCommand(TerminalStrip *strip,
|
||||
const QVector<RealTerminalData> &to_ungroup,
|
||||
const QVector<QWeakPointer<RealTerminal>> &to_ungroup,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
void setUp(const QVector<RealTerminalData> &to_ungroup);
|
||||
void setUp(const QVector<QWeakPointer<RealTerminal>> &to_ungroup);
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_terminal_strip;
|
||||
QHash <PhysicalTerminalData, QVector<RealTerminalData>> m_physical_real_H;
|
||||
QHash <PhysicalTerminalData, QVector<QWeakPointer<RealTerminal>>> m_physical_real_H;
|
||||
};
|
||||
|
||||
#endif // GROUPTERMINALSCOMMAND_H
|
||||
|
||||
@@ -54,7 +54,7 @@ void SortTerminalStripCommand::sort()
|
||||
|
||||
if (arg1.real_terminals_vector.count())
|
||||
{
|
||||
str1 = arg1.real_terminals_vector.constLast().label_;
|
||||
str1 = arg1.real_terminals_vector.constLast().label();
|
||||
|
||||
auto match = rx.match(str1);
|
||||
if (match.hasMatch()) {
|
||||
@@ -64,7 +64,7 @@ void SortTerminalStripCommand::sort()
|
||||
|
||||
if (arg2.real_terminals_vector.count())
|
||||
{
|
||||
str2 = arg2.real_terminals_vector.constLast().label_;
|
||||
str2 = arg2.real_terminals_vector.constLast().label();
|
||||
|
||||
auto match = rx.match(str2);
|
||||
if (match.hasMatch()) {
|
||||
|
||||
Reference in New Issue
Block a user