mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Revamp code
Change the way to know who is the physical terminal of a real terminal when we got only the real terminal.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "groupterminalscommand.h"
|
#include "groupterminalscommand.h"
|
||||||
#include "../physicalterminal.h"
|
#include "../physicalterminal.h"
|
||||||
|
#include "../realterminal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GroupTerminalsCommand::GroupTerminalsCommand
|
* @brief GroupTerminalsCommand::GroupTerminalsCommand
|
||||||
@@ -87,8 +88,7 @@ void UnGroupTerminalsCommand::setUp(const QVector<QSharedPointer<RealTerminal>>
|
|||||||
{
|
{
|
||||||
for (const auto &rt_ : to_ungroup)
|
for (const auto &rt_ : to_ungroup)
|
||||||
{
|
{
|
||||||
auto phy_t = m_terminal_strip->physicalTerminal(rt_);
|
if (auto phy_t = rt_->physicalTerminal())
|
||||||
if (phy_t)
|
|
||||||
{
|
{
|
||||||
//Physical have only one real terminal, no need to ungroup it
|
//Physical have only one real terminal, no need to ungroup it
|
||||||
if (phy_t->realTerminalCount() <= 1) {
|
if (phy_t->realTerminalCount() <= 1) {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ void RealTerminal::setPhysicalTerminal(const QSharedPointer<PhysicalTerminal> &p
|
|||||||
* @brief parentStrip
|
* @brief parentStrip
|
||||||
* @return parent terminal strip or nullptr
|
* @return parent terminal strip or nullptr
|
||||||
*/
|
*/
|
||||||
TerminalStrip *RealTerminal::parentStrip() const {
|
TerminalStrip *RealTerminal::parentStrip() const noexcept {
|
||||||
if (m_physical_terminal) {
|
if (m_physical_terminal) {
|
||||||
return m_physical_terminal->terminalStrip();
|
return m_physical_terminal->terminalStrip();
|
||||||
} else {
|
} else {
|
||||||
@@ -110,7 +110,7 @@ TerminalStrip *RealTerminal::parentStrip() const {
|
|||||||
* @return The parent physical terminal of this terminal.
|
* @return The parent physical terminal of this terminal.
|
||||||
* The returned QSharedPointer can be null
|
* The returned QSharedPointer can be null
|
||||||
*/
|
*/
|
||||||
QSharedPointer<PhysicalTerminal> RealTerminal::physicalTerminal() const {
|
QSharedPointer<PhysicalTerminal> RealTerminal::physicalTerminal() const noexcept{
|
||||||
return m_physical_terminal;
|
return m_physical_terminal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ class RealTerminal
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
~RealTerminal();
|
~RealTerminal();
|
||||||
TerminalStrip *parentStrip() const;
|
TerminalStrip *parentStrip() const noexcept;
|
||||||
QSharedPointer<PhysicalTerminal> physicalTerminal() const;
|
QSharedPointer<PhysicalTerminal> physicalTerminal() const noexcept;
|
||||||
|
|
||||||
QDomElement toXml(QDomDocument &parent_document) const;
|
QDomElement toXml(QDomDocument &parent_document) const;
|
||||||
|
|
||||||
|
|||||||
@@ -277,27 +277,6 @@ QSharedPointer<PhysicalTerminal> TerminalStrip::physicalTerminal(int index) cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TerminalStrip::physicalTerminalData
|
|
||||||
* @param real_terminal
|
|
||||||
* @return the parent PhysicalTerminal of \p real_terminal.
|
|
||||||
* the PhysicalTerminal can be null if \p real_terminal don't belong to this strip
|
|
||||||
*/
|
|
||||||
QSharedPointer<PhysicalTerminal> TerminalStrip::physicalTerminal (const QSharedPointer<RealTerminal> &real_terminal) const
|
|
||||||
{
|
|
||||||
if (real_terminal.isNull()) {
|
|
||||||
return QSharedPointer<PhysicalTerminal>();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &physical : qAsConst(m_physical_terminals)) {
|
|
||||||
if (physical->realTerminals().contains(real_terminal)) {
|
|
||||||
return physical;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QSharedPointer<PhysicalTerminal>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStrip::physicalTerminal
|
* @brief TerminalStrip::physicalTerminal
|
||||||
* @param uuid
|
* @param uuid
|
||||||
@@ -419,9 +398,9 @@ bool TerminalStrip::groupTerminals(const QSharedPointer<PhysicalTerminal> &recei
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto physical_ = physicalTerminal(added_terminal);
|
if (auto phy_t = added_terminal->physicalTerminal()) {
|
||||||
physical_->removeTerminal(added_terminal);
|
phy_t->removeTerminal(added_terminal);
|
||||||
|
}
|
||||||
receiver_terminal->addTerminal(added_terminal);
|
receiver_terminal->addTerminal(added_terminal);
|
||||||
have_grouped = true;
|
have_grouped = true;
|
||||||
}
|
}
|
||||||
@@ -452,7 +431,7 @@ void TerminalStrip::unGroupTerminals(const QVector<QSharedPointer<RealTerminal>>
|
|||||||
{
|
{
|
||||||
if (real_terminal)
|
if (real_terminal)
|
||||||
{
|
{
|
||||||
if (auto physical_terminal = physicalTerminal(real_terminal)) //Get the physical terminal
|
if (auto physical_terminal = real_terminal->physicalTerminal()) //Get the physical terminal
|
||||||
{
|
{
|
||||||
if (physical_terminal->realTerminals().size() > 1) //Check if physical have more than one real terminal
|
if (physical_terminal->realTerminals().size() > 1) //Check if physical have more than one real terminal
|
||||||
{
|
{
|
||||||
@@ -480,8 +459,7 @@ bool TerminalStrip::setLevel(const QSharedPointer<RealTerminal> &real_terminal,
|
|||||||
{
|
{
|
||||||
if (real_terminal)
|
if (real_terminal)
|
||||||
{
|
{
|
||||||
auto physical_terminal = physicalTerminal(real_terminal);
|
if (auto physical_terminal = real_terminal->physicalTerminal())
|
||||||
if (physical_terminal)
|
|
||||||
{
|
{
|
||||||
if (physical_terminal->realTerminals().size() > 1 &&
|
if (physical_terminal->realTerminals().size() > 1 &&
|
||||||
physical_terminal->setLevelOf(real_terminal, level))
|
physical_terminal->setLevelOf(real_terminal, level))
|
||||||
@@ -520,7 +498,7 @@ bool TerminalStrip::isBridgeable(const QVector<QSharedPointer<RealTerminal>> &re
|
|||||||
const int level_ = first_real_terminal->level();
|
const int level_ = first_real_terminal->level();
|
||||||
|
|
||||||
// Get the physical terminal and pos
|
// Get the physical terminal and pos
|
||||||
auto first_physical_terminal = physicalTerminal(first_real_terminal);
|
auto first_physical_terminal = first_real_terminal->physicalTerminal();
|
||||||
QVector<shared_physical_terminal> physical_vector{first_physical_terminal};
|
QVector<shared_physical_terminal> physical_vector{first_physical_terminal};
|
||||||
QVector<int> pos_vector{m_physical_terminals.indexOf(first_physical_terminal)};
|
QVector<int> pos_vector{m_physical_terminals.indexOf(first_physical_terminal)};
|
||||||
|
|
||||||
@@ -543,7 +521,7 @@ bool TerminalStrip::isBridgeable(const QVector<QSharedPointer<RealTerminal>> &re
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Not to the same physical terminal of a previous checked real terminal
|
// Not to the same physical terminal of a previous checked real terminal
|
||||||
const auto physical_terminal = physicalTerminal(real_terminal);
|
const auto physical_terminal = real_terminal->physicalTerminal();
|
||||||
if (physical_vector.contains(physical_terminal)) {
|
if (physical_vector.contains(physical_terminal)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -691,7 +669,7 @@ bool TerminalStrip::canUnBridge(const QVector<QSharedPointer<RealTerminal> > &re
|
|||||||
if (compar_bridge != isBridged(real_t)) {
|
if (compar_bridge != isBridged(real_t)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
sorted_terminal.insert(m_physical_terminals.indexOf(physicalTerminal(real_t)),
|
sorted_terminal.insert(m_physical_terminals.indexOf(real_t->physicalTerminal()),
|
||||||
real_t);
|
real_t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -785,7 +763,7 @@ QSharedPointer<TerminalStripBridge> TerminalStrip::bridgeFor(const QVector<QShar
|
|||||||
*/
|
*/
|
||||||
QSharedPointer<RealTerminal> TerminalStrip::previousTerminalInLevel(const QSharedPointer<RealTerminal> &real_terminal) const
|
QSharedPointer<RealTerminal> TerminalStrip::previousTerminalInLevel(const QSharedPointer<RealTerminal> &real_terminal) const
|
||||||
{
|
{
|
||||||
const auto phy_t = physicalTerminal(real_terminal);
|
const auto phy_t = real_terminal->physicalTerminal();
|
||||||
if (real_terminal && phy_t)
|
if (real_terminal && phy_t)
|
||||||
{
|
{
|
||||||
const auto level_ = phy_t->levelOf(real_terminal);
|
const auto level_ = phy_t->levelOf(real_terminal);
|
||||||
@@ -810,7 +788,7 @@ QSharedPointer<RealTerminal> TerminalStrip::previousTerminalInLevel(const QShare
|
|||||||
*/
|
*/
|
||||||
QSharedPointer<RealTerminal> TerminalStrip::nextTerminalInLevel(const QSharedPointer<RealTerminal> &real_terminal) const
|
QSharedPointer<RealTerminal> TerminalStrip::nextTerminalInLevel(const QSharedPointer<RealTerminal> &real_terminal) const
|
||||||
{
|
{
|
||||||
const auto phy_t = physicalTerminal(real_terminal);
|
const auto phy_t = real_terminal->physicalTerminal();
|
||||||
if (real_terminal && phy_t)
|
if (real_terminal && phy_t)
|
||||||
{
|
{
|
||||||
const auto level_ = phy_t->levelOf(real_terminal);
|
const auto level_ = phy_t->levelOf(real_terminal);
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ class TerminalStrip : public QObject
|
|||||||
int pos(const QSharedPointer<PhysicalTerminal> &terminal) const;
|
int pos(const QSharedPointer<PhysicalTerminal> &terminal) const;
|
||||||
int physicalTerminalCount() const;
|
int physicalTerminalCount() const;
|
||||||
QSharedPointer<PhysicalTerminal> physicalTerminal(int index) const;
|
QSharedPointer<PhysicalTerminal> physicalTerminal(int index) const;
|
||||||
QSharedPointer<PhysicalTerminal> physicalTerminal(const QSharedPointer<RealTerminal> &real_terminal) const;
|
|
||||||
QSharedPointer<PhysicalTerminal> physicalTerminal(const QUuid &uuid) const;
|
QSharedPointer<PhysicalTerminal> physicalTerminal(const QUuid &uuid) const;
|
||||||
QVector<QSharedPointer<PhysicalTerminal>> physicalTerminal() const;
|
QVector<QSharedPointer<PhysicalTerminal>> physicalTerminal() const;
|
||||||
QSharedPointer<RealTerminal> realTerminalForUuid(const QUuid &uuid) const;
|
QSharedPointer<RealTerminal> realTerminalForUuid(const QUuid &uuid) const;
|
||||||
|
|||||||
@@ -717,7 +717,7 @@ void TerminalStripEditor::on_m_group_terminals_pb_clicked()
|
|||||||
if (mrtd_vector.size() >= 2)
|
if (mrtd_vector.size() >= 2)
|
||||||
{
|
{
|
||||||
//At this step get the first physical terminal as receiver
|
//At this step get the first physical terminal as receiver
|
||||||
auto receiver_ = m_current_strip->physicalTerminal(mrtd_vector.first().real_terminal);
|
auto receiver_ = mrtd_vector.first().real_terminal.toStrongRef()->physicalTerminal();
|
||||||
|
|
||||||
QVector<QSharedPointer<RealTerminal>> vector_;
|
QVector<QSharedPointer<RealTerminal>> vector_;
|
||||||
int count_ = 0;
|
int count_ = 0;
|
||||||
@@ -728,11 +728,11 @@ void TerminalStripEditor::on_m_group_terminals_pb_clicked()
|
|||||||
|
|
||||||
//Get the better physical terminal as receiver
|
//Get the better physical terminal as receiver
|
||||||
//(physical terminal with the max of real terminal)
|
//(physical terminal with the max of real terminal)
|
||||||
const auto current_physical = m_current_strip->physicalTerminal(real_t);
|
const auto current_physical = real_t->physicalTerminal();
|
||||||
int real_t_count = current_physical->realTerminalCount();
|
int real_t_count = current_physical->realTerminalCount();
|
||||||
if (real_t_count > 1 && real_t_count > count_) {
|
if (real_t_count > 1 && real_t_count > count_) {
|
||||||
count_ = real_t_count;
|
count_ = real_t_count;
|
||||||
receiver_ = m_current_strip->physicalTerminal(real_t);
|
receiver_ = real_t->physicalTerminal();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -677,7 +677,7 @@ QPixmap TerminalStripModel::bridgePixmapFor(const QModelIndex &index) const
|
|||||||
//Check if we need to draw a none bridge pixmap
|
//Check if we need to draw a none bridge pixmap
|
||||||
|
|
||||||
//Check previous
|
//Check previous
|
||||||
auto phy_t = m_terminal_strip->physicalTerminal(mrtd.real_terminal);
|
auto phy_t = mrtd.real_terminal.toStrongRef()->physicalTerminal();
|
||||||
auto current_real_terminal = mrtd;
|
auto current_real_terminal = mrtd;
|
||||||
auto current_phy_uuid = phy_t->uuid();
|
auto current_phy_uuid = phy_t->uuid();
|
||||||
bool already_jumped_to_previous = false;
|
bool already_jumped_to_previous = false;
|
||||||
@@ -691,7 +691,7 @@ QPixmap TerminalStripModel::bridgePixmapFor(const QModelIndex &index) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
//We are in the same physical terminal as previous loop
|
//We are in the same physical terminal as previous loop
|
||||||
if (current_phy_uuid == m_terminal_strip->physicalTerminal(current_real_terminal.real_terminal)->uuid())
|
if (current_phy_uuid == current_real_terminal.real_terminal.toStrongRef()->physicalTerminal()->uuid())
|
||||||
{
|
{
|
||||||
if (current_real_terminal.bridged_ &&
|
if (current_real_terminal.bridged_ &&
|
||||||
current_real_terminal.level_ == level_column) {
|
current_real_terminal.level_ == level_column) {
|
||||||
@@ -703,7 +703,7 @@ QPixmap TerminalStripModel::bridgePixmapFor(const QModelIndex &index) const
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
already_jumped_to_previous = true;
|
already_jumped_to_previous = true;
|
||||||
current_phy_uuid = m_terminal_strip->physicalTerminal(current_real_terminal.real_terminal)->uuid();
|
current_phy_uuid = current_real_terminal.real_terminal.toStrongRef()->physicalTerminal()->uuid();
|
||||||
if (current_real_terminal.bridged_ &&
|
if (current_real_terminal.bridged_ &&
|
||||||
current_real_terminal.level_ == level_column) {
|
current_real_terminal.level_ == level_column) {
|
||||||
previous_data = current_real_terminal;
|
previous_data = current_real_terminal;
|
||||||
@@ -726,7 +726,7 @@ QPixmap TerminalStripModel::bridgePixmapFor(const QModelIndex &index) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
//We are in the same physical terminal as previous loop
|
//We are in the same physical terminal as previous loop
|
||||||
if (current_phy_uuid == m_terminal_strip->physicalTerminal(current_real_terminal.real_terminal)->uuid())
|
if (current_phy_uuid == current_real_terminal.real_terminal.toStrongRef()->physicalTerminal()->uuid())
|
||||||
{
|
{
|
||||||
if (current_real_terminal.bridged_ &&
|
if (current_real_terminal.bridged_ &&
|
||||||
current_real_terminal.level_ == level_column) {
|
current_real_terminal.level_ == level_column) {
|
||||||
@@ -738,7 +738,7 @@ QPixmap TerminalStripModel::bridgePixmapFor(const QModelIndex &index) const
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
already_jumped_to_next = true;
|
already_jumped_to_next = true;
|
||||||
current_phy_uuid = m_terminal_strip->physicalTerminal(current_real_terminal.real_terminal)->uuid();
|
current_phy_uuid = current_real_terminal.real_terminal.toStrongRef()->physicalTerminal()->uuid();
|
||||||
if (current_real_terminal.bridged_ &&
|
if (current_real_terminal.bridged_ &&
|
||||||
current_real_terminal.level_ == level_column) {
|
current_real_terminal.level_ == level_column) {
|
||||||
next_data = current_real_terminal;
|
next_data = current_real_terminal;
|
||||||
|
|||||||
Reference in New Issue
Block a user