[qet] [4150] Conductor : remove the possibility to have different texts on the same potential |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4150
Author: blacksun
Date: 2015-08-22 15:18:20 +0200 (Sat, 22 Aug 2015)
Log Message:
-----------
Conductor : remove the possibility to have different texts on the same potential
Modified Paths:
--------------
trunk/sources/conductorautonumerotation.cpp
trunk/sources/qetgraphicsitem/conductor.cpp
trunk/sources/ui/conductorpropertiesdialog.cpp
trunk/sources/ui/potentialtextsdialog.ui
Modified: trunk/sources/conductorautonumerotation.cpp
===================================================================
--- trunk/sources/conductorautonumerotation.cpp 2015-08-21 22:27:57 UTC (rev 4149)
+++ trunk/sources/conductorautonumerotation.cpp 2015-08-22 13:18:20 UTC (rev 4150)
@@ -114,22 +114,25 @@
* @brief ConductorAutoNumerotation::numeratePotential
* Numerate a conductor on an existing potential
*/
-void ConductorAutoNumerotation::numeratePotential() {
+void ConductorAutoNumerotation::numeratePotential()
+{
QStringList strl;
foreach (const Conductor *cc, conductor_list) strl<<(cc->text());
+
//the texts is identicals
- if (QET::eachStrIsEqual(strl)) {
+ if (QET::eachStrIsEqual(strl))
+ {
ConductorProperties cp = conductor_ -> properties();
cp.text = strl.at(0);
conductor_ -> setProperties(cp);
conductor_ -> setText(strl.at(0));
}
- //the texts isn't identicals
- else {
+ //the texts isn't identicals
+ else
+ {
PotentialTextsDialog ptd (conductor_, conductor_ -> diagramEditor());
- if (ptd.exec() == QDialog::Accepted) {
- applyText(ptd.selectedText());
- }
+ ptd.exec();
+ applyText(ptd.selectedText());
}
}
Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp 2015-08-21 22:27:57 UTC (rev 4149)
+++ trunk/sources/qetgraphicsitem/conductor.cpp 2015-08-22 13:18:20 UTC (rev 4150)
@@ -90,15 +90,11 @@
setFlags(QGraphicsItem::ItemIsSelectable);
setAcceptHoverEvents(true);
- // ajout du champ de texte editable
+ // Add the text field
text_item = new ConductorTextItem(properties_.text, this);
text_item -> setFlag(QGraphicsItem::ItemStacksBehindParent);
- connect(
- text_item,
- SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
- this,
- SLOT(displayedTextChanged())
- );
+
+ connect(text_item, &ConductorTextItem::diagramTextChanged, this, &Conductor::displayedTextChanged);
}
/**
@@ -1392,43 +1388,38 @@
}
/**
- Met a jour les proprietes du conducteur apres modification du champ de texte affiche
-*/
-void Conductor::displayedTextChanged() {
- // verifie que le texte a reellement change
- if (text_item -> toPlainText() == properties_.text) return;
-
- if (Diagram *my_diagram = diagram())
+ * @brief Conductor::displayedTextChanged
+ * Update the properties (text) of this conductor and other conductors
+ * at the same potential of this conductor.
+ */
+void Conductor::displayedTextChanged()
+{
+ if ((text_item->toPlainText() == properties_.text) || !diagram()) return;
+
+ QVariant old_value, new_value;
+ old_value.setValue(properties_);
+ ConductorProperties new_properties(properties_);
+ new_properties.text = text_item -> toPlainText();
+ 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"));
+
+ if (!relatedPotentialConductors().isEmpty())
{
- int qmbreturn=0;
- //if conductor isn't alone at this potential
- //ask user to apply text on every conductors of this potential
- if (relatedPotentialConductors().size() >= 1)
- {
- qmbreturn = QMessageBox::question(diagramEditor(), tr("Textes de conducteurs"),
- tr("Voulez-vous appliquer le nouveau texte \n"
- "à l'ensemble des conducteurs de ce potentiel ?"),
- QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes);
- if (qmbreturn == QMessageBox::Yes)
- {
- ConductorAutoNumerotation can(this, my_diagram);
- can.applyText(text_item -> toPlainText());
- }
- }
+ undo->setText(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
- if (qmbreturn == 0 || qmbreturn == QMessageBox::No)
+ foreach (Conductor *potential_conductor, relatedPotentialConductors())
{
- QVariant old_value, new_value;
- old_value.setValue(properties_);
- ConductorProperties new_properties(properties_);
- new_properties.text = text_item -> toPlainText();
+ old_value.setValue(potential_conductor->properties());
+ ConductorProperties new_properties = potential_conductor->properties();
+ new_properties.text = text_item->toPlainText();
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"));
- my_diagram -> undoStack().push(undo);
+ new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo);
}
}
+
+ diagram()->undoStack().push(undo);
}
Modified: trunk/sources/ui/conductorpropertiesdialog.cpp
===================================================================
--- trunk/sources/ui/conductorpropertiesdialog.cpp 2015-08-21 22:27:57 UTC (rev 4149)
+++ trunk/sources/ui/conductorpropertiesdialog.cpp 2015-08-22 13:18:20 UTC (rev 4150)
@@ -61,28 +61,44 @@
{
ConductorPropertiesDialog cpd (conductor, parent);
- if (cpd.exec() == QDialog::Accepted && cpd.properties() != conductor->properties())
+ if (cpd.exec() == QDialog::Rejected || cpd.properties() == conductor->properties()) return;
+
+ QVariant old_value, new_value;
+ old_value.setValue(conductor->properties());
+ new_value.setValue(cpd.properties());
+
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(conductor, "properties", old_value, new_value);
+ undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption"));
+
+ if (!conductor->relatedPotentialConductors().isEmpty())
{
- QVariant old_value, new_value;
- old_value.setValue(conductor->properties());
- new_value.setValue(cpd.properties());
+ undo->setText(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
+ QString old_text = conductor->properties().text;
+ QString new_text = cpd.properties().text;
- QPropertyUndoCommand *undo = new QPropertyUndoCommand(conductor, "properties", old_value, new_value);
- undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption"));
-
- //Make undo for all related potiential conductors
- if (cpd.applyAll() && !conductor->relatedPotentialConductors().isEmpty())
+ foreach (Conductor *potential_conductor, conductor->relatedPotentialConductors())
{
- undo->setText(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
- foreach (Conductor *cond, conductor->relatedPotentialConductors())
+ //"Apply to all conductors of potential" is checked,
+ //we apply the new properties for every conductors in the same potential.
+ if (cpd.applyAll())
{
- old_value.setValue(cond->properties());
- new QPropertyUndoCommand (cond, "properties", old_value, new_value, undo);
+ old_value.setValue(potential_conductor->properties());
+ new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo);
}
+ //The num of conductor isn't affected by "Apply to all conductors of potential"
+ //we always apply it to the potential if he change.
+ else if(old_text != new_text)
+ {
+ old_value.setValue(potential_conductor->properties());
+ ConductorProperties new_properties = potential_conductor->properties();
+ new_properties.text = new_text;
+ new_value.setValue(new_properties);
+ new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo);
+ }
}
+ }
- conductor->diagram()->undoStack().push(undo);
- }
+ conductor->diagram()->undoStack().push(undo);
}
/**
Modified: trunk/sources/ui/potentialtextsdialog.ui
===================================================================
--- trunk/sources/ui/potentialtextsdialog.ui 2015-08-21 22:27:57 UTC (rev 4149)
+++ trunk/sources/ui/potentialtextsdialog.ui 2015-08-22 13:18:20 UTC (rev 4150)
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>400</width>
+ <width>403</width>
<height>94</height>
</rect>
</property>
@@ -20,7 +20,7 @@
<widget class="QLabel" name="label">
<property name="text">
<string>Les textes de ce potentiel électrique ne sont pas identiques.
-Appliquer un texte à l'ensemble de ces conducteurs?</string>
+Appliquer un texte à l'ensemble de ces conducteurs.</string>
</property>
</widget>
</item>
@@ -48,7 +48,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ <set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>