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.


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4126 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-08-17 17:01:39 +00:00
parent 1973e3378f
commit d77011acfb
2 changed files with 76 additions and 31 deletions

View File

@@ -146,7 +146,6 @@ void ElementsMover::endMovement()
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 @@ void ElementsMover::endMovement()
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();
}
};
}

View File

@@ -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<Terminal *>(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 <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())
{
//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<Terminal *>(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<Conductor *>(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<Conductor *>(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);
}
/**