diff --git a/sources/elementsmover.cpp b/sources/elementsmover.cpp index e321ef06e..96b544a1d 100644 --- a/sources/elementsmover.cpp +++ b/sources/elementsmover.cpp @@ -146,7 +146,6 @@ void ElementsMover::endMovement() QPair 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 @@ void ElementsMover::endMovement() else undo_object = new AddItemCommand(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 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(); + } }; } diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index d6331c245..c03e6c64d 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -582,35 +582,59 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) previous_terminal_ = 0; hovered_color_ = neutralColor; - if (Diagram *d = diagram()) + if (!diagram()) return; + + //Stop conductor preview + diagram() -> setConductor(false); + + //Get item under cursor + QGraphicsItem *qgi = diagram() -> itemAt(e -> scenePos(), QTransform()); + if (!qgi) return; + + //Element must be a terminal + Terminal *other_terminal = qgraphicsitem_cast(qgi); + if (!other_terminal) return; + + other_terminal -> hovered_color_ = neutralColor; + other_terminal -> hovered_ = false; + + //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 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()) { - //Stop conductor preview - d -> setConductor(false); - - //Get item under cursor - QGraphicsItem *qgi = d -> itemAt(e -> scenePos(), QTransform()); - if (!qgi) return; - - //Element must be a terminal - Terminal *other_terminal = qgraphicsitem_cast(qgi); - if (!other_terminal) return; - - other_terminal -> hovered_color_ = neutralColor; - other_terminal -> hovered_ = false; - - //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); - new_conductor -> setProperties(d -> defaultConductorProperties); - QUndoCommand *undo = new AddItemCommand(new_conductor, d); - //Autonum it - ConductorAutoNumerotation can (new_conductor, d, undo); - can.numerate(); - //Add undo command to the parent diagram - d -> undoStack().push(undo); + 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(new_conductor, diagram()); + + if (use_properties) + new_conductor->setProperties(others_properties); + else + { + new_conductor -> setProperties(diagram() -> defaultConductorProperties); + //Autonum it + ConductorAutoNumerotation can (new_conductor, diagram(), undo); + can.numerate(); + } + + //Add undo command to the parent diagram + diagram() -> undoStack().push(undo); } /**