[qet] qet/qet: [4795] Element now use the pattern and variable of formula to create the label, both stored in diagram context ( instead of the label with a pattern and formula, to create the final label ) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
- To: qet@xxxxxxxxxxxxxxxxxxx
- Subject: [qet] qet/qet: [4795] Element now use the pattern and variable of formula to create the label, both stored in diagram context ( instead of the label with a pattern and formula, to create the final label )
- From: subversion@xxxxxxxxxxxxx
- Date: Thu, 01 Dec 2016 10:09:51 +0100
Revision: 4795
Author: blacksun
Date: 2016-12-01 10:09:50 +0100 (Thu, 01 Dec 2016)
Log Message:
-----------
Element now use the pattern and variable of formula to create the label, both stored in diagram context (instead of the label with a pattern and formula, to create the final label)
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/diagramevent/diagrameventaddelement.cpp
trunk/sources/qetgraphicsitem/commentitem.cpp
trunk/sources/qetgraphicsitem/customelement.cpp
trunk/sources/qetgraphicsitem/element.cpp
trunk/sources/qetgraphicsitem/element.h
trunk/sources/qetgraphicsitem/masterelement.cpp
trunk/sources/qetgraphicsitem/masterelement.h
trunk/sources/qetgraphicsitem/simpleelement.cpp
trunk/sources/qetgraphicsitem/simpleelement.h
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/diagram.cpp 2016-12-01 09:09:50 UTC (rev 4795)
@@ -1016,15 +1016,6 @@
Element *elmt = static_cast<Element*>(item);
foreach(ElementTextItem *eti, elmt->texts())
connect (eti, &ElementTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
- Element::kind linkType = elmt->linkType();
- if ((linkType == Element::Simple) ||
- (linkType == Element::Master) ||
- (linkType == Element::Slave) ||
- (linkType == Element::Terminale)) {
- CustomElement *celmt = static_cast<CustomElement*>(item);
- celmt->parseLabels();
- }
- elmt->updateLabel();
}
break;
Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp 2016-12-01 09:09:50 UTC (rev 4795)
@@ -189,7 +189,7 @@
//Everything is good
return true;
}
-
+#include "elementtextitem.h"
/**
* @brief DiagramEventAddElement::addElement
* Add an element at the current pos en current rotation,
@@ -237,8 +237,9 @@
conductor->setFreezeLabel(true);
}
};
+
m_diagram -> undoStack().push(undo_object);
- element->SetUpSequential();
+ element->setUpFormula();
+ element->updateLabel();
element->freezeNewAddedElement();
- element->updateLabel();
}
Modified: trunk/sources/qetgraphicsitem/commentitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/commentitem.cpp 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/qetgraphicsitem/commentitem.cpp 2016-12-01 09:09:50 UTC (rev 4795)
@@ -113,7 +113,6 @@
QString location = m_element -> elementInformations()["location"].toString();
- QPainterPath m_shape_path_ = QPainterPath();
prepareGeometryChange();
m_bounding_rect = QRectF();
Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/qetgraphicsitem/customelement.cpp 2016-12-01 09:09:50 UTC (rev 4795)
@@ -694,18 +694,6 @@
eti -> setFollowParentRotations(e.attribute("rotate") == "true");
list_texts_ << eti;
- if (e.attribute("tagg")=="label") {
- DiagramContext &dc = this->rElementInformations();
- dc.addValue("label", e.attribute("text"));
- this->setElementInformations(dc);
- this->setTaggedText("label", e.attribute("text"));
- }
- else if (e.attribute("tagg")=="function") {
- DiagramContext &dc = this->rElementInformations();
- dc.addValue("function", e.attribute("text"));
- this->setElementInformations(dc);
- }
-
// Se positionne aux coordonnees indiquees dans la description du texte
qp.setTransform(QTransform(), false);
qp.translate(pos_x, pos_y);
@@ -762,18 +750,19 @@
ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this);
eti -> setFont(QETApp::diagramTextsFont(size));
eti -> setTagg(e.attribute("tagg", "other"));
+ m_element_informations.addValue(e.attribute("tagg", "other"), e.attribute("text"));
- // position the text field
+ // position the text field
eti -> setOriginalPos(QPointF(pos_x, pos_y));
eti -> setPos(pos_x, pos_y);
- // rotation of the text field
+ // rotation of the text field
qreal original_rotation_angle = 0.0;
QET::attributeIsAReal(e, "rotation", &original_rotation_angle);
eti -> setOriginalRotationAngle(original_rotation_angle);
eti -> setRotationAngle(original_rotation_angle);
- // behavior when the parent element is rotated
+ // behavior when the parent element is rotated
eti -> setFollowParentRotations(e.attribute("rotate") == "true");
list_texts_ << eti;
Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/qetgraphicsitem/element.cpp 2016-12-01 09:09:50 UTC (rev 4795)
@@ -730,19 +730,45 @@
}
/**
- * @brief Element::SetUpSequential
- * Setup the sequential value of this element
+ * @brief Element::setUpFormula
+ * Set up the formula used to create the label of this element
+ * @param : if true set tagged text to code letter (ex K for coil) with condition :
+ * formula is empty, text tagged "label" is emptty or "_";
*/
-void Element::SetUpSequential()
+void Element::setUpFormula(bool code_letter)
{
+ if (linkType() == Element::Slave || linkType() & Element::AllReport)
+ return;
+
if (diagram())
{
- QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum();
- NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum);
- NumerotationContextCommands ncc (nc);
+ QString formula = diagram()->project()->elementAutoNumCurrentFormula();
- autonum::setSequential(elementInformations()["label"].toString(), m_autoNum_seq, nc, diagram(), element_currentAutoNum);
- diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next());
+ if (formula.isEmpty())
+ {
+ if (code_letter && !m_prefix.isEmpty())
+ {
+ if (ElementTextItem *eti = taggedText("label"))
+ {
+ QString text = eti->toPlainText();
+ if (text.isEmpty() || text == "_")
+ {
+ m_element_informations.addValue("formula", "%prefix");
+ }
+ }
+ }
+ }
+ else
+ {
+ m_element_informations.addValue("formula", formula);
+
+ QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum();
+ NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum);
+ NumerotationContextCommands ncc (nc);
+
+ autonum::setSequential(formula, m_autoNum_seq, nc, diagram(), element_currentAutoNum);
+ diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next());
+ }
}
}
@@ -824,3 +850,26 @@
}
else return;
}
+
+/**
+ * @brief Element::setUpConnectionForFormula
+ * setup connection according to the variable of formula
+ * @param old_formula
+ * @param new_formula
+ */
+void Element::setUpConnectionForFormula(QString old_formula, QString new_formula)
+{
+ if (diagram() && (old_formula.contains("%f") || old_formula.contains("%id")))
+ disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &Element::updateLabel);
+ if (old_formula.contains("%l"))
+ disconnect(this, &Element::yChanged, this, &Element::updateLabel);
+ if (old_formula.contains("%c"))
+ disconnect(this, &Element::xChanged, this, &Element::updateLabel);
+
+ if (diagram() && (new_formula.contains("%f") || new_formula.contains("%id")))
+ connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &Element::updateLabel);
+ if (new_formula.contains("%l"))
+ connect(this, &Element::yChanged, this, &Element::updateLabel);
+ if (new_formula.contains("%c"))
+ connect(this, &Element::xChanged, this, &Element::updateLabel);
+}
Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/qetgraphicsitem/element.h 2016-12-01 09:09:50 UTC (rev 4795)
@@ -32,7 +32,8 @@
/**
This is the base class for electrical elements.
*/
-class Element : public QetGraphicsItem {
+class Element : public QetGraphicsItem
+{
Q_OBJECT
// constructors, destructor
@@ -139,7 +140,7 @@
autonum::sequenceStruct sequenceStruct () const {return m_autoNum_seq;}
autonum::sequenceStruct& rSequenceStruct() {return m_autoNum_seq;}
- void SetUpSequential ();
+ void setUpFormula(bool code_letter = true);
void setPrefix(QString);
QString getPrefix() const;
void freezeLabel();
@@ -146,8 +147,11 @@
void unfreezeLabel();
void freezeNewAddedElement();
- //ATTRIBUTES
protected:
+ void setUpConnectionForFormula(QString old_formula, QString new_formula);
+
+ //ATTRIBUTES
+ protected:
DiagramContext m_element_informations, kind_informations_;
autonum::sequenceStruct m_autoNum_seq;
Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp 2016-12-01 09:09:50 UTC (rev 4795)
@@ -31,13 +31,11 @@
*/
MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
CustomElement(location, qgi, state),
- cri_ (nullptr)
+ m_Xref_item (nullptr)
{
link_type_ = Master;
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()));
+ connect(this, &Element::updateLabel, [this]() {this->updateLabel(this->elementInformations(), this->elementInformations());});
}
/**
@@ -62,12 +60,12 @@
connected_elements << elmt;
elmt->linkToElement(this);
- if (!cri_) cri_ = new CrossRefItem(this); //create cross ref item if not yet
+ if (!m_Xref_item) m_Xref_item = new CrossRefItem(this); //create cross ref item if not yet
- connect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
- connect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
- connect(elmt, SIGNAL(updateLabel()), cri_, SLOT(updateLabel()));
- cri_ -> updateLabel();
+ connect(elmt, SIGNAL(xChanged()), m_Xref_item, SLOT(updateLabel()));
+ connect(elmt, SIGNAL(yChanged()), m_Xref_item, SLOT(updateLabel()));
+ connect(elmt, SIGNAL(updateLabel()), m_Xref_item, SLOT(updateLabel()));
+ m_Xref_item -> updateLabel();
emit linkedElementChanged();
}
}
@@ -102,11 +100,11 @@
elmt -> setHighlighted (false);
//update the graphics cross ref
- disconnect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
- disconnect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
- disconnect(elmt, SIGNAL(updateLabel()), cri_, SLOT(updateLabel()));
+ disconnect(elmt, SIGNAL(xChanged()), m_Xref_item, SLOT(updateLabel()));
+ disconnect(elmt, SIGNAL(yChanged()), m_Xref_item, SLOT(updateLabel()));
+ disconnect(elmt, SIGNAL(updateLabel()), m_Xref_item, SLOT(updateLabel()));
- cri_ -> updateLabel();
+ m_Xref_item -> updateLabel();
aboutDeleteXref();
emit linkedElementChanged();
}
@@ -125,27 +123,6 @@
}
/**
- * @brief MasterElement::folioIdChange
- * Used to update the label of this item when the folio id change
- */
-void MasterElement::folioIdChange() {
- DiagramContext dc =elementInformations();
- setTaggedText("label", autonum::AssignVariables::formulaToLabel(dc["label"].toString(), m_autoNum_seq, diagram(), this), true);
-}
-
-/**
- * @brief MasterElement::changeElementInfo()
- * Update label if it contains %c, %l, %f or %F variables
- */
-void MasterElement::changeElementInfo(){
- QString temp_label = this->elementInformations()["label"].toString();
- if (temp_label.contains("\%")) {
- if (this->diagram()!=NULL)
- this->updateLabel(this->elementInformations(),this->elementInformations());
- }
-}
-
-/**
* @brief MasterElement::updateLabel
* update label of this element
* and the comment item if he's displayed.
@@ -152,49 +129,33 @@
*/
void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
{
- const QString old_label = old_info["label"].toString();
- const QString new_label = new_info["label"].toString();
+ QString old_formula = old_info["formula"].toString();
+ QString new_formula = new_info["formula"].toString();
- QString newstr = autonum::AssignVariables::formulaToLabel(new_label, m_autoNum_seq, diagram(), this);
+ setUpConnectionForFormula(old_formula, new_formula);
- ElementTextItem *eti = taggedText("label");
+ QString label = autonum::AssignVariables::formulaToLabel(new_formula, m_autoNum_seq, diagram(), this);
- //Label of element
- if (eti && (eti->toPlainText() != newstr))
+ if (label.isEmpty())
{
- if (new_label.isEmpty())
- {
- setTaggedText("label", "_", false);
- }
- else
- {
- setTaggedText("label", newstr, true);
- }
-
- //If autonum formula have %id %f or %F (because %F can itself contain %id or %f),
- //we connect the change of folio position, to keep up to date the label.
- if (diagram() && diagram()->project())
- {
- if (old_label.contains(QRegularExpression("%id|%f|%F")) && !new_label.contains(QRegularExpression("%id|%f|%F")))
- {
- disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &MasterElement::folioIdChange);
- }
- else if (new_label.contains(QRegularExpression("%id|%f|%F")))
- {
- connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &MasterElement::folioIdChange);
- }
- }
+ setTaggedText("label", new_info["label"].toString());
}
+ else
+ {
+ bool visible = m_element_informations.contains("label") ? m_element_informations.keyMustShow("label") : true;
+ m_element_informations.addValue("label", label, visible);
+ setTaggedText("label", label);
+ }
- if (eti)
+ if (ElementTextItem *eti = taggedText("label"))
{
- new_label.isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
+ new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
}
//Delete or update the xref
- if (cri_) {
- cri_ -> updateLabel();
+ if (m_Xref_item) {
+ m_Xref_item -> updateLabel();
aboutDeleteXref();
}
else {
@@ -205,7 +166,7 @@
bool must_show_location = elementInformations().keyMustShow("location");
if (! (comment.isEmpty() || !must_show_comment) || !(location.isEmpty() || !must_show_location)) {
- cri_ = new CrossRefItem(this);
+ m_Xref_item = new CrossRefItem(this);
}
}
}
@@ -221,12 +182,12 @@
* @return
*/
bool MasterElement::aboutDeleteXref() {
- if(!cri_) return true;
+ if(!m_Xref_item) return true;
if(!linkedElements().isEmpty()) return false;
- if (cri_ -> boundingRect().isNull()) {
- delete cri_;
- cri_ = nullptr;
+ if (m_Xref_item -> boundingRect().isNull()) {
+ delete m_Xref_item;
+ m_Xref_item = nullptr;
return true;
}
Modified: trunk/sources/qetgraphicsitem/masterelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.h 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/qetgraphicsitem/masterelement.h 2016-12-01 09:09:50 UTC (rev 4795)
@@ -40,21 +40,15 @@
virtual void unlinkAllElements ();
virtual void unlinkElement (Element *elmt);
virtual void initLink (QETProject *project);
-
- signals:
- private:
- void folioIdChange();
-
public slots:
void updateLabel(DiagramContext old_info, DiagramContext new_info);
- void changeElementInfo();
private:
bool aboutDeleteXref ();
private:
- CrossRefItem *cri_;
+ CrossRefItem *m_Xref_item;
};
#endif // MASTERELEMENT_H
Modified: trunk/sources/qetgraphicsitem/simpleelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.cpp 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/qetgraphicsitem/simpleelement.cpp 2016-12-01 09:09:50 UTC (rev 4795)
@@ -34,9 +34,7 @@
{
link_type_ = Simple;
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()));
+ connect(this, &Element::updateLabel, [this]() {this->updateLabel(this->elementInformations(), this->elementInformations());});
}
/**
@@ -58,59 +56,35 @@
}
/**
- * @brief SimpleElement::folioIdChange
- * Use to update the label of this item when the foio id change
- */
-void SimpleElement::folioIdChange()
-{
- DiagramContext dc =elementInformations();
- setTaggedText("label", autonum::AssignVariables::formulaToLabel(dc["label"].toString(), m_autoNum_seq, diagram(), this));
-}
-
-/**
- * @brief SimpleElement::changeElementInfo()
- * Update label if it contains %c, %l, %f or %F variables
- */
-void SimpleElement::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 SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
{
- QString label = autonum::AssignVariables::formulaToLabel(new_info["label"].toString(), m_autoNum_seq, diagram(), this);
+ QString old_formula = old_info["formula"].toString();
+ QString new_formula = new_info["formula"].toString();
- //Label of element
- if (old_info["label"].toString() != label) {
- if (new_info["label"].toString().isEmpty())
- setTaggedText("label", "_", false);
- else {
- setTaggedText("label", label, true);
- }
+ setUpConnectionForFormula(old_formula, new_formula);
- //If autonum formula have %id we connect the change of folio position, to keep up to date the label.
- if (diagram() && diagram()->project()) {
- if (old_info["label"].toString().contains("%id") && !new_info["label"].toString().contains("%id")) {
- disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &SimpleElement::folioIdChange);
- }
- else if (new_info["label"].toString().contains("%id")) {
- connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &SimpleElement::folioIdChange);
- }
+ QString label = autonum::AssignVariables::formulaToLabel(new_formula, m_autoNum_seq, diagram(), this);
+
+ if (label.isEmpty())
+ {
+ setTaggedText("label", new_info["label"].toString());
}
+ else
+ {
+ bool visible = m_element_informations.contains("label") ? m_element_informations.keyMustShow("label") : true;
+ m_element_informations.addValue("label", label, visible);
+ setTaggedText("label", label);
}
- if (ElementTextItem *eti = taggedText("label")) {
+ if (ElementTextItem *eti = taggedText("label"))
+ {
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
}
- //Comment and Location of element
+ //Comment and Location of element
QString comment = new_info["comment"].toString();
bool must_show = new_info.keyMustShow("comment");
QString location = new_info["location"].toString();
Modified: trunk/sources/qetgraphicsitem/simpleelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.h 2016-11-29 20:24:27 UTC (rev 4794)
+++ trunk/sources/qetgraphicsitem/simpleelement.h 2016-12-01 09:09:50 UTC (rev 4795)
@@ -37,14 +37,8 @@
virtual void initLink(QETProject *project);
- signals:
-
- private:
- void folioIdChange();
-
public slots:
void updateLabel(DiagramContext old_info, DiagramContext new_info);
- void changeElementInfo();
private:
CommentItem *m_comment_item;