revert and merge rev 4823.

Fix : in old projects without the conductors formula, the conductors texts aren't loaded and displayed
Fix it in method void Conductor::refreshText()


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4825 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-12-28 10:03:47 +00:00
parent 52f911887d
commit 14f02d4ed1
10 changed files with 189 additions and 95 deletions

View File

@@ -27,13 +27,24 @@
namespace autonum namespace autonum
{ {
/** /**
* @brief sequentialNumbers::sequentialNumbers * @brief sequentialNumbers::sequentialNumbers
*/ */
sequentialNumbers::sequentialNumbers() sequentialNumbers::sequentialNumbers()
{} {}
sequentialNumbers::sequentialNumbers(const sequentialNumbers &other)
{
unit = other.unit;
unit_folio = other.unit_folio;
ten = other.ten;
ten_folio = other.ten_folio;
hundred = other.hundred;
hundred_folio = other.hundred_folio;
}
sequentialNumbers::~sequentialNumbers() {}
sequentialNumbers &sequentialNumbers::operator=(const sequentialNumbers &other) sequentialNumbers &sequentialNumbers::operator=(const sequentialNumbers &other)
{ {
if (&other == this || other == *this) if (&other == this || other == *this)
@@ -216,22 +227,22 @@ namespace autonum
for (int i=1; i<=max ; i++) for (int i=1; i<=max ; i++)
{ {
if (m_assigned_label.contains("%sequ_" + QString::number(i)) && !m_seq_struct.unit.isEmpty()) { if (m_assigned_label.contains("%sequ_" + QString::number(i)) && m_seq_struct.unit.size() >= i) {
m_assigned_label.replace("%sequ_" + QString::number(i),m_seq_struct.unit.at(i-1)); m_assigned_label.replace("%sequ_" + QString::number(i),m_seq_struct.unit.at(i-1));
} }
if (m_assigned_label.contains("%seqt_" + QString::number(i)) && !m_seq_struct.ten.isEmpty()) { if (m_assigned_label.contains("%seqt_" + QString::number(i)) && m_seq_struct.ten.size() >= i) {
m_assigned_label.replace("%seqt_" + QString::number(i),m_seq_struct.ten.at(i-1)); m_assigned_label.replace("%seqt_" + QString::number(i),m_seq_struct.ten.at(i-1));
} }
if (m_assigned_label.contains("%seqh_" + QString::number(i)) && !m_seq_struct.hundred.isEmpty()) { if (m_assigned_label.contains("%seqh_" + QString::number(i)) && m_seq_struct.hundred.size() >= i) {
m_assigned_label.replace("%seqh_" + QString::number(i),m_seq_struct.hundred.at(i-1)); m_assigned_label.replace("%seqh_" + QString::number(i),m_seq_struct.hundred.at(i-1));
} }
if (m_assigned_label.contains("%sequf_" + QString::number(i)) && !m_seq_struct.unit_folio.isEmpty()) { if (m_assigned_label.contains("%sequf_" + QString::number(i)) && m_seq_struct.unit_folio.size() >= i) {
m_assigned_label.replace("%sequf_" + QString::number(i),m_seq_struct.unit_folio.at(i-1)); m_assigned_label.replace("%sequf_" + QString::number(i),m_seq_struct.unit_folio.at(i-1));
} }
if (m_assigned_label.contains("%seqtf_" + QString::number(i)) && !m_seq_struct.ten_folio.isEmpty()) { if (m_assigned_label.contains("%seqtf_" + QString::number(i)) && m_seq_struct.ten_folio.size() >= i) {
m_assigned_label.replace("%seqtf_" + QString::number(i),m_seq_struct.ten_folio.at(i-1)); m_assigned_label.replace("%seqtf_" + QString::number(i),m_seq_struct.ten_folio.at(i-1));
} }
if (m_assigned_label.contains("%seqhf_" + QString::number(i)) && !m_seq_struct.hundred_folio.isEmpty()) { if (m_assigned_label.contains("%seqhf_" + QString::number(i)) && m_seq_struct.hundred_folio.size() >= i) {
m_assigned_label.replace("%seqhf_" + QString::number(i),m_seq_struct.hundred_folio.at(i-1)); m_assigned_label.replace("%seqhf_" + QString::number(i),m_seq_struct.hundred_folio.at(i-1));
} }
} }

View File

@@ -34,6 +34,8 @@ namespace autonum
{ {
public: public:
sequentialNumbers(); sequentialNumbers();
sequentialNumbers(const sequentialNumbers &other);
~sequentialNumbers();
sequentialNumbers &operator= (const sequentialNumbers &other); sequentialNumbers &operator= (const sequentialNumbers &other);
bool operator== (const sequentialNumbers &other) const; bool operator== (const sequentialNumbers &other) const;
@@ -80,4 +82,6 @@ namespace autonum
QString elementPrefixForLocation(const ElementsLocation &location); QString elementPrefixForLocation(const ElementsLocation &location);
} }
Q_DECLARE_METATYPE(autonum::sequentialNumbers)
#endif // ASSIGNVARIABLES_H #endif // ASSIGNVARIABLES_H

View File

@@ -121,9 +121,8 @@ void ConductorAutoNumerotation::numeratePotential()
ConductorProperties cp = m_conductor -> properties(); ConductorProperties cp = m_conductor -> properties();
cp.text = text_list.first(); cp.text = text_list.first();
cp.m_formula = formula_list.first(); cp.m_formula = formula_list.first();
m_conductor->setProperties(cp);
m_conductor->rSequenceNum() = conductor_list.first()->sequenceNum(); m_conductor->rSequenceNum() = conductor_list.first()->sequenceNum();
m_conductor->setText(text_list.first()); m_conductor->setProperties(cp);
} }
//the texts isn't identicals //the texts isn't identicals
else else

View File

@@ -1158,8 +1158,7 @@ void Diagram::updateLabels() {
elmt->updateLabel(); elmt->updateLabel();
} }
foreach (Conductor *cnd, content().conductors()) { foreach (Conductor *cnd, content().conductors()) {
if (cnd->properties().text.contains("%F")) cnd->refreshText();
cnd->setText(cnd->properties().text);
} }
} }

View File

@@ -79,7 +79,7 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
terminal2(p2), terminal2(p2),
m_mouse_over(false), m_mouse_over(false),
m_handler(10), m_handler(10),
text_item(0), m_text_item(0),
segments(NULL), segments(NULL),
moving_segment(false), moving_segment(false),
modified_path(false), modified_path(false),
@@ -127,8 +127,8 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
// Add the text field // Add the text field
text_item = new ConductorTextItem(m_properties.text, this); m_text_item = new ConductorTextItem(m_properties.text, this);
connect(text_item, &ConductorTextItem::diagramTextChanged, this, &Conductor::displayedTextChanged); connect(m_text_item, &ConductorTextItem::diagramTextChanged, this, &Conductor::displayedTextChanged);
} }
/** /**
@@ -543,7 +543,7 @@ Diagram *Conductor::diagram() const {
@return le champ de texte associe a ce conducteur @return le champ de texte associe a ce conducteur
*/ */
ConductorTextItem *Conductor::textItem() const { ConductorTextItem *Conductor::textItem() const {
return(text_item); return(m_text_item);
} }
/** /**
@@ -597,7 +597,7 @@ void Conductor::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
moving_segment = true; moving_segment = true;
moved_segment = segmentsList().at(index+1); moved_segment = segmentsList().at(index+1);
before_mov_text_pos_ = text_item -> pos(); before_mov_text_pos_ = m_text_item -> pos();
} }
} }
@@ -855,7 +855,7 @@ bool Conductor::fromXml(QDomElement &dom_element)
bool return_ = pathFromXml(dom_element); bool return_ = pathFromXml(dom_element);
text_item -> fromXml(dom_element); m_text_item -> fromXml(dom_element);
ConductorProperties pr; ConductorProperties pr;
pr.fromXml(dom_element); pr.fromXml(dom_element);
@@ -909,7 +909,7 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
// Export the properties and text // Export the properties and text
m_properties. toXml(dom_element); m_properties. toXml(dom_element);
text_item -> toXml(dom_element); m_text_item -> toXml(dom_element);
return(dom_element); return(dom_element);
} }
@@ -1130,7 +1130,7 @@ QPointF Conductor::posForText(Qt::Orientations &flag) {
* If text was moved by user, this function do nothing, except check if text is near conductor. * If text was moved by user, this function do nothing, except check if text is near conductor.
*/ */
void Conductor::calculateTextItemPosition() { void Conductor::calculateTextItemPosition() {
if (!text_item || !diagram() || m_properties.type != ConductorProperties::Multi) return; if (!m_text_item || !diagram() || m_properties.type != ConductorProperties::Multi) return;
if (diagram() -> defaultConductorProperties.m_one_text_per_folio == true && if (diagram() -> defaultConductorProperties.m_one_text_per_folio == true &&
relatedPotentialConductors(false).size() > 0) { relatedPotentialConductors(false).size() > 0) {
@@ -1149,37 +1149,37 @@ void Conductor::calculateTextItemPosition() {
c -> textItem() -> setVisible(false); c -> textItem() -> setVisible(false);
} }
//Make sure text item is visible //Make sure text item is visible
text_item -> setVisible(true); m_text_item -> setVisible(true);
} }
//position //position
if (text_item -> wasMovedByUser()) { if (m_text_item -> wasMovedByUser()) {
//Text field was moved by user : //Text field was moved by user :
//we check if text field is yet near the conductor //we check if text field is yet near the conductor
QPointF text_item_pos = text_item -> pos(); QPointF text_item_pos = m_text_item -> pos();
QPainterPath near_shape = nearShape(); QPainterPath near_shape = nearShape();
if (!near_shape.contains(text_item_pos)) { if (!near_shape.contains(text_item_pos)) {
text_item -> setPos(movePointIntoPolygon(text_item_pos, near_shape)); m_text_item -> setPos(movePointIntoPolygon(text_item_pos, near_shape));
} }
} else { } else {
//Position and rotation of text is calculated. //Position and rotation of text is calculated.
Qt::Orientations rotation; Qt::Orientations rotation;
QPointF text_pos = posForText(rotation); QPointF text_pos = posForText(rotation);
if (!text_item -> wasRotateByUser()) { if (!m_text_item -> wasRotateByUser()) {
rotation == Qt::Vertical ? text_item -> setRotationAngle(m_properties.verti_rotate_text): rotation == Qt::Vertical ? m_text_item -> setRotationAngle(m_properties.verti_rotate_text):
text_item -> setRotationAngle(m_properties.horiz_rotate_text); m_text_item -> setRotationAngle(m_properties.horiz_rotate_text);
} }
//Adjust the position of text if his rotation //Adjust the position of text if his rotation
//is 0° or 270°, to be exactly centered to the conductor //is 0° or 270°, to be exactly centered to the conductor
if (text_item -> rotation() == 0) if (m_text_item -> rotation() == 0)
text_pos.rx() -= text_item -> boundingRect().width()/2; text_pos.rx() -= m_text_item -> boundingRect().width()/2;
else if (text_item -> rotation() == 270) else if (m_text_item -> rotation() == 270)
text_pos.ry() += text_item -> boundingRect().width()/2; text_pos.ry() += m_text_item -> boundingRect().width()/2;
//Finaly set the position of text //Finaly set the position of text
text_item -> setPos(text_pos); m_text_item -> setPos(text_pos);
} }
} }
@@ -1199,7 +1199,7 @@ void Conductor::saveProfile(bool undo) {
conductor_profiles[current_path_type], conductor_profiles[current_path_type],
current_path_type current_path_type
); );
undo_object -> setConductorTextItemMove(before_mov_text_pos_, text_item -> pos()); undo_object -> setConductorTextItemMove(before_mov_text_pos_, m_text_item -> pos());
dia -> undoStack().push(undo_object); dia -> undoStack().push(undo_object);
} }
} }
@@ -1248,61 +1248,100 @@ ConductorProfile Conductor::profile(Qt::Corner path_type) const {
return(conductor_profiles[path_type]); return(conductor_profiles[path_type]);
} }
/// @return le texte du conducteur
QString Conductor::text() const {
QString label = text_item->toPlainText();
return(label);
}
/**
* @brief Conductor::setText
* The text of this conductor
* @param t
*/
void Conductor::setText(const QString &t)
{
text_item->setPlainText(t);
}
/** /**
* @brief Conductor::refreshText * @brief Conductor::refreshText
* Refresh the text of this conductor. * Refresh the text of this conductor.
* recalcule and set the text according to the formula. * recalcule and set the text according to the formula.
*/ */
void Conductor::refreshText() { void Conductor::refreshText()
setText(m_freeze_label? text_item->toPlainText() : properties().text); {
if (m_freeze_label)
{
m_text_item->setPlainText(m_properties.text);
}
else
{
if (!m_properties.m_formula.isEmpty())
{
if (diagram())
{
QString text = autonum::AssignVariables::formulaToLabel(m_properties.m_formula, m_autoNum_seq, diagram());
m_properties.text = text;
m_text_item->setPlainText(text);
}
else
{
m_properties.text = m_properties.m_formula;
m_text_item->setPlainText(m_properties.text);
}
}
else
{
m_text_item->setPlainText(m_properties.text);
}
}
}
/**
* @brief Conductor::setPropertiesToPotential
* @param properties
* @param only_text
* Set @propertie to conductor and every conductors in the same potential of @conductor.
* If @only_text is true only formula, text, function and tension/protocol is set
* to other conductor in the same potential, the other values of property stay unmodified
*/
void Conductor::setPropertyToPotential(const ConductorProperties &property, bool only_text)
{
setProperties(property);
QSet <Conductor *> potential_list = relatedPotentialConductors();
foreach(Conductor *other_conductor, potential_list)
{
if (only_text)
{
ConductorProperties other_properties = other_conductor->properties();
other_properties.m_formula = m_properties.m_formula;
other_properties.text = m_properties.text;
other_properties.m_function = m_properties.m_function;
other_properties.m_tension_protocol = m_properties.m_tension_protocol;
other_conductor->setProperties(other_properties);
}
else
{
other_conductor->setProperties(property);
}
}
} }
/** /**
* @brief Conductor::setProperties * @brief Conductor::setProperties
* Set new properties for this conductor * Set @property as current property of conductor
* Also change the common properties for every conductors at the same potential.
* (text, function and tension/protocol) other value of properties isn't changed.
* @param properties : properties * @param properties : properties
*/ */
void Conductor::setProperties(const ConductorProperties &properties) void Conductor::setProperties(const ConductorProperties &property)
{ {
if (m_properties == properties) return; if (m_properties == property) return;
m_properties = properties; m_properties = property;
foreach(Conductor *other_conductor, relatedPotentialConductors()) if (!m_properties.m_formula.isEmpty())
{ {
ConductorProperties other_properties = other_conductor->properties(); if (diagram()) {
other_properties.text = m_properties.text; QString text = autonum::AssignVariables::formulaToLabel(m_properties.m_formula, m_autoNum_seq, diagram());
other_properties.color = m_properties.color; m_properties.text = text;
other_properties.cond_size = m_properties.cond_size; }
other_properties.m_function = m_properties.m_function; else {
other_properties.m_tension_protocol = m_properties.m_tension_protocol; m_properties.text = m_properties.m_formula;
other_conductor->setProperties(other_properties); }
} }
setText(m_properties.text);
text_item -> setFontSize(m_properties.text_size); m_text_item->setPlainText(m_properties.text);
m_text_item->setFontSize(m_properties.text_size);
if (m_properties.type != ConductorProperties::Multi) if (m_properties.type != ConductorProperties::Multi)
text_item -> setVisible(false); m_text_item->setVisible(false);
else else
text_item -> setVisible(m_properties.m_show_text); m_text_item->setVisible(m_properties.m_show_text);
calculateTextItemPosition(); calculateTextItemPosition();
update(); update();
@@ -1341,16 +1380,16 @@ void Conductor::setHighlighted(Conductor::Highlight hl) {
*/ */
void Conductor::displayedTextChanged() void Conductor::displayedTextChanged()
{ {
if ((text_item->toPlainText() == autonum::AssignVariables::formulaToLabel(m_properties.text, m_autoNum_seq, diagram())) || !diagram()) return;
QVariant old_value, new_value; QVariant old_value, new_value;
old_value.setValue(m_properties); old_value.setValue(m_properties);
ConductorProperties new_properties(m_properties); ConductorProperties new_properties(m_properties);
new_properties.text = text_item -> toPlainText(); new_properties.m_formula = m_text_item->toPlainText();
new_properties.text = m_text_item->toPlainText();
new_value.setValue(new_properties); new_value.setValue(new_properties);
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "properties", old_value, new_value);
undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption")); QUndoCommand *undo = new QUndoCommand(tr("Modifier les propriétés d'un conducteur", "undo caption"));
new QPropertyUndoCommand(this, "properties", old_value, new_value, undo);
if (!relatedPotentialConductors().isEmpty()) if (!relatedPotentialConductors().isEmpty())
{ {
@@ -1360,7 +1399,8 @@ void Conductor::displayedTextChanged()
{ {
old_value.setValue(potential_conductor->properties()); old_value.setValue(potential_conductor->properties());
ConductorProperties new_properties = potential_conductor->properties(); ConductorProperties new_properties = potential_conductor->properties();
new_properties.text = text_item->toPlainText(); new_properties.m_formula = m_text_item->toPlainText();
new_properties.text = m_text_item->toPlainText();
new_value.setValue(new_properties); new_value.setValue(new_properties);
new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo); new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo);
} }
@@ -1440,6 +1480,12 @@ void Conductor::editProperty() {
ConductorPropertiesDialog::PropertiesDialog(this, diagramEditor()); ConductorPropertiesDialog::PropertiesDialog(this, diagramEditor());
} }
void Conductor::setSequenceNum(autonum::sequentialNumbers sn)
{
m_autoNum_seq = sn;
refreshText();
}
/** /**
@param a point @param a point
@param b point @param b point

View File

@@ -45,6 +45,7 @@ class Conductor : public QObject, public QGraphicsPathItem
Q_PROPERTY(QPointF pos READ pos WRITE setPos) Q_PROPERTY(QPointF pos READ pos WRITE setPos)
Q_PROPERTY(int animPath READ fakePath WRITE updatePathAnimate) Q_PROPERTY(int animPath READ fakePath WRITE updatePathAnimate)
Q_PROPERTY(ConductorProperties properties READ properties WRITE setProperties) Q_PROPERTY(ConductorProperties properties READ properties WRITE setProperties)
Q_PROPERTY(autonum::sequentialNumbers sequenceNum READ sequenceNum WRITE setSequenceNum)
signals: signals:
void propertiesChange(); void propertiesChange();
@@ -62,9 +63,7 @@ class Conductor : public QObject, public QGraphicsPathItem
enum { Type = UserType + 1001 }; enum { Type = UserType + 1001 };
enum Highlight { None, Normal, Alert }; enum Highlight { None, Normal, Alert };
/// First terminal the wire is attached to
Terminal *terminal1; Terminal *terminal1;
/// Second terminal the wire is attached to
Terminal *terminal2; Terminal *terminal2;
public: public:
@@ -89,8 +88,6 @@ class Conductor : public QObject, public QGraphicsPathItem
qreal length() const; qreal length() const;
ConductorSegment *middleSegment(); ConductorSegment *middleSegment();
QPointF posForText(Qt::Orientations &flag); QPointF posForText(Qt::Orientations &flag);
QString text() const;
void setText(const QString &);
void refreshText(); void refreshText();
public: public:
@@ -103,8 +100,11 @@ class Conductor : public QObject, public QGraphicsPathItem
public: public:
QVector <QPointF> handlerPoints() const; QVector <QPointF> handlerPoints() const;
const QList<ConductorSegment *> segmentsList() const; const QList<ConductorSegment *> segmentsList() const;
void setProperties(const ConductorProperties &properties);
void setPropertyToPotential(const ConductorProperties &property, bool only_text = false);
void setProperties(const ConductorProperties &property);
ConductorProperties properties() const; ConductorProperties properties() const;
void setProfile(const ConductorProfile &, Qt::Corner); void setProfile(const ConductorProfile &, Qt::Corner);
ConductorProfile profile(Qt::Corner) const; ConductorProfile profile(Qt::Corner) const;
void setProfiles(const ConductorProfilesGroup &); void setProfiles(const ConductorProfilesGroup &);
@@ -118,6 +118,7 @@ class Conductor : public QObject, public QGraphicsPathItem
autonum::sequentialNumbers sequenceNum () const {return m_autoNum_seq;} autonum::sequentialNumbers sequenceNum () const {return m_autoNum_seq;}
autonum::sequentialNumbers& rSequenceNum() {return m_autoNum_seq;} autonum::sequentialNumbers& rSequenceNum() {return m_autoNum_seq;}
void setSequenceNum(autonum::sequentialNumbers sn);
private: private:
autonum::sequentialNumbers m_autoNum_seq; autonum::sequentialNumbers m_autoNum_seq;
@@ -143,7 +144,7 @@ class Conductor : public QObject, public QGraphicsPathItem
/// Functional properties /// Functional properties
ConductorProperties m_properties; ConductorProperties m_properties;
/// Text input for non simple, non-singleline conductors /// Text input for non simple, non-singleline conductors
ConductorTextItem *text_item; ConductorTextItem *m_text_item;
/// Segments composing the conductor /// Segments composing the conductor
ConductorSegment *segments; ConductorSegment *segments;
/// Attributs related to mouse interaction /// Attributs related to mouse interaction
@@ -159,14 +160,15 @@ class Conductor : public QObject, public QGraphicsPathItem
/// 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
static QPen conductor_pen;
static QBrush conductor_brush;
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; bool m_freeze_label = false;
/// QPen et QBrush objects used to draw conductors
static QPen conductor_pen;
static QBrush conductor_brush;
static bool pen_and_brush_initialized;
private: private:
void segmentsToPath(); void segmentsToPath();

View File

@@ -623,8 +623,7 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
if (use_properties) if (use_properties)
{ {
Conductor *other = conductors_list.toList().first(); Conductor *other = conductors_list.toList().first();
new_conductor->setText(""); new_conductor->setProperties(other->properties());
new_conductor->setText(other->properties().text);
} }
} }

View File

@@ -135,7 +135,7 @@ ConductorProperties ConductorPropertiesWidget::properties() const
bool ConductorPropertiesWidget::event(QEvent *event) bool ConductorPropertiesWidget::event(QEvent *event)
{ {
if (event->type() == QEvent::WindowActivate) { if (event->type() == QEvent::WindowActivate) {
ui -> m_text_le -> setFocus(); ui -> m_formula_le -> setFocus();
} }
return(QWidget::event(event)); return(QWidget::event(event));
} }

View File

@@ -24,6 +24,7 @@
#include "diagram.h" #include "diagram.h"
#include "element.h" #include "element.h"
#include "reportelement.h" #include "reportelement.h"
#include "assignvariables.h"
//### BEGIN PRIVATE CLASS ###// //### BEGIN PRIVATE CLASS ###//
@@ -43,8 +44,8 @@ class NewConductorPotentialSelector : public AbstractPotentialSelector
terminal_1->removeConductor(conductor); terminal_1->removeConductor(conductor);
terminal_2->removeConductor(conductor); terminal_2->removeConductor(conductor);
getPotential(terminal_1, m_properties_1, m_conductor_number_1); getPotential(terminal_1, m_properties_1, m_seq_num_1, m_conductor_number_1);
getPotential(terminal_2, m_properties_2, m_conductor_number_2); getPotential(terminal_2, m_properties_2, m_seq_num_2, m_conductor_number_2);
//There isn't a potential at terminal 1 or 2. //There isn't a potential at terminal 1 or 2.
if (m_conductor_number_1 == 0 && m_conductor_number_2 == 0) return; if (m_conductor_number_1 == 0 && m_conductor_number_2 == 0) return;
@@ -64,7 +65,7 @@ class NewConductorPotentialSelector : public AbstractPotentialSelector
* @param properties * @param properties
* @param number * @param number
*/ */
void getPotential(Terminal *terminal, ConductorProperties &properties, int &number) void getPotential(Terminal *terminal, ConductorProperties &properties, autonum::sequentialNumbers &seq_num , int &number)
{ {
Conductor *conductor_in_potential = nullptr; Conductor *conductor_in_potential = nullptr;
@@ -99,6 +100,7 @@ class NewConductorPotentialSelector : public AbstractPotentialSelector
if (!conductor_in_potential) return; if (!conductor_in_potential) return;
properties = conductor_in_potential->properties(); properties = conductor_in_potential->properties();
seq_num = conductor_in_potential->sequenceNum();
number = conductor_in_potential->relatedPotentialConductors().size()+1; //We add +1 because conductor_in_potential isn't count by relatedPotentialConductors number = conductor_in_potential->relatedPotentialConductors().size()+1; //We add +1 because conductor_in_potential isn't count by relatedPotentialConductors
} }
@@ -171,7 +173,7 @@ PotentialSelectorDialog::PotentialSelectorDialog(Conductor *conductor, QUndoComm
* Constructor when we link two potentiels together, with a folio report. * Constructor when we link two potentiels together, with a folio report.
* @param report : one of the report used to link the potentials (report must be linked to another report) * @param report : one of the report used to link the potentials (report must be linked to another report)
* @param parent_undo : undo parent to use * @param parent_undo : undo parent to use
* @param parent : paren widget * @param parent : parent widget
*/ */
PotentialSelectorDialog::PotentialSelectorDialog(Element *report, QUndoCommand *parent_undo, QWidget *parent) : PotentialSelectorDialog::PotentialSelectorDialog(Element *report, QUndoCommand *parent_undo, QWidget *parent) :
QDialog(parent), QDialog(parent),
@@ -200,8 +202,22 @@ void PotentialSelectorDialog::buildWidget()
QRadioButton *rb1 = new QRadioButton(tr("Le potentiel avec numero de fil %1 est présent %2 fois").arg(m_potential_selector->m_properties_1.text).arg(m_potential_selector->m_conductor_number_1), this); QRadioButton *rb1 = new QRadioButton(tr("Le potentiel avec numero de fil %1 est présent %2 fois").arg(m_potential_selector->m_properties_1.text).arg(m_potential_selector->m_conductor_number_1), this);
QRadioButton *rb2 = new QRadioButton(tr("Le potentiel avec numero de fil %1 est présent %2 fois").arg(m_potential_selector->m_properties_2.text).arg(m_potential_selector->m_conductor_number_2), this); QRadioButton *rb2 = new QRadioButton(tr("Le potentiel avec numero de fil %1 est présent %2 fois").arg(m_potential_selector->m_properties_2.text).arg(m_potential_selector->m_conductor_number_2), this);
connect(rb1, &QRadioButton::toggled, [this](bool t){if(t) this->m_selected_properties = this->m_potential_selector->m_properties_1;}); connect(rb1, &QRadioButton::toggled, [this](bool t)
connect(rb2, &QRadioButton::toggled, [this](bool t){if(t) this->m_selected_properties = this->m_potential_selector->m_properties_2;}); {
if(t)
{
this->m_selected_properties = this->m_potential_selector->m_properties_1;
this->m_sequential_num = this->m_potential_selector->m_seq_num_1;
}
});
connect(rb2, &QRadioButton::toggled, [this](bool t)
{
if(t)
{
this->m_selected_properties = this->m_potential_selector->m_properties_2;
this->m_sequential_num = this->m_potential_selector->m_seq_num_2;
}
});
//Set the radio button of potential with the bigger number of conductors, //Set the radio button of potential with the bigger number of conductors,
//at first position, and check it //at first position, and check it
@@ -232,6 +248,7 @@ void PotentialSelectorDialog::on_buttonBox_accepted()
ConductorProperties new_properties = m_conductor->properties(); ConductorProperties new_properties = m_conductor->properties();
new_properties.text = m_selected_properties.text; new_properties.text = m_selected_properties.text;
new_properties.m_formula = m_selected_properties.m_formula;
new_properties.m_function = m_selected_properties.m_function; new_properties.m_function = m_selected_properties.m_function;
new_properties.m_tension_protocol = m_selected_properties.m_tension_protocol; new_properties.m_tension_protocol = m_selected_properties.m_tension_protocol;
@@ -239,19 +256,32 @@ void PotentialSelectorDialog::on_buttonBox_accepted()
old_value.setValue(m_conductor->properties()); old_value.setValue(m_conductor->properties());
new_value.setValue(new_properties); new_value.setValue(new_properties);
QUndoCommand *undo = nullptr;
if (m_parent_undo)
undo = m_parent_undo;
else
undo = new QUndoCommand(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
//Set the properties for the new conductor //Set the properties for the new conductor
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_conductor, "properties", old_value, new_value, m_parent_undo); QVariant old_seq, new_seq;
undo->setText(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption")); old_seq.setValue(m_conductor->sequenceNum());
new_seq.setValue(m_sequential_num);
new QPropertyUndoCommand(m_conductor, "sequenceNum", old_seq, new_seq, undo);
new QPropertyUndoCommand(m_conductor, "properties", old_value, new_value, undo);
//Set the new properties for each conductors of the new potential //Set the new properties for each conductors of the new potential
foreach(Conductor *cond, m_conductor->relatedPotentialConductors()) foreach(Conductor *cond, m_conductor->relatedPotentialConductors())
{ {
new_properties = cond->properties(); new_properties = cond->properties();
new_properties.text = m_selected_properties.text; new_properties.text = m_selected_properties.text;
new_properties.m_formula = m_selected_properties.m_formula;
new_properties.m_function = m_selected_properties.m_function; new_properties.m_function = m_selected_properties.m_function;
new_properties.m_tension_protocol = m_selected_properties.m_tension_protocol; new_properties.m_tension_protocol = m_selected_properties.m_tension_protocol;
old_value.setValue(cond->properties()); old_value.setValue(cond->properties());
new_value.setValue(new_properties); new_value.setValue(new_properties);
old_seq.setValue(cond->sequenceNum());
new QPropertyUndoCommand(cond, "sequenceNum", old_seq, new_seq, undo);
new QPropertyUndoCommand(cond, "properties", old_value, new_value, undo); new QPropertyUndoCommand(cond, "properties", old_value, new_value, undo);
} }
@@ -263,6 +293,7 @@ void PotentialSelectorDialog::on_buttonBox_accepted()
else else
{ {
delete undo; delete undo;
m_conductor->setSequenceNum(m_sequential_num);
m_conductor->setProperties(new_properties); m_conductor->setProperties(new_properties);
} }
} }

View File

@@ -20,6 +20,7 @@
#include <QDialog> #include <QDialog>
#include "conductorproperties.h" #include "conductorproperties.h"
#include "assignvariables.h"
class Conductor; class Conductor;
class QUndoCommand; class QUndoCommand;
class Element; class Element;
@@ -32,6 +33,7 @@ class AbstractPotentialSelector
virtual bool isValid() const = 0; virtual bool isValid() const = 0;
ConductorProperties m_properties_1, m_properties_2; ConductorProperties m_properties_1, m_properties_2;
autonum::sequentialNumbers m_seq_num_1, m_seq_num_2;
int m_conductor_number_1, m_conductor_number_2; int m_conductor_number_1, m_conductor_number_2;
}; };
@@ -72,6 +74,7 @@ class PotentialSelectorDialog : public QDialog
Element *m_report; Element *m_report;
QUndoCommand *m_parent_undo; QUndoCommand *m_parent_undo;
ConductorProperties m_selected_properties; ConductorProperties m_selected_properties;
autonum::sequentialNumbers m_sequential_num;
AbstractPotentialSelector *m_potential_selector; AbstractPotentialSelector *m_potential_selector;
}; };
#endif // POTENTIALSELECTORDIALOG_H #endif // POTENTIALSELECTORDIALOG_H