[qet] [4126] At creation of a new conductor, if every properties of conductors at the same potential is equal, |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4126
Author: blacksun
Date: 2015-08-17 19:01:39 +0200 (Mon, 17 Aug 2015)
Log Message:
-----------
At creation of a new conductor, if every properties of conductors at the same potential is equal,
we use this properties for the new conductor, instead of the default properties.
Modified Paths:
--------------
trunk/sources/elementsmover.cpp
trunk/sources/qetgraphicsitem/terminal.cpp
Modified: trunk/sources/elementsmover.cpp
===================================================================
--- trunk/sources/elementsmover.cpp 2015-08-17 14:08:54 UTC (rev 4125)
+++ trunk/sources/elementsmover.cpp 2015-08-17 17:01:39 UTC (rev 4126)
@@ -146,7 +146,6 @@
QPair <Terminal *, Terminal *> pair = elmt -> AlignedFreeTerminals().takeFirst();
Conductor *conductor = new Conductor(pair.first, pair.second);
- conductor -> setProperties(diagram_ -> defaultConductorProperties);
//Create an undo object for each new auto conductor, with undo_object for parent if exist
//Else the first undo for this auto conductor become the undo_object
@@ -155,9 +154,31 @@
else
undo_object = new AddItemCommand<Conductor *>(conductor, diagram_, QPointF());
- //Autonum the new conductor, the undo command associated for this, have for parent undo_object
- ConductorAutoNumerotation can (conductor, diagram_, undo_object);
- can.numerate();
+ //Get all conductors at the same potential of conductor
+ QSet <Conductor *> conductors_list = conductor->relatedPotentialConductors();
+
+ //Compare the properties of every conductors stored in conductors_list,
+ //if every conductors properties is equal, we use this properties for conductor.
+ ConductorProperties others_properties;
+ bool use_properties = false;
+ if (!conductors_list.isEmpty())
+ {
+ use_properties = true;
+ others_properties = (*conductors_list.begin())->properties();
+ foreach (Conductor *cond, conductors_list)
+ if (cond->properties() != others_properties)
+ use_properties = false;
+ }
+
+ if (use_properties)
+ conductor->setProperties(others_properties);
+ else
+ {
+ conductor -> setProperties(diagram_ -> defaultConductorProperties);
+ //Autonum the new conductor, the undo command associated for this, have for parent undo_object
+ ConductorAutoNumerotation can (conductor, diagram_, undo_object);
+ can.numerate();
+ }
};
}
Modified: trunk/sources/qetgraphicsitem/terminal.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.cpp 2015-08-17 14:08:54 UTC (rev 4125)
+++ trunk/sources/qetgraphicsitem/terminal.cpp 2015-08-17 17:01:39 UTC (rev 4126)
@@ -582,35 +582,59 @@
previous_terminal_ = 0;
hovered_color_ = neutralColor;
- if (Diagram *d = diagram())
- {
- //Stop conductor preview
- d -> setConductor(false);
+ if (!diagram()) return;
- //Get item under cursor
- QGraphicsItem *qgi = d -> itemAt(e -> scenePos(), QTransform());
- if (!qgi) return;
+ //Stop conductor preview
+ diagram() -> setConductor(false);
- //Element must be a terminal
- Terminal *other_terminal = qgraphicsitem_cast<Terminal *>(qgi);
- if (!other_terminal) return;
+ //Get item under cursor
+ QGraphicsItem *qgi = diagram() -> itemAt(e -> scenePos(), QTransform());
+ if (!qgi) return;
- other_terminal -> hovered_color_ = neutralColor;
- other_terminal -> hovered_ = false;
+ //Element must be a terminal
+ Terminal *other_terminal = qgraphicsitem_cast<Terminal *>(qgi);
+ if (!other_terminal) return;
- //We stop her if we can't link this terminal with other terminal
- if (!canBeLinkedTo(other_terminal)) return;
+ other_terminal -> hovered_color_ = neutralColor;
+ other_terminal -> hovered_ = false;
- //Create conductor
- Conductor *new_conductor = new Conductor(this, other_terminal);
- new_conductor -> setProperties(d -> defaultConductorProperties);
- QUndoCommand *undo = new AddItemCommand<Conductor *>(new_conductor, d);
+ //We stop her if we can't link this terminal with other terminal
+ if (!canBeLinkedTo(other_terminal)) return;
+
+ //Create conductor
+ Conductor *new_conductor = new Conductor(this, other_terminal);
+
+ //Get all conductors at the same potential of new conductors
+ QSet <Conductor *> conductors_list = new_conductor->relatedPotentialConductors();
+
+ //Compare the properties of every conductors stored in conductors_list,
+ //if every conductors properties is equal, we use this properties for the new conductor.
+ ConductorProperties others_properties;
+ bool use_properties = false;
+ if (!conductors_list.isEmpty())
+ {
+ use_properties = true;
+ others_properties = (*conductors_list.begin())->properties();
+ foreach (Conductor *conductor, conductors_list)
+ if (conductor->properties() != others_properties)
+ use_properties = false;
+ }
+
+
+ QUndoCommand *undo = new AddItemCommand<Conductor *>(new_conductor, diagram());
+
+ if (use_properties)
+ new_conductor->setProperties(others_properties);
+ else
+ {
+ new_conductor -> setProperties(diagram() -> defaultConductorProperties);
//Autonum it
- ConductorAutoNumerotation can (new_conductor, d, undo);
+ ConductorAutoNumerotation can (new_conductor, diagram(), undo);
can.numerate();
- //Add undo command to the parent diagram
- d -> undoStack().push(undo);
}
+
+ //Add undo command to the parent diagram
+ diagram() -> undoStack().push(undo);
}
/**