[qet] [4195] Element editor : Add new tagg for text field (function and tension/ protocol). |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4195
Author: blacksun
Date: 2015-09-10 10:48:33 +0200 (Thu, 10 Sep 2015)
Log Message:
-----------
Element editor : Add new tagg for text field (function and tension/protocol).
Report element : text field tagged function or tension/protocol display the function tension/protocol of the potential.
Modified Paths:
--------------
trunk/sources/editor/textfieldeditor.cpp
trunk/sources/qetgraphicsitem/conductor.cpp
trunk/sources/qetgraphicsitem/conductor.h
trunk/sources/qetgraphicsitem/reportelement.cpp
trunk/sources/qetgraphicsitem/reportelement.h
trunk/sources/qetgraphicsitem/terminal.cpp
trunk/sources/qetgraphicsitem/terminal.h
Modified: trunk/sources/editor/textfieldeditor.cpp
===================================================================
--- trunk/sources/editor/textfieldeditor.cpp 2015-09-08 18:18:02 UTC (rev 4194)
+++ trunk/sources/editor/textfieldeditor.cpp 2015-09-10 08:48:33 UTC (rev 4195)
@@ -66,12 +66,14 @@
t -> addWidget(qle_text);
main_layout -> addLayout(t);
- //add the tagg combobox
+ //add the tagg combobox
QHBoxLayout *tagg_layout = new QHBoxLayout();
tagg_layout -> addWidget(new QLabel(tr("tagg :")));
tagg_layout -> addWidget(m_tagg_cb = new QComboBox());
m_tagg_cb -> addItem(tr("Aucun"), QVariant("none"));
m_tagg_cb -> addItem(tr("label"), QVariant("label"));
+ m_tagg_cb -> addItem(tr("Fonction"), QVariant("function"));
+ m_tagg_cb -> addItem(tr("Tension/protocole"), QVariant("tension-protocol"));
main_layout -> addLayout(tagg_layout);
QHBoxLayout *rotation_angle_layout = new QHBoxLayout();
@@ -184,6 +186,12 @@
}
m_locked= false;
}
+
+/**
+ * @brief TextFieldEditor::updateTagg
+ * Change the tagg of the text field.
+ * Change is apply with a QUndoCommand
+ */
void TextFieldEditor::updateTagg()
{
if(m_locked) return;
Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp 2015-09-08 18:18:02 UTC (rev 4194)
+++ trunk/sources/qetgraphicsitem/conductor.cpp 2015-09-10 08:48:33 UTC (rev 4195)
@@ -1366,6 +1366,7 @@
}
readProperties();
+ emit propertiesChange();
}
/**
Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h 2015-09-08 18:18:02 UTC (rev 4194)
+++ trunk/sources/qetgraphicsitem/conductor.h 2015-09-10 08:48:33 UTC (rev 4195)
@@ -42,6 +42,9 @@
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
Q_PROPERTY(int animPath READ fakePath WRITE updatePathAnimate)
Q_PROPERTY(ConductorProperties properties READ properties WRITE setProperties)
+
+ signals:
+ void propertiesChange();
// constructors, destructor
public:
Modified: trunk/sources/qetgraphicsitem/reportelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.cpp 2015-09-08 18:18:02 UTC (rev 4194)
+++ trunk/sources/qetgraphicsitem/reportelement.cpp 2015-09-10 08:48:33 UTC (rev 4195)
@@ -20,10 +20,13 @@
#include "diagramposition.h"
#include "qetproject.h"
#include "diagram.h"
+#include "terminal.h"
+#include "conductor.h"
ReportElement::ReportElement(const ElementsLocation &location, QString link_type,QGraphicsItem *qgi, int *state) :
CustomElement(location, qgi, state),
- m_text_field (nullptr)
+ m_text_field (nullptr),
+ m_watched_conductor(nullptr)
{
/*
* Get text tagged label. This is work for report
@@ -39,10 +42,22 @@
link_type == "next_report"? link_type_=NextReport : link_type_=PreviousReport;
link_type == "next_report"? inverse_report=PreviousReport : inverse_report=NextReport;
+
+ //We make these connections, to be always aware about the conductor properties
+ connect (terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
+ connect (terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
}
-ReportElement::~ReportElement() {
+/**
+ * @brief ReportElement::~ReportElement
+ * Destructor
+ */
+ReportElement::~ReportElement()
+{
unlinkAllElements();
+ disconnect(terminals().first(), 0, 0, 0);
+ if (m_watched_conductor)
+ disconnect(m_watched_conductor, &Conductor::propertiesChange, this, &ReportElement::updateLabel);
}
/**
@@ -61,10 +76,8 @@
//ensure elmt isn't already linked
bool i = true;
- if (!this -> isFree())
- {
- if (connected_elements.first() == elmt) i = false;
- }
+ if (!this -> isFree() && (connected_elements.first() == elmt))
+ i = false;
//ensure elmt is an inverse report of this element
if ((elmt->linkType() == inverse_report) && i)
@@ -76,11 +89,18 @@
connect(elmt, SIGNAL( yChanged() ), this, SLOT( updateLabel() ));
connect(diagram(), SIGNAL( reportPropertiesChanged(QString) ), this, SLOT( setLabel(QString) ));
connect(diagram() -> project(), SIGNAL( projectDiagramsOrderChanged(QETProject*,int,int) ), this, SLOT( updateLabel() ));
+ connect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
+ connect(elmt->terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
label_ = diagram() -> defaultReportProperties();
- updateLabel();
+ if (!m_watched_conductor && elmt->conductors().size())
+ conductorWasAdded(elmt->conductors().first());
+ else
+ updateLabel();
+
elmt -> linkToElement(this);
+
emit linkedElementChanged();
}
}
@@ -91,26 +111,30 @@
*/
void ReportElement::unlinkAllElements()
{
- if (!isFree())
- {
- QList <Element *> tmp_elmt = connected_elements;
+ if (isFree()) return;
- foreach(Element *elmt, connected_elements)
- {
- disconnect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel()));
- disconnect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel()));
- disconnect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
- }
- connected_elements.clear();
- updateLabel();
+ QList <Element *> tmp_elmt = connected_elements;
- foreach(Element *elmt, tmp_elmt)
- {
- elmt -> setHighlighted(false);
- elmt -> unlinkAllElements();
- }
- emit linkedElementChanged();
+ foreach(Element *elmt, connected_elements)
+ {
+ disconnect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel()));
+ disconnect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel()));
+ disconnect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
+ disconnect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
+ disconnect(elmt->terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
+ connected_elements.removeAll(elmt);
+ //if elmt is the owner of m_watched_conductor, we remove it
+ if (elmt->conductors().contains(m_watched_conductor))
+ conductorWasRemoved(m_watched_conductor);
}
+ updateLabel();
+
+ foreach(Element *elmt, tmp_elmt)
+ {
+ elmt -> setHighlighted(false);
+ elmt -> unlinkAllElements();
+ }
+ emit linkedElementChanged();
}
/**
* @brief ReportElement::unlinkElement
@@ -125,6 +149,44 @@
}
/**
+ * @brief ReportElement::conductorWasAdded
+ * This method is called when a conduxtor is added to the potential
+ * @param conductor : added conductor
+ */
+void ReportElement::conductorWasAdded(Conductor *conductor)
+{
+ if (m_watched_conductor) return;
+
+ m_watched_conductor = conductor;
+ connect(m_watched_conductor, &Conductor::propertiesChange, this, &ReportElement::updateLabel);
+ updateLabel();
+}
+
+/**
+ * @brief ReportElement::conductorWasRemoved
+ * This method is called when a conductor is removed to the potential
+ * @param conductor : removed conductor
+ */
+void ReportElement::conductorWasRemoved(Conductor *conductor)
+{
+ if (m_watched_conductor != conductor) return;
+
+ disconnect(m_watched_conductor, &Conductor::propertiesChange, this, &ReportElement::updateLabel);
+ m_watched_conductor = nullptr;
+
+ //Get another conductor to be always up to date about the properties of the potential.
+
+ //Get a conducteur docked to this report
+ if (conductors().size())
+ conductorWasAdded(conductors().first());
+ //Else we get a conductor of the linked report (if any)
+ else if (linkedElements().size() && linkedElements().first()->conductors().size())
+ conductorWasAdded(linkedElements().first()->conductors().first());
+ else
+ updateLabel();
+}
+
+/**
* @brief ReportElement::setLabel
* Set new label and call updatelabel
* @param label new label
@@ -153,7 +215,8 @@
m_text_field -> setPlainText(label);
}
else
- {
m_text_field -> setPlainText("/");
- }
+
+ setTaggedText("function", (m_watched_conductor? m_watched_conductor->properties().m_function : ""));
+ setTaggedText("tension-protocol", (m_watched_conductor? m_watched_conductor->properties().m_tension_protocol : ""));
}
Modified: trunk/sources/qetgraphicsitem/reportelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.h 2015-09-08 18:18:02 UTC (rev 4194)
+++ trunk/sources/qetgraphicsitem/reportelement.h 2015-09-10 08:48:33 UTC (rev 4195)
@@ -27,27 +27,30 @@
*this class represent an element that can be linked to an other ReportElement
* a folio report in a diagram is a element that show a wire go on an other folio
*/
-class ReportElement : public CustomElement {
-
+class ReportElement : public CustomElement
+{
Q_OBJECT
- public :
- explicit ReportElement(const ElementsLocation &,QString link_type, QGraphicsItem * = 0, int * = 0);
- ~ReportElement();
- virtual void linkToElement(Element *);
- virtual void unlinkAllElements();
- virtual void unlinkElement(Element *elmt);
+ public :
+ explicit ReportElement(const ElementsLocation &,QString link_type, QGraphicsItem * = 0, int * = 0);
+ ~ReportElement();
+ virtual void linkToElement(Element *);
+ virtual void unlinkAllElements();
+ virtual void unlinkElement(Element *elmt);
private:
- int inverse_report;
- QString label_;
- ElementTextItem *m_text_field;
+ int inverse_report;
+ QString label_;
+ ElementTextItem *m_text_field;
+ Conductor *m_watched_conductor;
- signals:
+ private:
+ void conductorWasAdded(Conductor *conductor);
+ void conductorWasRemoved(Conductor *conductor);
private slots:
- void setLabel (QString label);
- void updateLabel();
+ void setLabel (QString label);
+ void updateLabel();
};
#endif // REPORTELEMENT_H
Modified: trunk/sources/qetgraphicsitem/terminal.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.cpp 2015-09-08 18:18:02 UTC (rev 4194)
+++ trunk/sources/qetgraphicsitem/terminal.cpp 2015-09-10 08:48:33 UTC (rev 4195)
@@ -78,7 +78,7 @@
@param s Scene sur laquelle figure cette borne
*/
Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
- QGraphicsItem(e),
+ QGraphicsObject(e),
m_draw_help_line(false),
m_help_line (nullptr),
m_help_line_a (nullptr),
@@ -97,7 +97,7 @@
@param s Scene sur laquelle figure cette borne
*/
Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
- QGraphicsItem(e),
+ QGraphicsObject(e),
m_draw_help_line (false),
m_help_line (nullptr),
m_help_line_a (nullptr),
@@ -118,7 +118,7 @@
@param s Scene sur laquelle figure cette borne
*/
Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) :
- QGraphicsItem (e),
+ QGraphicsObject (e),
m_draw_help_line (false),
m_help_line (nullptr),
m_help_line_a (nullptr),
@@ -179,41 +179,41 @@
}
/**
- Attribue un conductor a la borne
- @param f Le conducteur a rattacher a cette borne
-*/
-bool Terminal::addConductor(Conductor *f) {
- // pointeur 0 refuse
- if (!f) return(false);
+ * @brief Terminal::addConductor
+ * Add a conductor to this terminal
+ * @param conductor : the conductor to add.
+ * @return true if the conductor was successfully added
+ */
+bool Terminal::addConductor(Conductor *conductor)
+{
+ if (!conductor) return(false);
- // une seule des deux bornes du conducteur doit etre this
- Q_ASSERT_X(((f -> terminal1 == this) ^ (f -> terminal2 == this)), "Terminal::addConductor", "Le conductor devrait etre relie exactement une fois a la terminal en cours");
+ Q_ASSERT_X(((conductor -> terminal1 == this) ^ (conductor -> terminal2 == this)), "Terminal::addConductor", "The conductor must be linked exactly once to this terminal");
- // determine l'autre borne a laquelle cette borne va etre relie grace au conducteur
- Terminal *autre_terminal = (f -> terminal1 == this) ? f -> terminal2 : f -> terminal1;
+ //Get the other terminal where the conductor must be linked
+ Terminal *other_terminal = (conductor -> terminal1 == this) ? conductor->terminal2 : conductor->terminal1;
- // verifie que la borne n'est pas deja reliee avec l'autre borne
- bool deja_liees = false;
- foreach (Conductor* conductor, conductors_) {
- if (conductor -> terminal1 == autre_terminal || conductor -> terminal2 == autre_terminal) deja_liees = true;
- }
-
- // si les deux bornes sont deja reliees, on refuse d'ajouter le conducteur
- if (deja_liees) return(false);
-
- // sinon on ajoute le conducteur
- conductors_.append(f);
+ //Check if this terminal isn't already linked with other_terminal
+ foreach (Conductor* cond, conductors_)
+ if (cond -> terminal1 == other_terminal || cond -> terminal2 == other_terminal)
+ return false; //They already a conductor linked to this and other_terminal
+
+ conductors_.append(conductor);
+ emit conductorWasAdded(conductor);
return(true);
}
/**
- Enleve un conducteur donne a la borne
- @param f Conducteur a enlever
-*/
-void Terminal::removeConductor(Conductor *f) {
- int index = conductors_.indexOf(f);
+ * @brief Terminal::removeConductor
+ * Remove a conductor from this terminal
+ * @param conductor : conductor to remove
+ */
+void Terminal::removeConductor(Conductor *conductor)
+{
+ int index = conductors_.indexOf(conductor);
if (index == -1) return;
conductors_.removeAt(index);
+ emit conductorWasRemoved(conductor);
}
/**
Modified: trunk/sources/qetgraphicsitem/terminal.h
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.h 2015-09-08 18:18:02 UTC (rev 4194)
+++ trunk/sources/qetgraphicsitem/terminal.h 2015-09-10 08:48:33 UTC (rev 4195)
@@ -27,9 +27,15 @@
This class represents a terminal of an electrical element, i.e. a possible
plug point for conductors.
*/
-class Terminal : public QGraphicsItem {
+class Terminal : public QGraphicsObject
+{
+ Q_OBJECT
+
+ signals:
+ void conductorWasAdded(Conductor *conductor);
+ void conductorWasRemoved(Conductor *conductor);
- // constructors, destructor
+ // constructors, destructor
public:
Terminal(QPointF, Qet::Orientation, Element * = 0);
Terminal(qreal, qreal, Qet::Orientation, Element * = 0);
@@ -39,7 +45,7 @@
private:
Terminal(const Terminal &);
- // methods
+ // methods
public:
//Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a Terminal
//@return the QGraphicsItem type
@@ -52,8 +58,8 @@
// methods to manage conductors attached to the terminal
Terminal* alignedWithTerminal () const;
- bool addConductor (Conductor *);
- void removeConductor (Conductor *);
+ bool addConductor (Conductor *conductor);
+ void removeConductor (Conductor *conductor);
int conductorsCount () const;
Diagram *diagram () const;
Element *parentElement () const;