Fix bugtracker report N° 119 : Variable %F (of several element Xref) is not always up to date when the corresponding value of titleblock change.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4906 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-02-11 11:42:52 +00:00
parent 9265839411
commit 1b120550e8
10 changed files with 232 additions and 150 deletions

View File

@@ -1694,15 +1694,11 @@ QETProject *Diagram::project() const {
*/ */
void Diagram::setProject(QETProject *project) void Diagram::setProject(QETProject *project)
{ {
if (m_project == project) return; if (m_project == project)
return;
if (m_project)
disconnect (m_project, SIGNAL(XRefPropertiesChanged()), this, SIGNAL(XRefPropertiesChanged()));
m_project = project; m_project = project;
setParent (project); setParent (project);
connect (m_project, SIGNAL(XRefPropertiesChanged()), this, SIGNAL(XRefPropertiesChanged()));
} }
/** /**

View File

@@ -129,18 +129,14 @@ class Diagram : public QGraphicsScene
public: public:
void setEventInterface (DiagramEventInterface *event_interface); void setEventInterface (DiagramEventInterface *event_interface);
//methods related to xref properties //methods related to autonum
QString defaultReportProperties () const {return m_project -> defaultReportProperties();}
XRefProperties defaultXRefProperties (const QString &str) const {return m_project -> defaultXRefProperties(str);}
//methods related to autonum
QString conductorsAutonumName() const; QString conductorsAutonumName() const;
void setConductorsAutonumName(const QString &name); void setConductorsAutonumName(const QString &name);
static bool clipboardMayContainDiagram(); static bool clipboardMayContainDiagram();
// methods related to parent project // methods related to parent project
QETProject *project() const; QETProject *project() const;
void setProject(QETProject *); void setProject(QETProject *);
int folioIndex() const; int folioIndex() const;
@@ -148,88 +144,88 @@ class Diagram : public QGraphicsScene
void showMe() {emit showDiagram(this);} void showMe() {emit showDiagram(this);}
bool isReadOnly() const; bool isReadOnly() const;
// methods related to conductor creation // methods related to conductor creation
void setConductor(bool); void setConductor(bool);
void setConductorStart (QPointF); void setConductorStart (QPointF);
void setConductorStop(QPointF); void setConductorStop(QPointF);
QList < QSet <Conductor *> > potentials(); QList < QSet <Conductor *> > potentials();
// methods related to XML import/export // methods related to XML import/export
QDomDocument toXml(bool = true); QDomDocument toXml(bool = true);
bool initFromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0); bool initFromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true, DiagramContent * = 0); bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
bool fromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0); bool fromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
void write(); void write();
void write(const QDomElement &); void write(const QDomElement &);
bool wasWritten() const; bool wasWritten() const;
QDomElement writeXml(QDomDocument &) const; QDomElement writeXml(QDomDocument &) const;
void folioSequentialsToXml(QHash<QString, QStringList>*, QDomElement *, QString, QString, QDomDocument *); void folioSequentialsToXml(QHash<QString, QStringList>*, QDomElement *, QString, QString, QDomDocument *);
void folioSequentialsFromXml(const QDomElement&, QHash<QString, QStringList>*, QString, QString, QString, QString); void folioSequentialsFromXml(const QDomElement&, QHash<QString, QStringList>*, QString, QString, QString, QString);
void refreshContents();
// methods related to graphics items addition/removal on the diagram
virtual void addItem (QGraphicsItem *item);
virtual void removeItem (QGraphicsItem *item);
// methods related to graphics options void refreshContents();
ExportProperties applyProperties(const ExportProperties &);
void setDisplayGrid(bool);
bool displayGrid();
void setUseBorder(bool);
bool useBorder();
void setBorderOptions(BorderOptions);
BorderOptions borderOptions();
DiagramPosition convertPosition(const QPointF &);
static QPointF snapToGrid(const QPointF &p);
bool drawTerminals() const; // methods related to graphics items addition/removal on the diagram
void setDrawTerminals(bool); virtual void addItem (QGraphicsItem *item);
bool drawColoredConductors() const; virtual void removeItem (QGraphicsItem *item);
void setDrawColoredConductors(bool);
QString title() const;
bool toPaintDevice(QPaintDevice &, int = -1, int = -1, Qt::AspectRatioMode = Qt::KeepAspectRatio);
QSize imageSize() const;
bool isEmpty() const; // methods related to graphics options
ExportProperties applyProperties(const ExportProperties &);
void setDisplayGrid(bool);
bool displayGrid();
void setUseBorder(bool);
bool useBorder();
void setBorderOptions(BorderOptions);
BorderOptions borderOptions();
DiagramPosition convertPosition(const QPointF &);
static QPointF snapToGrid(const QPointF &p);
QList<CustomElement *> customElements() const; bool drawTerminals() const;
QList<Element *> elements() const; void setDrawTerminals(bool);
QList<Conductor *> conductors() const; bool drawColoredConductors() const;
QSet<DiagramTextItem *> selectedTexts() const; void setDrawColoredConductors(bool);
QSet<ConductorTextItem *> selectedConductorTexts() const;
QSet<ElementTextItem*> selectedElementTexts() const;
QSet<Conductor *> selectedConductors() const;
DiagramContent content() const;
DiagramContent selectedContent();
bool canRotateSelection() const;
int beginMoveElements(QGraphicsItem * = 0);
void continueMoveElements(const QPointF &);
void endMoveElements();
int beginMoveElementTexts(QGraphicsItem * = 0);
void continueMoveElementTexts(const QPointF &);
void endMoveElementTexts();
bool usesElement(const ElementsLocation &);
bool usesTitleBlockTemplate(const QString &);
QUndoStack &undoStack(); QString title() const;
QGIManager &qgiManager(); bool toPaintDevice(QPaintDevice &, int = -1, int = -1, Qt::AspectRatioMode = Qt::KeepAspectRatio);
QSize imageSize() const;
bool isEmpty() const;
//methods related to element label Update Policy QList<CustomElement *> customElements() const;
void freezeElements(bool freeze); QList<Element *> elements() const;
void unfreezeElements(); QList<Conductor *> conductors() const;
void setFreezeNewElements(bool); QSet<DiagramTextItem *> selectedTexts() const;
bool freezeNewElements(); QSet<ConductorTextItem *> selectedConductorTexts() const;
QSet<ElementTextItem*> selectedElementTexts() const;
//methods related to conductor label Update Policy QSet<Conductor *> selectedConductors() const;
void freezeConductors(bool freeze); DiagramContent content() const;
void setFreezeNewConductors(bool); DiagramContent selectedContent();
bool freezeNewConductors(); bool canRotateSelection() const;
int beginMoveElements(QGraphicsItem * = 0);
//methods related to insertion and loading of folio sequential void continueMoveElements(const QPointF &);
void insertFolioSeqHash (QHash<QString, QStringList> *hash, QString title, QString seq, NumerotationContext *nc); void endMoveElements();
void loadFolioSeqHash (QHash<QString, QStringList> *hash, QString title, QString seq, NumerotationContext *nc); int beginMoveElementTexts(QGraphicsItem * = 0);
void continueMoveElementTexts(const QPointF &);
void endMoveElementTexts();
bool usesElement(const ElementsLocation &);
bool usesTitleBlockTemplate(const QString &);
QUndoStack &undoStack();
QGIManager &qgiManager();
//methods related to element label Update Policy
void freezeElements(bool freeze);
void unfreezeElements();
void setFreezeNewElements(bool);
bool freezeNewElements();
//methods related to conductor label Update Policy
void freezeConductors(bool freeze);
void setFreezeNewConductors(bool);
bool freezeNewConductors();
//methods related to insertion and loading of folio sequential
void insertFolioSeqHash (QHash<QString, QStringList> *hash, QString title, QString seq, NumerotationContext *nc);
void loadFolioSeqHash (QHash<QString, QStringList> *hash, QString title, QString seq, NumerotationContext *nc);
public slots: public slots:
@@ -243,7 +239,7 @@ class Diagram : public QGraphicsScene
void loadElmtFolioSeq(); void loadElmtFolioSeq();
void loadCndFolioSeq(); void loadCndFolioSeq();
// methods related to graphics items selection // methods related to graphics items selection
void selectAll(); void selectAll();
void deselectAll(); void deselectAll();
void invertSelection(); void invertSelection();
@@ -255,7 +251,6 @@ class Diagram : public QGraphicsScene
void diagramTitleChanged(Diagram *, const QString &); void diagramTitleChanged(Diagram *, const QString &);
void findElementRequired(const ElementsLocation &); /// Signal emitted when users wish to locate an element from the diagram within elements collection void findElementRequired(const ElementsLocation &); /// Signal emitted when users wish to locate an element from the diagram within elements collection
void editElementRequired(const ElementsLocation &); /// Signal emitted when users wish to edit an element from the diagram void editElementRequired(const ElementsLocation &); /// Signal emitted when users wish to edit an element from the diagram
void XRefPropertiesChanged();
void diagramActivated(); void diagramActivated();
}; };
Q_DECLARE_METATYPE(Diagram *) Q_DECLARE_METATYPE(Diagram *)

View File

@@ -54,11 +54,13 @@ QRectF CommentItem::boundingRect() const {
* @brief CommentItem::autoPos * @brief CommentItem::autoPos
* Adjust the position of this item. * Adjust the position of this item.
*/ */
void CommentItem::autoPos() { void CommentItem::autoPos()
{
if (m_text_parent) if (m_text_parent)
centerToParentBottom(this); centerToParentBottom(this);
else { else
XRefProperties xrp = m_element->diagram()->defaultXRefProperties(m_element->kindInformations()["type"].toString()); {
XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
centerToBottomDiagram(this, m_element, xrp.offset()); centerToBottomDiagram(this, m_element, xrp.offset());
} }
} }

View File

@@ -45,15 +45,17 @@ CrossRefItem::CrossRefItem(Element *elmt) :
{ {
Q_ASSERT_X(elmt->diagram(), "CrossRefItem constructor", "Parent element is not in a diagram"); Q_ASSERT_X(elmt->diagram(), "CrossRefItem constructor", "Parent element is not in a diagram");
m_properties = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString()); m_properties = elmt->diagram()->project()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
connect(elmt -> diagram() -> project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); QETProject *project = elmt->diagram()->project();
connect(elmt -> diagram() -> project(), SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel())); connect(project, &QETProject::projectDiagramsOrderChanged, this, &CrossRefItem::updateLabel);
connect(elmt -> diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateProperties())); connect(project, &QETProject::diagramRemoved, this, &CrossRefItem::updateLabel);
connect(project, &QETProject::XRefPropertiesChanged, this, &CrossRefItem::updateProperties);
//set specific behavior related to the parent item. //set specific behavior related to the parent item.
if(m_properties.snapTo() == XRefProperties::Bottom) { if(m_properties.snapTo() == XRefProperties::Bottom)
{
connect(elmt, SIGNAL(yChanged()), this, SLOT(autoPos())); connect(elmt, SIGNAL(yChanged()), this, SLOT(autoPos()));
connect(elmt, SIGNAL(rotationChanged()), this, SLOT(autoPos())); connect(elmt, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
} else { } else {
@@ -92,7 +94,7 @@ QPainterPath CrossRefItem::shape() const{
*/ */
QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_prefix) const QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_prefix) const
{ {
XRefProperties xrp = m_element->diagram()->defaultXRefProperties(m_element->kindInformations()["type"].toString()); XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
QString formula = xrp.masterLabel(); QString formula = xrp.masterLabel();
autonum::sequentialNumbers seq; autonum::sequentialNumbers seq;
QString txt = autonum::AssignVariables::formulaToLabel(formula, seq, elmt->diagram(), elmt); QString txt = autonum::AssignVariables::formulaToLabel(formula, seq, elmt->diagram(), elmt);
@@ -110,16 +112,22 @@ QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_p
* @brief CrossRefItem::updateProperties * @brief CrossRefItem::updateProperties
* update the curent properties * update the curent properties
*/ */
void CrossRefItem::updateProperties() { void CrossRefItem::updateProperties()
XRefProperties xrp = m_element->diagram()->defaultXRefProperties(m_element->kindInformations()["type"].toString()); {
XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
if (m_properties != xrp) { if (m_properties != xrp)
if (m_properties.snapTo() != xrp.snapTo()) { {
if (xrp.snapTo() == XRefProperties::Bottom) { if (m_properties.snapTo() != xrp.snapTo())
{
if (xrp.snapTo() == XRefProperties::Bottom)
{
setParentItem(m_element); setParentItem(m_element);
connect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos())); connect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos()));
connect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos())); connect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
} else { }
else
{
setTextParent(); setTextParent();
disconnect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos())); disconnect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos()));
disconnect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos())); disconnect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));

View File

@@ -877,7 +877,10 @@ void Element::setUpConnectionForFormula(QString old_formula, QString new_formula
//Because the variable %F is a reference to another text which can contain variables, //Because the variable %F is a reference to another text which can contain variables,
//we must to replace %F by the real text, to check if the real text contain the variable %id //we must to replace %F by the real text, to check if the real text contain the variable %id
if (diagram() && old_formula.contains("%F")) if (diagram() && old_formula.contains("%F"))
old_formula.replace("%F", diagram()->border_and_titleblock.folio()); {
disconnect(&diagram()->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &Element::updateLabel);
old_formula.replace("%F", m_F_str);
}
if (diagram() && (old_formula.contains("%f") || old_formula.contains("%id"))) if (diagram() && (old_formula.contains("%f") || old_formula.contains("%id")))
disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &Element::updateLabel); disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &Element::updateLabel);
@@ -891,7 +894,11 @@ void Element::setUpConnectionForFormula(QString old_formula, QString new_formula
return; return;
if (diagram() && new_formula.contains("%F")) if (diagram() && new_formula.contains("%F"))
new_formula.replace("%F", diagram()->border_and_titleblock.folio()); {
m_F_str = diagram()->border_and_titleblock.folio();
new_formula.replace("%F", m_F_str);
connect(&diagram()->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &Element::updateLabel);
}
if (diagram() && (new_formula.contains("%f") || new_formula.contains("%id"))) if (diagram() && (new_formula.contains("%f") || new_formula.contains("%id")))
connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &Element::updateLabel); connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &Element::updateLabel);

View File

@@ -149,13 +149,14 @@ class Element : public QetGraphicsItem
void freezeNewAddedElement(); void freezeNewAddedElement();
protected: protected:
void setUpConnectionForFormula(QString old_formula, QString new_formula); virtual void setUpConnectionForFormula(QString old_formula, QString new_formula);
//ATTRIBUTES //ATTRIBUTES
protected: protected:
DiagramContext m_element_informations, kind_informations_; DiagramContext m_element_informations, kind_informations_;
autonum::sequentialNumbers m_autoNum_seq; autonum::sequentialNumbers m_autoNum_seq;
bool m_freeze_label = false; bool m_freeze_label = false;
QString m_F_str;
/** /**
Draw this element Draw this element

View File

@@ -65,6 +65,7 @@ void MasterElement::linkToElement(Element *elmt)
connect(elmt, SIGNAL(xChanged()), m_Xref_item, SLOT(updateLabel())); connect(elmt, SIGNAL(xChanged()), m_Xref_item, SLOT(updateLabel()));
connect(elmt, SIGNAL(yChanged()), m_Xref_item, SLOT(updateLabel())); connect(elmt, SIGNAL(yChanged()), m_Xref_item, SLOT(updateLabel()));
connect(elmt, SIGNAL(updateLabel()), m_Xref_item, SLOT(updateLabel())); connect(elmt, SIGNAL(updateLabel()), m_Xref_item, SLOT(updateLabel()));
connect(&elmt->diagram()->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, m_Xref_item, &CrossRefItem::updateLabel);
m_Xref_item -> updateLabel(); m_Xref_item -> updateLabel();
emit linkedElementChanged(); emit linkedElementChanged();
} }
@@ -103,6 +104,7 @@ void MasterElement::unlinkElement(Element *elmt)
disconnect(elmt, SIGNAL(xChanged()), m_Xref_item, SLOT(updateLabel())); disconnect(elmt, SIGNAL(xChanged()), m_Xref_item, SLOT(updateLabel()));
disconnect(elmt, SIGNAL(yChanged()), m_Xref_item, SLOT(updateLabel())); disconnect(elmt, SIGNAL(yChanged()), m_Xref_item, SLOT(updateLabel()));
disconnect(elmt, SIGNAL(updateLabel()), m_Xref_item, SLOT(updateLabel())); disconnect(elmt, SIGNAL(updateLabel()), m_Xref_item, SLOT(updateLabel()));
disconnect(&elmt->diagram()->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, m_Xref_item, &CrossRefItem::updateLabel);
m_Xref_item -> updateLabel(); m_Xref_item -> updateLabel();
aboutDeleteXref(); aboutDeleteXref();

View File

@@ -88,25 +88,22 @@ void ReportElement::linkToElement(Element * elmt)
{ {
unlinkAllElements(); unlinkAllElements();
connected_elements << elmt; connected_elements << elmt;
m_formula = diagram()->project()->defaultReportProperties();
connect(elmt, SIGNAL( xChanged() ), this, SLOT( updateLabel() )); setConnectionForFormula(m_formula);
connect(elmt, SIGNAL( yChanged() ), this, SLOT( updateLabel() ));
connect(diagram()->project(), &QETProject::reportPropertiesChanged, this, &ReportElement::reportPropertiesChange); connect(diagram()->project(), &QETProject::reportPropertiesChanged, this, &ReportElement::reportPropertiesChange);
connect(diagram() -> project(), SIGNAL( projectDiagramsOrderChanged(QETProject*,int,int) ), this, SLOT( updateLabel() ));
if (elmt->terminals().size()) if (elmt->terminals().size())
{ {
connect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded); connect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
connect(elmt->terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved); connect(elmt->terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
} }
m_label = diagram() -> defaultReportProperties();
if (!m_watched_conductor && elmt->conductors().size()) if (!m_watched_conductor && elmt->conductors().size())
conductorWasAdded(elmt->conductors().first()); conductorWasAdded(elmt->conductors().first());
else else
updateLabel(); updateLabel();
elmt -> linkToElement(this); elmt->linkToElement(this);
emit linkedElementChanged(); emit linkedElementChanged();
} }
@@ -118,16 +115,16 @@ void ReportElement::linkToElement(Element * elmt)
*/ */
void ReportElement::unlinkAllElements() void ReportElement::unlinkAllElements()
{ {
if (isFree()) return; if (isFree())
return;
QList <Element *> tmp_elmt = connected_elements; const QList <Element *> tmp_elmt = connected_elements;
foreach(Element *elmt, connected_elements) for (Element *elmt : tmp_elmt)
{ {
disconnect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel())); removeConnectionForFormula(m_formula);
disconnect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel()));
disconnect(diagram()->project(), &QETProject::reportPropertiesChanged, this, &ReportElement::reportPropertiesChange); disconnect(diagram()->project(), &QETProject::reportPropertiesChanged, this, &ReportElement::reportPropertiesChange);
disconnect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
if (elmt->terminals().size()) if (elmt->terminals().size())
{ {
disconnect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded); disconnect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
@@ -140,11 +137,12 @@ void ReportElement::unlinkAllElements()
} }
updateLabel(); updateLabel();
foreach(Element *elmt, tmp_elmt) for(Element *elmt : tmp_elmt)
{ {
elmt -> setHighlighted(false); elmt -> setHighlighted(false);
elmt -> unlinkAllElements(); elmt -> unlinkAllElements();
} }
emit linkedElementChanged(); emit linkedElementChanged();
} }
/** /**
@@ -198,12 +196,15 @@ void ReportElement::conductorWasRemoved(Conductor *conductor)
} }
/** /**
* @brief ReportElement::setLabel * @brief ReportElement::setFormula
* Set new label and call updatelabel * Set new Formula and call updatelabel
* @param label new label * @param formula : the new formula
*/ */
void ReportElement::setLabel(QString label) { void ReportElement::setFormula(QString formula)
m_label = label; {
removeConnectionForFormula(m_formula);
m_formula = formula;
setConnectionForFormula(m_formula);
updateLabel(); updateLabel();
} }
@@ -219,7 +220,7 @@ void ReportElement::updateLabel()
if (!connected_elements.isEmpty()) if (!connected_elements.isEmpty())
{ {
Element *elmt = connected_elements.at(0); Element *elmt = connected_elements.at(0);
QString label = m_label; QString label = m_formula;
label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt); label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
m_text_field -> setPlainText(label); m_text_field -> setPlainText(label);
} }
@@ -233,5 +234,73 @@ void ReportElement::updateLabel()
void ReportElement::reportPropertiesChange(const QString &old_str, const QString &new_str) void ReportElement::reportPropertiesChange(const QString &old_str, const QString &new_str)
{ {
Q_UNUSED(old_str); Q_UNUSED(old_str);
setLabel(new_str); setFormula(new_str);
}
/**
* @brief ReportElement::setConnectionForFormula
* Set up the required connection for the formula @str.
* @param str
*/
void ReportElement::setConnectionForFormula(const QString &str)
{
if (connected_elements.isEmpty() || str.isEmpty())
return;
QString string = str;
Element *other_elmt = connected_elements.first();
Diagram *other_diagram = other_elmt->diagram();
//Because the variable %F is a reference to another text which can contain variables,
//we must to replace %F by the real text, to check if the real text contain the variable %id
if (other_diagram && string.contains("%F"))
{
m_F_str = other_diagram->border_and_titleblock.folio();
string.replace("%F", m_F_str);
connect(&other_diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &ReportElement::updateFormulaConnection);
}
if (other_diagram && (string.contains("%f") || string.contains("%id")))
connect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &ReportElement::updateLabel);
if (string.contains("%l"))
connect(other_elmt, &Element::yChanged, this, &ReportElement::updateLabel);
if (string.contains("%c"))
connect(other_elmt, &Element::xChanged, this, &ReportElement::updateLabel);
}
/**
* @brief ReportElement::removeConnectionForFormula
* Remove the existing connection made for the formula @str
* @param str
*/
void ReportElement::removeConnectionForFormula(const QString &str)
{
if (connected_elements.isEmpty() || str.isEmpty())
return;
QString string = str;
Element *other_element = connected_elements.first();
Diagram *other_diagram = other_element->diagram();
//Because the variable %F is a reference to another text which can contain variables,
//we must to replace %F by the real text, to check if the real text contain the variable %id
if (other_diagram && string.contains("%F"))
{
string.replace("%F", m_F_str);
disconnect(&other_diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &ReportElement::updateFormulaConnection);
}
if (other_diagram && (string.contains("%f") || string.contains("%id")))
disconnect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &ReportElement::updateLabel);
if (string.contains("%l"))
disconnect(other_element, &Element::yChanged, this, &ReportElement::updateLabel);
if (string.contains("%c"))
disconnect(other_element, &Element::xChanged, this, &ReportElement::updateLabel);
}
void ReportElement::updateFormulaConnection()
{
removeConnectionForFormula(m_formula);
setConnectionForFormula(m_formula);
updateLabel();
} }

View File

@@ -37,21 +37,22 @@ class ReportElement : public CustomElement
virtual void linkToElement(Element *); virtual void linkToElement(Element *);
virtual void unlinkAllElements(); virtual void unlinkAllElements();
virtual void unlinkElement(Element *elmt); virtual void unlinkElement(Element *elmt);
private:
int m_inverse_report;
QString m_label;
ElementTextItem *m_text_field;
Conductor *m_watched_conductor;
private: private:
void conductorWasAdded(Conductor *conductor); void conductorWasAdded(Conductor *conductor);
void conductorWasRemoved(Conductor *conductor); void conductorWasRemoved(Conductor *conductor);
void setFormula (QString label);
private slots:
void setLabel (QString label);
void updateLabel(); void updateLabel();
void reportPropertiesChange(const QString &old_str, const QString &new_str); void reportPropertiesChange(const QString &old_str, const QString &new_str);
void setConnectionForFormula(const QString &str);
void removeConnectionForFormula(const QString &str);
void updateFormulaConnection();
private:
int m_inverse_report;
QString m_formula;
ElementTextItem *m_text_field;
Conductor *m_watched_conductor;
}; };
#endif // REPORTELEMENT_H #endif // REPORTELEMENT_H

View File

@@ -60,13 +60,14 @@ void SlaveElement::linkToElement(Element *elmt)
this->disconnect(); this->disconnect();
connected_elements << elmt; connected_elements << elmt;
connect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel())); QETProject *project = elmt->diagram()->project();
connect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel())); connect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel()));
connect(elmt, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)),this, SLOT(updateLabel())); connect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel()));
connect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); connect(elmt, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel()));
connect(diagram()->project(), SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel())); connect(project, SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
connect(elmt -> diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateLabel())); connect(project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel()));
connect(elmt, SIGNAL(updateLabel()), this, SLOT(updateLabel())); connect(project, SIGNAL(XRefPropertiesChanged()), this, SLOT(updateLabel()));
connect(elmt, SIGNAL(updateLabel()), this, SLOT(updateLabel()));
updateLabel(); updateLabel();
elmt -> linkToElement(this); elmt -> linkToElement(this);
@@ -141,11 +142,11 @@ void SlaveElement::updateLabel()
{ {
no_editable = true; no_editable = true;
Element *elmt = linkedElements().first(); Element *elmt = linkedElements().first();
label = elmt -> elementInformations()["label"].toString(); label = elmt->elementInformations()["label"].toString();
XRefProperties xrp = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
XRefProperties xrp = elmt->diagram()->project()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
Xreflabel = xrp.slaveLabel(); Xreflabel = xrp.slaveLabel();
Xreflabel = autonum::AssignVariables::formulaToLabel(Xreflabel, elmt->rSequenceStruct(), elmt->diagram(), elmt); Xreflabel = autonum::AssignVariables::formulaToLabel(Xreflabel, elmt->rSequenceStruct(), elmt->diagram(), elmt);
label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
} }
else else
label = autonum::AssignVariables::formulaToLabel(label, m_autoNum_seq, diagram(), this); label = autonum::AssignVariables::formulaToLabel(label, m_autoNum_seq, diagram(), this);