mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Change relationship betwen classes RealTerminal PhysicalTerminald and TerminalElement
This commit is contained in:
@@ -30,7 +30,13 @@ PhysicalTerminal::PhysicalTerminal(TerminalStrip *parent_strip,
|
|||||||
QVector<QSharedPointer<RealTerminal>> terminals) :
|
QVector<QSharedPointer<RealTerminal>> terminals) :
|
||||||
m_parent_terminal_strip(parent_strip),
|
m_parent_terminal_strip(parent_strip),
|
||||||
m_real_terminal(terminals)
|
m_real_terminal(terminals)
|
||||||
{}
|
{
|
||||||
|
for (const auto &real_t : m_real_terminal) {
|
||||||
|
if (real_t) {
|
||||||
|
real_t->setPhysicalTerminal(sharedRef());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PhysicalTerminal::sharedRef
|
* @brief PhysicalTerminal::sharedRef
|
||||||
@@ -80,6 +86,11 @@ QDomElement PhysicalTerminal::toXml(QDomDocument &parent_document) const
|
|||||||
*/
|
*/
|
||||||
void PhysicalTerminal::setTerminals(const QVector<QSharedPointer<RealTerminal>> &terminals) {
|
void PhysicalTerminal::setTerminals(const QVector<QSharedPointer<RealTerminal>> &terminals) {
|
||||||
m_real_terminal = terminals;
|
m_real_terminal = terminals;
|
||||||
|
for (const auto &real_t : m_real_terminal) {
|
||||||
|
if (real_t) {
|
||||||
|
real_t->setPhysicalTerminal(sharedRef());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +101,7 @@ void PhysicalTerminal::setTerminals(const QVector<QSharedPointer<RealTerminal>>
|
|||||||
*/
|
*/
|
||||||
void PhysicalTerminal::addTerminal(const QSharedPointer<RealTerminal> &terminal) {
|
void PhysicalTerminal::addTerminal(const QSharedPointer<RealTerminal> &terminal) {
|
||||||
m_real_terminal.append(terminal);
|
m_real_terminal.append(terminal);
|
||||||
|
terminal->setPhysicalTerminal(sharedRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,8 +110,13 @@ void PhysicalTerminal::addTerminal(const QSharedPointer<RealTerminal> &terminal)
|
|||||||
* @param terminal
|
* @param terminal
|
||||||
* @return true if sucessfully removed
|
* @return true if sucessfully removed
|
||||||
*/
|
*/
|
||||||
bool PhysicalTerminal::removeTerminal(const QSharedPointer<RealTerminal> &terminal) {
|
bool PhysicalTerminal::removeTerminal(const QSharedPointer<RealTerminal> &terminal)
|
||||||
return m_real_terminal.removeOne(terminal);
|
{
|
||||||
|
if (m_real_terminal.removeOne(terminal)) {
|
||||||
|
terminal->setPhysicalTerminal(QSharedPointer<PhysicalTerminal>());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,6 +141,23 @@ bool PhysicalTerminal::setLevelOf(const QSharedPointer<RealTerminal> &terminal,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PhysicalTerminal::~PhysicalTerminal()
|
||||||
|
{
|
||||||
|
for (const auto &real_t : m_real_terminal) {
|
||||||
|
if (real_t) {
|
||||||
|
real_t->setPhysicalTerminal(QSharedPointer<PhysicalTerminal>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief PhysicalTerminal::terminalStrip
|
||||||
|
* @return The parent terminal strip ornullptr
|
||||||
|
*/
|
||||||
|
TerminalStrip *PhysicalTerminal::terminalStrip() const {
|
||||||
|
return m_parent_terminal_strip.data();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief levelCount
|
* @brief levelCount
|
||||||
* @return the number of level of this terminal
|
* @return the number of level of this terminal
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class TerminalStrip;
|
|||||||
class PhysicalTerminal
|
class PhysicalTerminal
|
||||||
{
|
{
|
||||||
friend class TerminalStrip;
|
friend class TerminalStrip;
|
||||||
|
friend class RealTerminal;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PhysicalTerminal(TerminalStrip *parent_strip, QVector<QSharedPointer<RealTerminal>> terminals);
|
PhysicalTerminal(TerminalStrip *parent_strip, QVector<QSharedPointer<RealTerminal>> terminals);
|
||||||
@@ -77,7 +78,9 @@ class PhysicalTerminal
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
PhysicalTerminal(){}
|
PhysicalTerminal(){}
|
||||||
|
~PhysicalTerminal();
|
||||||
|
|
||||||
|
TerminalStrip* terminalStrip() const;
|
||||||
int levelCount() const;
|
int levelCount() const;
|
||||||
int levelOf(const QSharedPointer<RealTerminal> &terminal) const;
|
int levelOf(const QSharedPointer<RealTerminal> &terminal) const;
|
||||||
QVector<QSharedPointer<RealTerminal>> realTerminals() const;
|
QVector<QSharedPointer<RealTerminal>> realTerminals() const;
|
||||||
|
|||||||
@@ -25,11 +25,23 @@
|
|||||||
* @param parent_strip : parent terminal strip
|
* @param parent_strip : parent terminal strip
|
||||||
* @param terminal : terminal element (if any) in a folio
|
* @param terminal : terminal element (if any) in a folio
|
||||||
*/
|
*/
|
||||||
RealTerminal::RealTerminal(TerminalStrip *parent_strip,
|
RealTerminal::RealTerminal(Element *terminal) :
|
||||||
Element *terminal) :
|
m_element(terminal)
|
||||||
m_element(terminal),
|
{
|
||||||
m_parent_terminal_strip(parent_strip)
|
if (terminal) {
|
||||||
{}
|
static_cast<TerminalElement *>(terminal)->setRealTerminal(sharedRef());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RealTerminal::~RealTerminal()
|
||||||
|
{
|
||||||
|
if (m_physical_terminal) {
|
||||||
|
m_physical_terminal->removeTerminal(sharedRef());
|
||||||
|
}
|
||||||
|
if (m_element) {
|
||||||
|
static_cast<TerminalElement *>(m_element.data())->setRealTerminal(QSharedPointer<RealTerminal>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief RealTerminal::sharedRef
|
* @brief RealTerminal::sharedRef
|
||||||
@@ -47,6 +59,16 @@ QSharedPointer<RealTerminal> RealTerminal::sharedRef()
|
|||||||
return this_shared;
|
return this_shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RealTerminal::sharedRef
|
||||||
|
* @return a shared reference of this, not that because
|
||||||
|
* this method is const, the shared reference can be null if not already
|
||||||
|
* used in another part of the code.
|
||||||
|
*/
|
||||||
|
QSharedPointer<RealTerminal> RealTerminal::sharedRef() const {
|
||||||
|
return QSharedPointer<RealTerminal>(m_this_weak);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief RealTerminal::weakRef
|
* @brief RealTerminal::weakRef
|
||||||
* @return a QWeakPointer of this, weak pointer can be bull
|
* @return a QWeakPointer of this, weak pointer can be bull
|
||||||
@@ -76,6 +98,7 @@ bool RealTerminal::fromXml(QDomElement xml_element, const QVector<TerminalElemen
|
|||||||
if (terminal->uuid() == uuid_)
|
if (terminal->uuid() == uuid_)
|
||||||
{
|
{
|
||||||
m_element = terminal;
|
m_element = terminal;
|
||||||
|
static_cast<TerminalElement *>(terminal)->setRealTerminal(sharedRef());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,11 +123,24 @@ QDomElement RealTerminal::toXml(QDomDocument &parent_document) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief parentStrip
|
* @brief RealTerminal::setPhysicalTerminal
|
||||||
* @return parent terminal strip
|
* Set the parent physical terminal of this real terminal
|
||||||
*/
|
* @param phy_t
|
||||||
|
*/
|
||||||
|
void RealTerminal::setPhysicalTerminal(const QSharedPointer<PhysicalTerminal> &phy_t) {
|
||||||
|
m_physical_terminal = phy_t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief parentStrip
|
||||||
|
* @return parent terminal strip or nullptr
|
||||||
|
*/
|
||||||
TerminalStrip *RealTerminal::parentStrip() const {
|
TerminalStrip *RealTerminal::parentStrip() const {
|
||||||
return m_parent_terminal_strip.data();
|
if (m_physical_terminal) {
|
||||||
|
return m_physical_terminal->terminalStrip();
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,11 +149,9 @@ TerminalStrip *RealTerminal::parentStrip() const {
|
|||||||
*/
|
*/
|
||||||
int RealTerminal::level() const
|
int RealTerminal::level() const
|
||||||
{
|
{
|
||||||
if (m_parent_terminal_strip) {
|
if (m_physical_terminal &&
|
||||||
const auto phy_t = m_parent_terminal_strip->physicalTerminal(m_this_weak);
|
sharedRef()) {
|
||||||
if (phy_t) {
|
return m_physical_terminal->levelOf(sharedRef());
|
||||||
return phy_t->levelOf(m_this_weak);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@@ -224,8 +258,8 @@ bool RealTerminal::isElement() const {
|
|||||||
*/
|
*/
|
||||||
bool RealTerminal::isBridged() const
|
bool RealTerminal::isBridged() const
|
||||||
{
|
{
|
||||||
if (m_parent_terminal_strip) {
|
if (parentStrip()) {
|
||||||
return !m_parent_terminal_strip->isBridged(m_this_weak.toStrongRef()).isNull();
|
return !parentStrip()->isBridged(m_this_weak.toStrongRef()).isNull();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -237,8 +271,8 @@ bool RealTerminal::isBridged() const
|
|||||||
*/
|
*/
|
||||||
QSharedPointer<TerminalStripBridge> RealTerminal::bridge() const
|
QSharedPointer<TerminalStripBridge> RealTerminal::bridge() const
|
||||||
{
|
{
|
||||||
if (m_parent_terminal_strip) {
|
if (parentStrip()) {
|
||||||
return m_parent_terminal_strip->isBridged(m_this_weak.toStrongRef());
|
return parentStrip()->isBridged(m_this_weak.toStrongRef());
|
||||||
} else {
|
} else {
|
||||||
return QSharedPointer<TerminalStripBridge>();
|
return QSharedPointer<TerminalStripBridge>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,14 +45,19 @@ class RealTerminal
|
|||||||
friend class PhysicalTerminal;
|
friend class PhysicalTerminal;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RealTerminal(TerminalStrip *strip, Element *element = nullptr);
|
RealTerminal(Element *element = nullptr);
|
||||||
|
|
||||||
QSharedPointer<RealTerminal> sharedRef();
|
QSharedPointer<RealTerminal> sharedRef();
|
||||||
|
QSharedPointer<RealTerminal> sharedRef() const;
|
||||||
QWeakPointer<RealTerminal> weakRef();
|
QWeakPointer<RealTerminal> weakRef();
|
||||||
|
|
||||||
bool fromXml(QDomElement xml_element, const QVector<TerminalElement *> &terminal_vector);
|
bool fromXml(QDomElement xml_element, const QVector<TerminalElement *> &terminal_vector);
|
||||||
QDomElement toXml(QDomDocument &parent_document) const;
|
QDomElement toXml(QDomDocument &parent_document) const;
|
||||||
|
|
||||||
|
void setPhysicalTerminal(const QSharedPointer<PhysicalTerminal> &phy_t);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
~RealTerminal();
|
||||||
TerminalStrip *parentStrip() const;
|
TerminalStrip *parentStrip() const;
|
||||||
int level() const;
|
int level() const;
|
||||||
QString label() const;
|
QString label() const;
|
||||||
@@ -78,9 +83,9 @@ class RealTerminal
|
|||||||
|
|
||||||
private :
|
private :
|
||||||
QPointer<Element> m_element;
|
QPointer<Element> m_element;
|
||||||
QPointer<TerminalStrip> m_parent_terminal_strip;
|
|
||||||
QUuid m_uuid = QUuid::createUuid();
|
QUuid m_uuid = QUuid::createUuid();
|
||||||
QWeakPointer<RealTerminal> m_this_weak;
|
QWeakPointer<RealTerminal> m_this_weak;
|
||||||
|
QSharedPointer<PhysicalTerminal> m_physical_terminal;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REALTERMINAL_H
|
#endif // REALTERMINAL_H
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ bool TerminalStrip::addTerminal(Element *terminal)
|
|||||||
m_terminal_elements_vector.append(terminal);
|
m_terminal_elements_vector.append(terminal);
|
||||||
|
|
||||||
//Create the real terminal
|
//Create the real terminal
|
||||||
auto raw_real_ptr = new RealTerminal(this, terminal);
|
auto raw_real_ptr = new RealTerminal(terminal);
|
||||||
auto real_terminal = raw_real_ptr->sharedRef();
|
auto real_terminal = raw_real_ptr->sharedRef();
|
||||||
m_real_terminals.append(real_terminal);
|
m_real_terminals.append(real_terminal);
|
||||||
|
|
||||||
@@ -122,8 +122,6 @@ bool TerminalStrip::addTerminal(Element *terminal)
|
|||||||
auto raw_phy_ptr = new PhysicalTerminal(this, QVector<QSharedPointer<RealTerminal>>{real_terminal});
|
auto raw_phy_ptr = new PhysicalTerminal(this, QVector<QSharedPointer<RealTerminal>>{real_terminal});
|
||||||
m_physical_terminals.append(raw_phy_ptr->sharedRef());
|
m_physical_terminals.append(raw_phy_ptr->sharedRef());
|
||||||
|
|
||||||
static_cast<TerminalElement *>(terminal)->setParentTerminalStrip(this);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +151,6 @@ bool TerminalStrip::removeTerminal(Element *terminal)
|
|||||||
}
|
}
|
||||||
m_real_terminals.removeOne(real_terminal);
|
m_real_terminals.removeOne(real_terminal);
|
||||||
|
|
||||||
static_cast<TerminalElement *>(terminal)->setParentTerminalStrip(nullptr);
|
|
||||||
|
|
||||||
rebuildRealVector();
|
rebuildRealVector();
|
||||||
return true;
|
return true;
|
||||||
@@ -824,13 +821,12 @@ bool TerminalStrip::fromXml(QDomElement &xml_element)
|
|||||||
//Read each real terminal of the current physical terminal of the loop
|
//Read each real terminal of the current physical terminal of the loop
|
||||||
for (auto &xml_real : QETXML::findInDomElement(xml_physical, RealTerminal::xmlTagName()))
|
for (auto &xml_real : QETXML::findInDomElement(xml_physical, RealTerminal::xmlTagName()))
|
||||||
{
|
{
|
||||||
auto raw_ptr = new RealTerminal(this);
|
auto raw_ptr = new RealTerminal();
|
||||||
auto real_t = raw_ptr->sharedRef();
|
auto real_t = raw_ptr->sharedRef();
|
||||||
real_t->fromXml(xml_real, free_terminals);
|
real_t->fromXml(xml_real, free_terminals);
|
||||||
if(real_t->isElement())
|
if(real_t->isElement())
|
||||||
{
|
{
|
||||||
m_terminal_elements_vector.append(real_t->element());
|
m_terminal_elements_vector.append(real_t->element());
|
||||||
static_cast<TerminalElement*>(real_t->element())->setParentTerminalStrip(this);
|
|
||||||
}
|
}
|
||||||
real_t_vector.append(real_t);
|
real_t_vector.append(real_t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "terminalelement.h"
|
#include "terminalelement.h"
|
||||||
|
#include"../TerminalStrip/realterminal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief TerminalElement::TerminalElement
|
@brief TerminalElement::TerminalElement
|
||||||
@@ -41,17 +42,20 @@ void TerminalElement::initLink(QETProject *project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalElement::setParentTerminalStrip
|
* @brief TerminalElement::setRealTerminal
|
||||||
* Set \p strip as parent terminal strip.
|
* Set @a real_t as the real terminal for this terminal element
|
||||||
* Be carefull, this function only set internally the parent terminal strip.
|
* @param real_t
|
||||||
* This function don't check if there is a previous
|
|
||||||
* parent terminal strip and don't check
|
|
||||||
* if the new terminal strip have this terminal element
|
|
||||||
* in her list of terminal element.
|
|
||||||
* @param strip
|
|
||||||
*/
|
*/
|
||||||
void TerminalElement::setParentTerminalStrip(TerminalStrip *strip) {
|
void TerminalElement::setRealTerminal(const QSharedPointer<RealTerminal> &real_t) {
|
||||||
m_parent_terminal_strip = strip;
|
m_real_terminal = real_t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalElement::realTerminal
|
||||||
|
* @return the real terminal of this terminal element.
|
||||||
|
*/
|
||||||
|
QSharedPointer<RealTerminal> TerminalElement::realTerminal() const {
|
||||||
|
return m_real_terminal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,6 +64,9 @@ void TerminalElement::setParentTerminalStrip(TerminalStrip *strip) {
|
|||||||
* terminal element or nullptr if not.
|
* terminal element or nullptr if not.
|
||||||
*/
|
*/
|
||||||
TerminalStrip *TerminalElement::parentTerminalStrip() const {
|
TerminalStrip *TerminalElement::parentTerminalStrip() const {
|
||||||
return m_parent_terminal_strip.data();
|
if (m_real_terminal) {
|
||||||
|
return m_real_terminal->parentStrip();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "../TerminalStrip/terminalstrip.h"
|
#include "../TerminalStrip/terminalstrip.h"
|
||||||
|
|
||||||
class QETProject;
|
class QETProject;
|
||||||
|
class RealTerminal;
|
||||||
/**
|
/**
|
||||||
@brief The TerminalElement class
|
@brief The TerminalElement class
|
||||||
*/
|
*/
|
||||||
@@ -35,11 +36,13 @@ class TerminalElement : public Element
|
|||||||
~TerminalElement() override;
|
~TerminalElement() override;
|
||||||
void initLink(QETProject *project) override;
|
void initLink(QETProject *project) override;
|
||||||
|
|
||||||
|
void setRealTerminal(const QSharedPointer<RealTerminal> &real_t);
|
||||||
|
QSharedPointer<RealTerminal> realTerminal() const;
|
||||||
void setParentTerminalStrip(TerminalStrip *strip);
|
void setParentTerminalStrip(TerminalStrip *strip);
|
||||||
TerminalStrip *parentTerminalStrip() const;
|
TerminalStrip *parentTerminalStrip() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<TerminalStrip> m_parent_terminal_strip;
|
QSharedPointer<RealTerminal> m_real_terminal;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TERMINALELEMENT_H
|
#endif // TERMINALELEMENT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user