Bug fix : Conductor text with formula that contain %id isn't good when open project (variable %id is replaced by 0 in each folio)

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4746 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-10-17 14:26:13 +00:00
parent ccf7e1dbde
commit 6ea169e1f7
6 changed files with 64 additions and 41 deletions

View File

@@ -983,9 +983,19 @@ QDomElement Diagram::writeXml(QDomDocument &xml_doc) const {
return(new_node.toElement()); return(new_node.toElement());
} }
void Diagram::initElementsLinks() { /**
* @brief Diagram::refreshContents
* refresh all content of diagram.
* - refresh conductor text.
* - linking the elements waiting to be linked
*/
void Diagram::refreshContents() {
foreach (Element *elmt, elements()) foreach (Element *elmt, elements())
elmt->initLink(project()); elmt->initLink(project());
foreach (Conductor *conductor, conductors())
conductor->refreshText();
} }
/** /**
@@ -1506,7 +1516,7 @@ bool Diagram::freezeNewElements() {
*/ */
void Diagram::freezeConductors() { void Diagram::freezeConductors() {
foreach (Conductor *cnd, conductors()) { foreach (Conductor *cnd, conductors()) {
cnd->freezeLabel(); cnd->setFreezeLabel(true);
} }
} }
@@ -1516,7 +1526,7 @@ void Diagram::freezeConductors() {
*/ */
void Diagram::unfreezeConductors() { void Diagram::unfreezeConductors() {
foreach (Conductor *cnd, conductors()) { foreach (Conductor *cnd, conductors()) {
cnd->unfreezeLabel(); cnd->setFreezeLabel(false);
} }
} }

View File

@@ -166,8 +166,9 @@ class Diagram : public QGraphicsScene
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);
// methods related to graphics items addition/removal on the diagram void refreshContents();
void initElementsLinks();
// methods related to graphics items addition/removal on the diagram
virtual void addItem (QGraphicsItem *item); virtual void addItem (QGraphicsItem *item);
virtual void removeItem (QGraphicsItem *item); virtual void removeItem (QGraphicsItem *item);

View File

@@ -217,7 +217,8 @@ void DiagramEventAddElement::addElement()
element -> setRotation(m_element -> rotation()); element -> setRotation(m_element -> rotation());
m_diagram -> addItem(element); m_diagram -> addItem(element);
QUndoCommand *undo_object = new AddItemCommand<Element *>(element, m_diagram, m_element -> pos()); QUndoCommand *undo_object = new QUndoCommand(tr("Ajouter %1").arg(element->name()));
new AddItemCommand<Element *>(element, m_diagram, m_element -> pos(), undo_object);
while (!element -> AlignedFreeTerminals().isEmpty() && m_diagram -> project() -> autoConductor()) while (!element -> AlignedFreeTerminals().isEmpty() && m_diagram -> project() -> autoConductor())
{ {
@@ -232,8 +233,9 @@ void DiagramEventAddElement::addElement()
ConductorAutoNumerotation can (conductor, m_diagram, undo_object); ConductorAutoNumerotation can (conductor, m_diagram, undo_object);
can.numerate(); can.numerate();
conductor->setSeq = true; conductor->setSeq = true;
if (m_diagram->freezeNewConductors() || m_diagram->project()->freezeNewConductors() ) if (m_diagram->freezeNewConductors() || m_diagram->project()->freezeNewConductors()) {
conductor->freeze_label = true; conductor->setFreezeLabel(true);
}
}; };
m_diagram -> undoStack().push(undo_object); m_diagram -> undoStack().push(undo_object);
element->setSequential(); element->setSequential();

View File

@@ -48,7 +48,6 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
terminal1(p1), terminal1(p1),
terminal2(p2), terminal2(p2),
setSeq(true), setSeq(true),
freeze_label(false),
bMouseOver(false), bMouseOver(false),
m_handler(10), m_handler(10),
text_item(0), text_item(0),
@@ -1446,6 +1445,15 @@ void Conductor::setText(const QString &t) {
text_item -> setPlainText(label); text_item -> setPlainText(label);
} }
/**
* @brief Conductor::refreshText
* Refresh the text of this conductor.
* recalcule and set the text according to the formula.
*/
void Conductor::refreshText() {
setText(m_freeze_label? text_item->toPlainText() : properties().text);
}
/** /**
* @brief Conductor::setProperties * @brief Conductor::setProperties
* Set new properties for this conductor * Set new properties for this conductor
@@ -1478,8 +1486,8 @@ void Conductor::setProperties(const ConductorProperties &properties)
else else
m_frozen_label = properties_.text; m_frozen_label = properties_.text;
} }
if (freeze_label)
freezeLabel(); setFreezeLabel(m_freeze_label);
if (properties_.type != ConductorProperties::Multi) if (properties_.type != ConductorProperties::Multi)
text_item -> setVisible(false); text_item -> setVisible(false);
else else
@@ -1883,22 +1891,23 @@ QList <Conductor *> relatedConductors(const Conductor *conductor) {
} }
/** /**
* @brief Conductor::freezeLabel * @brief Conductor::setFreezeLabel
* Freeze this conductor label * Freeze this conductor label if true
* Unfreeze this conductor label if false
* @param freeze
*/ */
void Conductor::freezeLabel() { void Conductor::setFreezeLabel(bool freeze) {
QString freezelabel = this->text_item->toPlainText(); m_freeze_label = freeze;
m_frozen_label = properties_.text;
this->setText(freezelabel);
this->properties_.text = freezelabel;
}
/** if (m_freeze_label) {
* @brief Conductor::unfreezeLabel QString freezelabel = this->text_item->toPlainText();
* Unfreeze this conductor label m_frozen_label = properties_.text;
*/ this->setText(freezelabel);
void Conductor::unfreezeLabel() { this->properties_.text = freezelabel;
this->setText(m_frozen_label); }
if (m_frozen_label == "") return; else {
properties_.text = m_frozen_label; this->setText(m_frozen_label);
if (m_frozen_label == "") return;
properties_.text = m_frozen_label;
}
} }

View File

@@ -95,6 +95,7 @@ class Conductor : public QObject, public QGraphicsPathItem
QString text() const; QString text() const;
QString assignVariables(QString) ; QString assignVariables(QString) ;
void setText(const QString &); void setText(const QString &);
void refreshText();
QString assignSeq (QString, Conductor*); QString assignSeq (QString, Conductor*);
void setSequential (); void setSequential ();
void setOthersSequential (Conductor *); void setOthersSequential (Conductor *);
@@ -131,9 +132,7 @@ class Conductor : public QObject, public QGraphicsPathItem
QStringList seq_hundred; QStringList seq_hundred;
QStringList seq_hundredfolio; QStringList seq_hundredfolio;
bool setSeq; bool setSeq;
bool freeze_label; void setFreezeLabel(bool freeze);
void freezeLabel();
void unfreezeLabel();
QString m_frozen_label; QString m_frozen_label;
public slots: public slots:
@@ -153,32 +152,33 @@ class Conductor : public QObject, public QGraphicsPathItem
private: private:
QetGraphicsHandlerUtility m_handler; QetGraphicsHandlerUtility m_handler;
/// Functional properties /// Functional properties
ConductorProperties properties_; ConductorProperties properties_;
/// Text input for non simple, non-singleline conductors /// Text input for non simple, non-singleline conductors
ConductorTextItem *text_item; ConductorTextItem *text_item;
/// Segments composing the conductor /// Segments composing the conductor
ConductorSegment *segments; ConductorSegment *segments;
/// Attributs related to mouse interaction /// Attributs related to mouse interaction
bool moving_segment; bool moving_segment;
int moved_point; int moved_point;
qreal previous_z_value; qreal previous_z_value;
ConductorSegment *moved_segment; ConductorSegment *moved_segment;
QPointF before_mov_text_pos_; QPointF before_mov_text_pos_;
/// Whether the conductor was manually modified by users /// Whether the conductor was manually modified by users
bool modified_path; bool modified_path;
/// Whether the current profile should be saved as soon as possible /// Whether the current profile should be saved as soon as possible
bool has_to_save_profile; bool has_to_save_profile;
/// conductor profile: "photography" of what the conductor is supposed to look /// conductor profile: "photography" of what the conductor is supposed to look
/// like - there is one profile per kind of traject /// like - there is one profile per kind of traject
ConductorProfilesGroup conductor_profiles; ConductorProfilesGroup conductor_profiles;
/// QPen et QBrush objects used to draw conductors /// QPen et QBrush objects used to draw conductors
static QPen conductor_pen; static QPen conductor_pen;
static QBrush conductor_brush; static QBrush conductor_brush;
static bool pen_and_brush_initialized; static bool pen_and_brush_initialized;
/// Define whether and how the conductor should be highlighted /// Define whether and how the conductor should be highlighted
Highlight must_highlight_; Highlight must_highlight_;
bool m_valid; bool m_valid;
bool m_freeze_label = false;
private: private:
void segmentsToPath(); void segmentsToPath();

View File

@@ -1367,8 +1367,9 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
addDiagram(diagram); addDiagram(diagram);
//Initialise links between elements in this project //Initialise links between elements in this project
//and refresh the text of conductor
foreach (Diagram *d, diagrams()) foreach (Diagram *d, diagrams())
d->initElementsLinks(); d->refreshContents();
delete dlgWaiting; delete dlgWaiting;
} }