minor fix : master element doesn't properly update her tagged text 'label' when he contain %F and %F contain himself %f or %id.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4780 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-11-15 10:18:32 +00:00
parent 151d63c1a3
commit ae9f4b1590

View File

@@ -19,6 +19,7 @@
#include "crossrefitem.h" #include "crossrefitem.h"
#include "elementtextitem.h" #include "elementtextitem.h"
#include "diagram.h" #include "diagram.h"
#include <QRegularExpression>
/** /**
* @brief MasterElement::MasterElement * @brief MasterElement::MasterElement
@@ -149,33 +150,48 @@ void MasterElement::changeElementInfo(){
* update label of this element * update label of this element
* and the comment item if he's displayed. * and the comment item if he's displayed.
*/ */
void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info) { void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
QString newstr = new_info["label"].toString(); {
newstr = autonum::AssignVariables::formulaToLabel(newstr, m_autoNum_seq, diagram(), this); const QString old_label = old_info["label"].toString();
const QString new_label = new_info["label"].toString();
QString newstr = autonum::AssignVariables::formulaToLabel(new_label, m_autoNum_seq, diagram(), this);
ElementTextItem *eti = taggedText("label");
//Label of element //Label of element
if (old_info["label"].toString() != newstr) { if (eti && (eti->toPlainText() != newstr))
if (new_info["label"].toString().isEmpty()) {
if (new_label.isEmpty())
{
setTaggedText("label", "_", false); setTaggedText("label", "_", false);
else { }
else
{
setTaggedText("label", newstr, true); setTaggedText("label", newstr, true);
} }
//If autonum formula have %id we connect the change of folio position, to keep up to date the label. //If autonum formula have %id %f or %F (because %F can itself contain %id or %f),
if (diagram() && diagram()->project()) { //we connect the change of folio position, to keep up to date the label.
if (old_info["label"].toString().contains("%id") && !new_info["label"].toString().contains("%id")) { 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); disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &MasterElement::folioIdChange);
} }
else if (new_info["label"].toString().contains("%id")) { else if (new_label.contains(QRegularExpression("%id|%f|%F")))
{
connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &MasterElement::folioIdChange); connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &MasterElement::folioIdChange);
} }
} }
} }
if (ElementTextItem *eti = taggedText("label")) { if (eti)
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label")); {
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 (cri_) {
cri_ -> updateLabel(); cri_ -> updateLabel();