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) :
|
||||
m_parent_terminal_strip(parent_strip),
|
||||
m_real_terminal(terminals)
|
||||
{}
|
||||
{
|
||||
for (const auto &real_t : m_real_terminal) {
|
||||
if (real_t) {
|
||||
real_t->setPhysicalTerminal(sharedRef());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PhysicalTerminal::sharedRef
|
||||
@@ -80,6 +86,11 @@ QDomElement PhysicalTerminal::toXml(QDomDocument &parent_document) const
|
||||
*/
|
||||
void PhysicalTerminal::setTerminals(const QVector<QSharedPointer<RealTerminal>> &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) {
|
||||
m_real_terminal.append(terminal);
|
||||
terminal->setPhysicalTerminal(sharedRef());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,8 +110,13 @@ void PhysicalTerminal::addTerminal(const QSharedPointer<RealTerminal> &terminal)
|
||||
* @param terminal
|
||||
* @return true if sucessfully removed
|
||||
*/
|
||||
bool PhysicalTerminal::removeTerminal(const QSharedPointer<RealTerminal> &terminal) {
|
||||
return m_real_terminal.removeOne(terminal);
|
||||
bool PhysicalTerminal::removeTerminal(const QSharedPointer<RealTerminal> &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;
|
||||
}
|
||||
|
||||
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
|
||||
* @return the number of level of this terminal
|
||||
|
||||
@@ -61,6 +61,7 @@ class TerminalStrip;
|
||||
class PhysicalTerminal
|
||||
{
|
||||
friend class TerminalStrip;
|
||||
friend class RealTerminal;
|
||||
|
||||
private:
|
||||
PhysicalTerminal(TerminalStrip *parent_strip, QVector<QSharedPointer<RealTerminal>> terminals);
|
||||
@@ -77,7 +78,9 @@ class PhysicalTerminal
|
||||
|
||||
public:
|
||||
PhysicalTerminal(){}
|
||||
~PhysicalTerminal();
|
||||
|
||||
TerminalStrip* terminalStrip() const;
|
||||
int levelCount() const;
|
||||
int levelOf(const QSharedPointer<RealTerminal> &terminal) const;
|
||||
QVector<QSharedPointer<RealTerminal>> realTerminals() const;
|
||||
|
||||
@@ -25,11 +25,23 @@
|
||||
* @param parent_strip : parent terminal strip
|
||||
* @param terminal : terminal element (if any) in a folio
|
||||
*/
|
||||
RealTerminal::RealTerminal(TerminalStrip *parent_strip,
|
||||
Element *terminal) :
|
||||
m_element(terminal),
|
||||
m_parent_terminal_strip(parent_strip)
|
||||
{}
|
||||
RealTerminal::RealTerminal(Element *terminal) :
|
||||
m_element(terminal)
|
||||
{
|
||||
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
|
||||
@@ -47,6 +59,16 @@ QSharedPointer<RealTerminal> RealTerminal::sharedRef()
|
||||
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
|
||||
* @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_)
|
||||
{
|
||||
m_element = terminal;
|
||||
static_cast<TerminalElement *>(terminal)->setRealTerminal(sharedRef());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -100,11 +123,24 @@ QDomElement RealTerminal::toXml(QDomDocument &parent_document) const
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief parentStrip
|
||||
* @return parent terminal strip
|
||||
* @brief RealTerminal::setPhysicalTerminal
|
||||
* 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 {
|
||||
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
|
||||
{
|
||||
if (m_parent_terminal_strip) {
|
||||
const auto phy_t = m_parent_terminal_strip->physicalTerminal(m_this_weak);
|
||||
if (phy_t) {
|
||||
return phy_t->levelOf(m_this_weak);
|
||||
}
|
||||
if (m_physical_terminal &&
|
||||
sharedRef()) {
|
||||
return m_physical_terminal->levelOf(sharedRef());
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -224,8 +258,8 @@ bool RealTerminal::isElement() const {
|
||||
*/
|
||||
bool RealTerminal::isBridged() const
|
||||
{
|
||||
if (m_parent_terminal_strip) {
|
||||
return !m_parent_terminal_strip->isBridged(m_this_weak.toStrongRef()).isNull();
|
||||
if (parentStrip()) {
|
||||
return !parentStrip()->isBridged(m_this_weak.toStrongRef()).isNull();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -237,8 +271,8 @@ bool RealTerminal::isBridged() const
|
||||
*/
|
||||
QSharedPointer<TerminalStripBridge> RealTerminal::bridge() const
|
||||
{
|
||||
if (m_parent_terminal_strip) {
|
||||
return m_parent_terminal_strip->isBridged(m_this_weak.toStrongRef());
|
||||
if (parentStrip()) {
|
||||
return parentStrip()->isBridged(m_this_weak.toStrongRef());
|
||||
} else {
|
||||
return QSharedPointer<TerminalStripBridge>();
|
||||
}
|
||||
|
||||
@@ -45,14 +45,19 @@ class RealTerminal
|
||||
friend class PhysicalTerminal;
|
||||
|
||||
private:
|
||||
RealTerminal(TerminalStrip *strip, Element *element = nullptr);
|
||||
RealTerminal(Element *element = nullptr);
|
||||
|
||||
QSharedPointer<RealTerminal> sharedRef();
|
||||
QSharedPointer<RealTerminal> sharedRef() const;
|
||||
QWeakPointer<RealTerminal> weakRef();
|
||||
|
||||
bool fromXml(QDomElement xml_element, const QVector<TerminalElement *> &terminal_vector);
|
||||
QDomElement toXml(QDomDocument &parent_document) const;
|
||||
|
||||
void setPhysicalTerminal(const QSharedPointer<PhysicalTerminal> &phy_t);
|
||||
|
||||
public:
|
||||
~RealTerminal();
|
||||
TerminalStrip *parentStrip() const;
|
||||
int level() const;
|
||||
QString label() const;
|
||||
@@ -78,9 +83,9 @@ class RealTerminal
|
||||
|
||||
private :
|
||||
QPointer<Element> m_element;
|
||||
QPointer<TerminalStrip> m_parent_terminal_strip;
|
||||
QUuid m_uuid = QUuid::createUuid();
|
||||
QWeakPointer<RealTerminal> m_this_weak;
|
||||
QSharedPointer<PhysicalTerminal> m_physical_terminal;
|
||||
};
|
||||
|
||||
#endif // REALTERMINAL_H
|
||||
|
||||
@@ -114,7 +114,7 @@ bool TerminalStrip::addTerminal(Element *terminal)
|
||||
m_terminal_elements_vector.append(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();
|
||||
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});
|
||||
m_physical_terminals.append(raw_phy_ptr->sharedRef());
|
||||
|
||||
static_cast<TerminalElement *>(terminal)->setParentTerminalStrip(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -153,7 +151,6 @@ bool TerminalStrip::removeTerminal(Element *terminal)
|
||||
}
|
||||
m_real_terminals.removeOne(real_terminal);
|
||||
|
||||
static_cast<TerminalElement *>(terminal)->setParentTerminalStrip(nullptr);
|
||||
|
||||
rebuildRealVector();
|
||||
return true;
|
||||
@@ -824,13 +821,12 @@ bool TerminalStrip::fromXml(QDomElement &xml_element)
|
||||
//Read each real terminal of the current physical terminal of the loop
|
||||
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();
|
||||
real_t->fromXml(xml_real, free_terminals);
|
||||
if(real_t->isElement())
|
||||
{
|
||||
m_terminal_elements_vector.append(real_t->element());
|
||||
static_cast<TerminalElement*>(real_t->element())->setParentTerminalStrip(this);
|
||||
}
|
||||
real_t_vector.append(real_t);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "terminalelement.h"
|
||||
#include"../TerminalStrip/realterminal.h"
|
||||
|
||||
/**
|
||||
@brief TerminalElement::TerminalElement
|
||||
@@ -41,17 +42,20 @@ void TerminalElement::initLink(QETProject *project) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalElement::setParentTerminalStrip
|
||||
* Set \p strip as parent terminal strip.
|
||||
* Be carefull, this function only set internally the parent terminal strip.
|
||||
* 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
|
||||
* @brief TerminalElement::setRealTerminal
|
||||
* Set @a real_t as the real terminal for this terminal element
|
||||
* @param real_t
|
||||
*/
|
||||
void TerminalElement::setParentTerminalStrip(TerminalStrip *strip) {
|
||||
m_parent_terminal_strip = strip;
|
||||
void TerminalElement::setRealTerminal(const QSharedPointer<RealTerminal> &real_t) {
|
||||
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.
|
||||
*/
|
||||
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"
|
||||
|
||||
class QETProject;
|
||||
class RealTerminal;
|
||||
/**
|
||||
@brief The TerminalElement class
|
||||
*/
|
||||
@@ -35,11 +36,13 @@ class TerminalElement : public Element
|
||||
~TerminalElement() override;
|
||||
void initLink(QETProject *project) override;
|
||||
|
||||
void setRealTerminal(const QSharedPointer<RealTerminal> &real_t);
|
||||
QSharedPointer<RealTerminal> realTerminal() const;
|
||||
void setParentTerminalStrip(TerminalStrip *strip);
|
||||
TerminalStrip *parentTerminalStrip() const;
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_parent_terminal_strip;
|
||||
QSharedPointer<RealTerminal> m_real_terminal;
|
||||
};
|
||||
|
||||
#endif // TERMINALELEMENT_H
|
||||
|
||||
Reference in New Issue
Block a user