[qet] qet/qet: [4833] Continue to fix bug tracker N°118 |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4833
Author: blacksun
Date: 2017-01-05 16:25:07 +0100 (Thu, 05 Jan 2017)
Log Message:
-----------
Continue to fix bug tracker N°118
Modified Paths:
--------------
trunk/sources/conductorautonumerotation.cpp
trunk/sources/conductorproperties.cpp
trunk/sources/conductorproperties.h
trunk/sources/ui/potentialselectordialog.cpp
trunk/sources/ui/potentialselectordialog.h
Modified: trunk/sources/conductorautonumerotation.cpp
===================================================================
--- trunk/sources/conductorautonumerotation.cpp 2017-01-04 22:40:46 UTC (rev 4832)
+++ trunk/sources/conductorautonumerotation.cpp 2017-01-05 15:25:07 UTC (rev 4833)
@@ -105,6 +105,21 @@
*/
void ConductorAutoNumerotation::numeratePotential()
{
+ ConductorProperties cp = conductor_list.first()->properties();
+ bool properties_equal = true;
+ foreach (const Conductor *conductor, conductor_list)
+ {
+ if (conductor->properties() != cp)
+ properties_equal = false;
+ }
+ //Every properties of the potential is equal, so we apply it to m_conductor
+ if (properties_equal)
+ {
+ m_conductor->setProperties(cp);
+ m_conductor->rSequenceNum() = conductor_list.first()->sequenceNum();
+ return;
+ }
+
QStringList text_list;
QStringList formula_list;
foreach (const Conductor *cc, conductor_list)
@@ -118,9 +133,12 @@
//the texts is identicals
if (QET::eachStrIsEqual(text_list) && QET::eachStrIsEqual(formula_list))
{
- ConductorProperties cp = m_conductor -> properties();
- cp.text = text_list.first();
- cp.m_formula = formula_list.first();
+ QList<ConductorProperties> cp_list;
+ foreach(Conductor *c, conductor_list)
+ cp_list<<c->properties();
+
+ ConductorProperties cp = m_conductor->properties();
+ cp.applyForEqualAttributes(cp_list);
m_conductor->rSequenceNum() = conductor_list.first()->sequenceNum();
m_conductor->setProperties(cp);
}
Modified: trunk/sources/conductorproperties.cpp
===================================================================
--- trunk/sources/conductorproperties.cpp 2017-01-04 22:40:46 UTC (rev 4832)
+++ trunk/sources/conductorproperties.cpp 2017-01-05 15:25:07 UTC (rev 4833)
@@ -381,6 +381,158 @@
}
/**
+ * @brief ConductorProperties::applyForEqualAttributes
+ * Test each attribute of properties in the list separatly.
+ * For each attributes, if is equal, the attribute is apply to this.
+ * @param list
+ */
+void ConductorProperties::applyForEqualAttributes(QList<ConductorProperties> list)
+{
+ if (list.isEmpty())
+ return;
+
+ if (list.size() == 1)
+ {
+ ConductorProperties cp = list.first();
+ color = cp.color;
+ text = cp.text;
+ m_formula = cp.m_formula;
+ m_function = cp.m_function;
+ m_tension_protocol = cp.m_tension_protocol;
+ text_size = cp.text_size;
+ cond_size = cp.cond_size;
+ m_show_text = cp.m_show_text;
+ m_one_text_per_folio = cp.m_one_text_per_folio;
+ verti_rotate_text = cp.verti_rotate_text;
+ horiz_rotate_text = cp.horiz_rotate_text;
+
+ return;
+ }
+
+ bool equal = true;
+ //Color
+ QColor c_value = list.first().color;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.color != c_value)
+ equal = false;
+ }
+ if (equal)
+ color = c_value;
+ equal = true;
+
+ //text
+ QString s_value = list.first().text;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.text != s_value)
+ equal = false;
+ }
+ if (equal)
+ text = s_value;
+ equal = true;
+
+ //formula
+ s_value = list.first().m_formula;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.m_formula != s_value)
+ equal = false;
+ }
+ if (equal)
+ m_formula = s_value;
+ equal = true;
+
+ //function
+ s_value = list.first().m_function;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.m_function != s_value)
+ equal = false;
+ }
+ if (equal)
+ m_function = s_value;
+ equal = true;
+
+ //Tension protocol
+ s_value = list.first().m_tension_protocol;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.m_tension_protocol != s_value)
+ equal = false;
+ }
+ if (equal)
+ m_tension_protocol = s_value;
+ equal = true;
+
+ //text size
+ int i_value = list.first().text_size;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.text_size != i_value)
+ equal = false;
+ }
+ if (equal)
+ text_size = i_value;
+ equal = true;
+
+ //conductor size
+ double d_value = list.first().cond_size;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.cond_size != d_value)
+ equal = false;
+ }
+ if (equal)
+ cond_size = d_value;
+ equal = true;
+
+ //show text
+ bool b_value = list.first().m_show_text;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.m_show_text != b_value)
+ equal = false;
+ }
+ if (equal)
+ m_show_text = b_value;
+ equal = true;
+
+ //One text per folio
+ b_value = list.first().m_one_text_per_folio;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.m_one_text_per_folio != b_value)
+ equal = false;
+ }
+ if (equal)
+ m_one_text_per_folio = b_value;
+ equal = true;
+
+ //Text rotation for vertical conducor
+ d_value = list.first().verti_rotate_text;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.verti_rotate_text != d_value)
+ equal = false;
+ }
+ if (equal)
+ verti_rotate_text = d_value;
+ equal = true;
+
+ //Text rotation for horizontal conducor
+ d_value = list.first().horiz_rotate_text;
+ foreach(ConductorProperties cp, list)
+ {
+ if (cp.horiz_rotate_text != d_value)
+ equal = false;
+ }
+ if (equal)
+ horiz_rotate_text = d_value;
+ equal = true;
+}
+
+/**
* @brief ConductorProperties::defaultProperties
* @return the default properties stored in the setting file
*/
Modified: trunk/sources/conductorproperties.h
===================================================================
--- trunk/sources/conductorproperties.h 2017-01-04 22:40:46 UTC (rev 4832)
+++ trunk/sources/conductorproperties.h 2017-01-05 15:25:07 UTC (rev 4833)
@@ -98,6 +98,7 @@
void fromSettings(QSettings &, const QString & = QString());
static QString typeToString(ConductorType);
void setText(QString);
+ void applyForEqualAttributes(QList<ConductorProperties> list);
static ConductorProperties defaultProperties();
Modified: trunk/sources/ui/potentialselectordialog.cpp
===================================================================
--- trunk/sources/ui/potentialselectordialog.cpp 2017-01-04 22:40:46 UTC (rev 4832)
+++ trunk/sources/ui/potentialselectordialog.cpp 2017-01-05 15:25:07 UTC (rev 4833)
@@ -44,8 +44,8 @@
terminal_1->removeConductor(conductor);
terminal_2->removeConductor(conductor);
- getPotential(terminal_1, m_properties_1, m_seq_num_1, m_conductor_number_1);
- getPotential(terminal_2, m_properties_2, m_seq_num_2, m_conductor_number_2);
+ getPotential(terminal_1, m_properties_1, m_seq_num_1, m_conductor_number_1, m_properties_list_1);
+ getPotential(terminal_2, m_properties_2, m_seq_num_2, m_conductor_number_2, m_properties_list_2);
//There isn't a potential at terminal 1 or 2.
if (m_conductor_number_1 == 0 && m_conductor_number_2 == 0) return;
@@ -65,7 +65,7 @@
* @param properties
* @param number
*/
- void getPotential(Terminal *terminal, ConductorProperties &properties, autonum::sequentialNumbers &seq_num , int &number)
+ void getPotential(Terminal *terminal, ConductorProperties &properties, autonum::sequentialNumbers &seq_num , int &number, QList<ConductorProperties> &properties_list)
{
Conductor *conductor_in_potential = nullptr;
@@ -98,10 +98,16 @@
}
}
- if (!conductor_in_potential) return;
+ if (!conductor_in_potential)
+ return;
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
+
+ QList<Conductor *> c_list = conductor_in_potential->relatedPotentialConductors().toList();
+ c_list.append(conductor_in_potential);
+ foreach(Conductor *c, c_list)
+ properties_list.append(c->properties());
}
~NewConductorPotentialSelector() {}
@@ -126,15 +132,28 @@
Element *other_report = report->linkedElements().first();
report->unlinkAllElements();
- if (report->conductors().isEmpty() || other_report->conductors().isEmpty()) return;
+ if (report->conductors().isEmpty() || other_report->conductors().isEmpty())
+ return;
+ QList <Conductor*> c_list;
+
m_properties_1 = report->conductors().first()->properties();
m_conductor_number_1 = report->conductors().first()->relatedPotentialConductors().size() + 1;
m_seq_num_1 = report->conductors().first()->sequenceNum();
+ c_list.append(report->conductors().first()->relatedPotentialConductors().toList());
+ c_list.append(report->conductors().first());
+ foreach(Conductor *c, c_list)
+ m_properties_list_1 << c->properties();
+ c_list.clear();
+
m_properties_2 = other_report->conductors().first()->properties();
m_conductor_number_2 = other_report->conductors().first()->relatedPotentialConductors().size() + 1;
m_seq_num_2 = other_report->conductors().first()->sequenceNum();
+ c_list.append(other_report->conductors().first()->relatedPotentialConductors().toList());
+ c_list.append(other_report->conductors().first());
+ foreach(Conductor *c, c_list)
+ m_properties_list_2 << c->properties();
//We relink the report
report->linkToElement(other_report);
@@ -211,6 +230,8 @@
{
this->m_selected_properties = this->m_potential_selector->m_properties_1;
this->m_sequential_num = this->m_potential_selector->m_seq_num_1;
+ this->m_properties_list = this->m_potential_selector->m_properties_list_1;
+ m_selected = 1;
}
});
connect(rb2, &QRadioButton::toggled, [this](bool t)
@@ -219,6 +240,8 @@
{
this->m_selected_properties = this->m_potential_selector->m_properties_2;
this->m_sequential_num = this->m_potential_selector->m_seq_num_2;
+ this->m_properties_list = this->m_potential_selector->m_properties_list_2;
+ m_selected = 2;
}
});
@@ -244,22 +267,9 @@
*/
void PotentialSelectorDialog::on_buttonBox_accepted()
{
- if (!m_potential_selector->isValid()) return;
+ if (!m_potential_selector->isValid())
+ return;
- if (!m_conductor)
- m_conductor = m_report->conductors().first();
-
- ConductorProperties new_properties = m_conductor->properties();
- 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_tension_protocol = m_selected_properties.m_tension_protocol;
-
- QVariant old_value, new_value;
- old_value.setValue(m_conductor->properties());
- new_value.setValue(new_properties);
-
-
QUndoCommand *undo = nullptr;
if (m_parent_undo)
undo = m_parent_undo;
@@ -266,37 +276,90 @@
else
undo = new QUndoCommand(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
- //Set the properties for the new conductor
- QVariant old_seq, new_seq;
- 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);
+ Diagram * diagram = nullptr;
- //Set the new properties for each conductors of the new potential
- foreach(Conductor *cond, m_conductor->relatedPotentialConductors())
+ if (m_report)
{
- new_properties = cond->properties();
- 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_tension_protocol = m_selected_properties.m_tension_protocol;
- old_value.setValue(cond->properties());
+ if ((m_report->linkType() & Element::AllReport) && !m_report->isFree())
+ {
+ if (m_report->diagram())
+ diagram = m_report->diagram();
+
+ //We temporarily unlink report to get the two existing potential
+ Element *other_report = m_report->linkedElements().first();
+ m_report->unlinkAllElements();
+
+ QList<Conductor *> conductor_list;
+
+ if (m_selected == 1)
+ {
+ conductor_list.append(other_report->conductors().first()->relatedPotentialConductors().toList());
+ conductor_list.append(other_report->conductors().first());
+ }
+
+ else if (m_selected == 2)
+ {
+ conductor_list.append(m_report->conductors().first()->relatedPotentialConductors().toList());
+ conductor_list.append(m_report->conductors().first());
+ }
+
+ QVariant old_value, new_value;
+ QVariant old_seq, new_seq;
+ new_seq.setValue(m_sequential_num);
+
+ //Set the new properties for each conductors of the new potential
+ foreach(Conductor *cond, conductor_list)
+ {
+ ConductorProperties new_properties = cond->properties();
+ new_properties.applyForEqualAttributes(m_properties_list);
+ old_value.setValue(cond->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);
+ }
+ //We relink the report
+ m_report->linkToElement(other_report);
+ }
+
+ }
+
+ else if (m_conductor)
+ {
+ if (m_conductor->diagram())
+ diagram = m_conductor->diagram();
+
+ ConductorProperties new_properties = m_conductor->properties();
+ new_properties.applyForEqualAttributes(m_properties_list);
+
+ QVariant old_value, new_value;
+ old_value.setValue(m_conductor->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);
+
+ QVariant old_seq, new_seq;
+ 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
+ foreach(Conductor *cond, m_conductor->relatedPotentialConductors())
+ {
+ new_properties = cond->properties();
+ new_properties.applyForEqualAttributes(m_properties_list);
+ old_value.setValue(cond->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);
+ }
}
//There is an undo parent, we stop here, the owner of m_parent_undo will push it to an undo stack
- if (m_parent_undo) return;
+ if (m_parent_undo)
+ return;
//There isn't a parent, we push the undo command to diagram undo stack.
- if (m_conductor->diagram()) m_conductor->diagram()->undoStack().push(undo);
- //We apply the change without undo command
- else
- {
- delete undo;
- m_conductor->setSequenceNum(m_sequential_num);
- m_conductor->setProperties(new_properties);
- }
+ if (diagram)
+ diagram->undoStack().push(undo);
}
Modified: trunk/sources/ui/potentialselectordialog.h
===================================================================
--- trunk/sources/ui/potentialselectordialog.h 2017-01-04 22:40:46 UTC (rev 4832)
+++ trunk/sources/ui/potentialselectordialog.h 2017-01-05 15:25:07 UTC (rev 4833)
@@ -35,6 +35,7 @@
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;
+ QList<ConductorProperties> m_properties_list_1, m_properties_list_2;
};
namespace Ui {
@@ -76,5 +77,7 @@
ConductorProperties m_selected_properties;
autonum::sequentialNumbers m_sequential_num;
AbstractPotentialSelector *m_potential_selector;
+ QList <ConductorProperties> m_properties_list;
+ int m_selected = 0;
};
#endif // POTENTIALSELECTORDIALOG_H