mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 01:10:53 +01:00
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)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4795 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1016,15 +1016,6 @@ void Diagram::addItem(QGraphicsItem *item)
|
|||||||
Element *elmt = static_cast<Element*>(item);
|
Element *elmt = static_cast<Element*>(item);
|
||||||
foreach(ElementTextItem *eti, elmt->texts())
|
foreach(ElementTextItem *eti, elmt->texts())
|
||||||
connect (eti, &ElementTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
|
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;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ bool DiagramEventAddElement::buildElement()
|
|||||||
//Everything is good
|
//Everything is good
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#include "elementtextitem.h"
|
||||||
/**
|
/**
|
||||||
* @brief DiagramEventAddElement::addElement
|
* @brief DiagramEventAddElement::addElement
|
||||||
* Add an element at the current pos en current rotation,
|
* Add an element at the current pos en current rotation,
|
||||||
@@ -237,8 +237,9 @@ void DiagramEventAddElement::addElement()
|
|||||||
conductor->setFreezeLabel(true);
|
conductor->setFreezeLabel(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
m_diagram -> undoStack().push(undo_object);
|
m_diagram -> undoStack().push(undo_object);
|
||||||
element->SetUpSequential();
|
element->setUpFormula();
|
||||||
element->freezeNewAddedElement();
|
|
||||||
element->updateLabel();
|
element->updateLabel();
|
||||||
|
element->freezeNewAddedElement();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ void CommentItem::updateLabel()
|
|||||||
|
|
||||||
QString location = m_element -> elementInformations()["location"].toString();
|
QString location = m_element -> elementInformations()["location"].toString();
|
||||||
|
|
||||||
QPainterPath m_shape_path_ = QPainterPath();
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
m_bounding_rect = QRectF();
|
m_bounding_rect = QRectF();
|
||||||
|
|
||||||
|
|||||||
@@ -694,18 +694,6 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp) {
|
|||||||
eti -> setFollowParentRotations(e.attribute("rotate") == "true");
|
eti -> setFollowParentRotations(e.attribute("rotate") == "true");
|
||||||
list_texts_ << eti;
|
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
|
// Se positionne aux coordonnees indiquees dans la description du texte
|
||||||
qp.setTransform(QTransform(), false);
|
qp.setTransform(QTransform(), false);
|
||||||
qp.translate(pos_x, pos_y);
|
qp.translate(pos_x, pos_y);
|
||||||
@@ -762,6 +750,7 @@ ElementTextItem *CustomElement::parseInput(QDomElement &e) {
|
|||||||
ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this);
|
ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this);
|
||||||
eti -> setFont(QETApp::diagramTextsFont(size));
|
eti -> setFont(QETApp::diagramTextsFont(size));
|
||||||
eti -> setTagg(e.attribute("tagg", "other"));
|
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 -> setOriginalPos(QPointF(pos_x, pos_y));
|
||||||
|
|||||||
@@ -730,21 +730,47 @@ void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Element::SetUpSequential
|
* @brief Element::setUpFormula
|
||||||
* Setup the sequential value of this element
|
* 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())
|
if (diagram())
|
||||||
{
|
{
|
||||||
|
QString formula = diagram()->project()->elementAutoNumCurrentFormula();
|
||||||
|
|
||||||
|
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();
|
QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum();
|
||||||
NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum);
|
NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum);
|
||||||
NumerotationContextCommands ncc (nc);
|
NumerotationContextCommands ncc (nc);
|
||||||
|
|
||||||
autonum::setSequential(elementInformations()["label"].toString(), m_autoNum_seq, nc, diagram(), element_currentAutoNum);
|
autonum::setSequential(formula, m_autoNum_seq, nc, diagram(), element_currentAutoNum);
|
||||||
diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next());
|
diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementTextItem::setTaggedText
|
* @brief ElementTextItem::setTaggedText
|
||||||
@@ -824,3 +850,26 @@ void Element::freezeNewAddedElement() {
|
|||||||
}
|
}
|
||||||
else return;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ class NumerotationContext;
|
|||||||
/**
|
/**
|
||||||
This is the base class for electrical elements.
|
This is the base class for electrical elements.
|
||||||
*/
|
*/
|
||||||
class Element : public QetGraphicsItem {
|
class Element : public QetGraphicsItem
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
// constructors, destructor
|
// constructors, destructor
|
||||||
@@ -139,13 +140,16 @@ class Element : public QetGraphicsItem {
|
|||||||
autonum::sequenceStruct sequenceStruct () const {return m_autoNum_seq;}
|
autonum::sequenceStruct sequenceStruct () const {return m_autoNum_seq;}
|
||||||
autonum::sequenceStruct& rSequenceStruct() {return m_autoNum_seq;}
|
autonum::sequenceStruct& rSequenceStruct() {return m_autoNum_seq;}
|
||||||
|
|
||||||
void SetUpSequential ();
|
void setUpFormula(bool code_letter = true);
|
||||||
void setPrefix(QString);
|
void setPrefix(QString);
|
||||||
QString getPrefix() const;
|
QString getPrefix() const;
|
||||||
void freezeLabel();
|
void freezeLabel();
|
||||||
void unfreezeLabel();
|
void unfreezeLabel();
|
||||||
void freezeNewAddedElement();
|
void freezeNewAddedElement();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setUpConnectionForFormula(QString old_formula, QString new_formula);
|
||||||
|
|
||||||
//ATTRIBUTES
|
//ATTRIBUTES
|
||||||
protected:
|
protected:
|
||||||
DiagramContext m_element_informations, kind_informations_;
|
DiagramContext m_element_informations, kind_informations_;
|
||||||
|
|||||||
@@ -31,13 +31,11 @@
|
|||||||
*/
|
*/
|
||||||
MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
||||||
CustomElement(location, qgi, state),
|
CustomElement(location, qgi, state),
|
||||||
cri_ (nullptr)
|
m_Xref_item (nullptr)
|
||||||
{
|
{
|
||||||
link_type_ = Master;
|
link_type_ = Master;
|
||||||
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
||||||
connect(this, SIGNAL(xChanged()), this, SLOT(changeElementInfo()));
|
connect(this, &Element::updateLabel, [this]() {this->updateLabel(this->elementInformations(), this->elementInformations());});
|
||||||
connect(this, SIGNAL(yChanged()), this, SLOT(changeElementInfo()));
|
|
||||||
connect(this, SIGNAL(updateLabel()), this, SLOT(changeElementInfo()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,12 +60,12 @@ void MasterElement::linkToElement(Element *elmt)
|
|||||||
connected_elements << elmt;
|
connected_elements << elmt;
|
||||||
elmt->linkToElement(this);
|
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(xChanged()), m_Xref_item, SLOT(updateLabel()));
|
||||||
connect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
|
connect(elmt, SIGNAL(yChanged()), m_Xref_item, SLOT(updateLabel()));
|
||||||
connect(elmt, SIGNAL(updateLabel()), cri_, SLOT(updateLabel()));
|
connect(elmt, SIGNAL(updateLabel()), m_Xref_item, SLOT(updateLabel()));
|
||||||
cri_ -> updateLabel();
|
m_Xref_item -> updateLabel();
|
||||||
emit linkedElementChanged();
|
emit linkedElementChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,11 +100,11 @@ void MasterElement::unlinkElement(Element *elmt)
|
|||||||
elmt -> setHighlighted (false);
|
elmt -> setHighlighted (false);
|
||||||
|
|
||||||
//update the graphics cross ref
|
//update the graphics cross ref
|
||||||
disconnect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
|
disconnect(elmt, SIGNAL(xChanged()), m_Xref_item, SLOT(updateLabel()));
|
||||||
disconnect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
|
disconnect(elmt, SIGNAL(yChanged()), m_Xref_item, SLOT(updateLabel()));
|
||||||
disconnect(elmt, SIGNAL(updateLabel()), cri_, SLOT(updateLabel()));
|
disconnect(elmt, SIGNAL(updateLabel()), m_Xref_item, SLOT(updateLabel()));
|
||||||
|
|
||||||
cri_ -> updateLabel();
|
m_Xref_item -> updateLabel();
|
||||||
aboutDeleteXref();
|
aboutDeleteXref();
|
||||||
emit linkedElementChanged();
|
emit linkedElementChanged();
|
||||||
}
|
}
|
||||||
@@ -124,27 +122,6 @@ void MasterElement::initLink(QETProject *project) {
|
|||||||
updateLabel(DiagramContext(), elementInformations());
|
updateLabel(DiagramContext(), elementInformations());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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
|
* @brief MasterElement::updateLabel
|
||||||
* update label of this element
|
* update label of this element
|
||||||
@@ -152,49 +129,33 @@ void MasterElement::changeElementInfo(){
|
|||||||
*/
|
*/
|
||||||
void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
|
void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
|
||||||
{
|
{
|
||||||
const QString old_label = old_info["label"].toString();
|
QString old_formula = old_info["formula"].toString();
|
||||||
const QString new_label = new_info["label"].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 (label.isEmpty())
|
||||||
if (eti && (eti->toPlainText() != newstr))
|
|
||||||
{
|
{
|
||||||
if (new_label.isEmpty())
|
setTaggedText("label", new_info["label"].toString());
|
||||||
{
|
|
||||||
setTaggedText("label", "_", false);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setTaggedText("label", newstr, true);
|
bool visible = m_element_informations.contains("label") ? m_element_informations.keyMustShow("label") : true;
|
||||||
|
m_element_informations.addValue("label", label, visible);
|
||||||
|
setTaggedText("label", label);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If autonum formula have %id %f or %F (because %F can itself contain %id or %f),
|
if (ElementTextItem *eti = taggedText("label"))
|
||||||
//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")))
|
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eti)
|
|
||||||
{
|
|
||||||
new_label.isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Delete or update the xref
|
//Delete or update the xref
|
||||||
if (cri_) {
|
if (m_Xref_item) {
|
||||||
cri_ -> updateLabel();
|
m_Xref_item -> updateLabel();
|
||||||
aboutDeleteXref();
|
aboutDeleteXref();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -205,7 +166,7 @@ void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info
|
|||||||
bool must_show_location = elementInformations().keyMustShow("location");
|
bool must_show_location = elementInformations().keyMustShow("location");
|
||||||
|
|
||||||
if (! (comment.isEmpty() || !must_show_comment) || !(location.isEmpty() || !must_show_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 @@ void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool MasterElement::aboutDeleteXref() {
|
bool MasterElement::aboutDeleteXref() {
|
||||||
if(!cri_) return true;
|
if(!m_Xref_item) return true;
|
||||||
if(!linkedElements().isEmpty()) return false;
|
if(!linkedElements().isEmpty()) return false;
|
||||||
|
|
||||||
if (cri_ -> boundingRect().isNull()) {
|
if (m_Xref_item -> boundingRect().isNull()) {
|
||||||
delete cri_;
|
delete m_Xref_item;
|
||||||
cri_ = nullptr;
|
m_Xref_item = nullptr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,20 +41,14 @@ class MasterElement : public CustomElement
|
|||||||
virtual void unlinkElement (Element *elmt);
|
virtual void unlinkElement (Element *elmt);
|
||||||
virtual void initLink (QETProject *project);
|
virtual void initLink (QETProject *project);
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
private:
|
|
||||||
void folioIdChange();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateLabel(DiagramContext old_info, DiagramContext new_info);
|
void updateLabel(DiagramContext old_info, DiagramContext new_info);
|
||||||
void changeElementInfo();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool aboutDeleteXref ();
|
bool aboutDeleteXref ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CrossRefItem *cri_;
|
CrossRefItem *m_Xref_item;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MASTERELEMENT_H
|
#endif // MASTERELEMENT_H
|
||||||
|
|||||||
@@ -34,9 +34,7 @@ SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qg
|
|||||||
{
|
{
|
||||||
link_type_ = Simple;
|
link_type_ = Simple;
|
||||||
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
||||||
connect(this, SIGNAL(xChanged()),this, SLOT(changeElementInfo()));
|
connect(this, &Element::updateLabel, [this]() {this->updateLabel(this->elementInformations(), this->elementInformations());});
|
||||||
connect(this, SIGNAL(yChanged()),this, SLOT(changeElementInfo()));
|
|
||||||
connect(this, SIGNAL(updateLabel()),this,SLOT(changeElementInfo()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,56 +55,32 @@ void SimpleElement::initLink(QETProject *project) {
|
|||||||
updateLabel(DiagramContext(), elementInformations());
|
updateLabel(DiagramContext(), elementInformations());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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
|
* @brief SimpleElement::updateLabel
|
||||||
* update label of this element
|
* update label of this element
|
||||||
*/
|
*/
|
||||||
void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
|
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
|
setUpConnectionForFormula(old_formula, new_formula);
|
||||||
if (old_info["label"].toString() != label) {
|
|
||||||
if (new_info["label"].toString().isEmpty())
|
QString label = autonum::AssignVariables::formulaToLabel(new_formula, m_autoNum_seq, diagram(), this);
|
||||||
setTaggedText("label", "_", false);
|
|
||||||
else {
|
if (label.isEmpty())
|
||||||
setTaggedText("label", label, true);
|
{
|
||||||
|
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 autonum formula have %id we connect the change of folio position, to keep up to date the label.
|
if (ElementTextItem *eti = taggedText("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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ElementTextItem *eti = taggedText("label")) {
|
|
||||||
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
|
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,14 +37,8 @@ class SimpleElement : public CustomElement {
|
|||||||
|
|
||||||
virtual void initLink(QETProject *project);
|
virtual void initLink(QETProject *project);
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
private:
|
|
||||||
void folioIdChange();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateLabel(DiagramContext old_info, DiagramContext new_info);
|
void updateLabel(DiagramContext old_info, DiagramContext new_info);
|
||||||
void changeElementInfo();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CommentItem *m_comment_item;
|
CommentItem *m_comment_item;
|
||||||
|
|||||||
Reference in New Issue
Block a user