diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 397a69675..73231b9e3 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -26,6 +26,7 @@ */ PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) : CustomElementGraphicPart(editor, parent), + m_tagg("none"), m_orientation(Qet::North) { updateSecondPoint(); @@ -64,6 +65,7 @@ const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { // ecrit la position de la borne xml_element.setAttribute("x", QString("%1").arg(scenePos().x())); xml_element.setAttribute("y", QString("%1").arg(scenePos().y())); + xml_element.setAttribute("tagg", m_tagg); // ecrit l'orientation de la borne xml_element.setAttribute("orientation", Qet::orientationToString(m_orientation)); diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index bf41196cf..da8461c33 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -19,6 +19,9 @@ #define PART_TERMINAL_H #include "customelementgraphicpart.h" +#include "customelementpart.h" +class TextFieldEditor; +class QETElementEditor; /** This class represents a terminal which may be used to compose the drawing of @@ -30,6 +33,11 @@ class PartTerminal : public CustomElementGraphicPart Q_PROPERTY(Qet::Orientation orientation READ orientation WRITE setOrientation) + // tagg of text + Q_PROPERTY(QString tagg READ tagg WRITE setTagg) + QString tagg() const {return m_tagg;} + void setTagg(const QString &tagg) {m_tagg = tagg;} + public: // constructors, destructor PartTerminal(QETElementEditor *editor, QGraphicsItem *parent = 0); @@ -44,6 +52,7 @@ class PartTerminal : public CustomElementGraphicPart private: Qet::Orientation m_orientation; QPointF second_point; + QString m_tagg; // methods public: diff --git a/sources/nomenclature.cpp b/sources/nomenclature.cpp index 7a48e51a1..421b97aea 100644 --- a/sources/nomenclature.cpp +++ b/sources/nomenclature.cpp @@ -105,7 +105,7 @@ QString nomenclature::getNomenclature() //Get only simple, master and unlinked slave element. ElementProvider ep(d); QList list_elements; - list_elements << ep.find(Element::Simple | Element::Master); + list_elements << ep.find(Element::Simple | Element::Master | Element::Terminale); list_elements << ep.freeElement(Element::Slave); foreach (Element *elmt, list_elements) { diff --git a/sources/qetgraphicsitem/terminalelement.cpp b/sources/qetgraphicsitem/terminalelement.cpp index 852115cea..4cb392456 100644 --- a/sources/qetgraphicsitem/terminalelement.cpp +++ b/sources/qetgraphicsitem/terminalelement.cpp @@ -16,6 +16,8 @@ along with QElectroTech. If not, see . */ #include "terminalelement.h" +#include "commentitem.h" +#include "elementtextitem.h" /** * @brief TerminalElement::TerminalElement @@ -26,9 +28,76 @@ * @param state int used to know if the creation of element have error */ TerminalElement::TerminalElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) : - CustomElement(location, qgi, state) + CustomElement(location, qgi, state), + m_comment_item (nullptr), + m_location_item (nullptr) { link_type_ = Terminale; + connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext))); + connect(this, SIGNAL(xChanged()),this, SLOT(changeElementInfo())); + connect(this, SIGNAL(yChanged()),this, SLOT(changeElementInfo())); + connect(this, SIGNAL(updateLabel()),this,SLOT(changeElementInfo())); +} + +TerminalElement::~TerminalElement() { +if (m_comment_item) delete m_comment_item; +} + +/** + * @brief TerminalElement::initLink + * @param project + */ +void TerminalElement::initLink(QETProject *project) { + CustomElement::initLink(project); + updateLabel(DiagramContext(), elementInformations()); +} + +/** + * @brief SimpleElement::changeElementInfo() + * Update label if it contains %c, %l, %f or %F variables + */ +void TerminalElement::changeElementInfo(){ + QString temp_label = this->elementInformations()["label"].toString(); + if (temp_label.contains("\%")) { + if (this->diagram()!=NULL) + this->updateLabel(this->elementInformations(),this->elementInformations()); + } +} + +/** + * @brief SimpleElement::updateLabel + * update label of this element + */ +void TerminalElement::updateLabel(DiagramContext old_info, DiagramContext new_info) { + QString label = new_info["label"].toString(); + Element *elmt = this; + label = assignVariables(label,elmt); + + //Label of element + if (old_info["label"].toString() != label) { + if (new_info["label"].toString().isEmpty()) + setTaggedText("label", "_", false); + else { + setTaggedText("label", label, true); + } + } + + if (ElementTextItem *eti = taggedText("label")) { + new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label")); + } + + //Comment and Location of element + QString comment = new_info["comment"].toString(); + bool must_show = new_info.keyMustShow("comment"); + QString location = new_info["location"].toString(); + bool must_show_location = new_info.keyMustShow("location"); + + if ((!(comment.isEmpty() || !must_show) && !m_comment_item)||(!(location.isEmpty() || !must_show_location) && !m_comment_item)) { + m_comment_item = new CommentItem(this); + } + else if (((comment.isEmpty() || !must_show) && m_comment_item) && ((location.isEmpty() || !must_show_location) && m_comment_item)) { + delete m_comment_item; + m_comment_item = nullptr; + } } -TerminalElement::~TerminalElement() {} diff --git a/sources/qetgraphicsitem/terminalelement.h b/sources/qetgraphicsitem/terminalelement.h index 3cfd51c27..94545b636 100644 --- a/sources/qetgraphicsitem/terminalelement.h +++ b/sources/qetgraphicsitem/terminalelement.h @@ -20,12 +20,26 @@ #include "customelement.h" +class CommentItem; +class QETProject; + class TerminalElement : public CustomElement { Q_OBJECT public: TerminalElement(const ElementsLocation &, QGraphicsItem * = 0, int * = 0); ~TerminalElement(); + virtual void initLink(QETProject *project); + + signals: + + public slots: + void updateLabel(DiagramContext old_info, DiagramContext new_info); + void changeElementInfo(); + + private: + CommentItem *m_comment_item; + CommentItem *m_location_item; }; #endif // TERMINALELEMENT_H diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index 48ee325c6..923cde220 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -198,6 +198,7 @@ void ElementPropertiesWidget::updateUi() m_list_editor << new LinkSingleElementWidget(m_element, this); break; case Element::Terminale: + m_list_editor << new ElementInfoWidget(m_element, this); break; default: break;