mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-29 15:10:52 +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:
@@ -34,9 +34,7 @@ SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qg
|
||||
{
|
||||
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());});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,60 +55,36 @@ void SimpleElement::initLink(QETProject *project) {
|
||||
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
|
||||
* 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();
|
||||
|
||||
Reference in New Issue
Block a user