mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
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:
@@ -146,7 +146,6 @@ void ElementsMover::endMovement()
|
|||||||
QPair <Terminal *, Terminal *> pair = elmt -> AlignedFreeTerminals().takeFirst();
|
QPair <Terminal *, Terminal *> pair = elmt -> AlignedFreeTerminals().takeFirst();
|
||||||
|
|
||||||
Conductor *conductor = new Conductor(pair.first, pair.second);
|
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
|
//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
|
//Else the first undo for this auto conductor become the undo_object
|
||||||
@@ -155,9 +154,31 @@ void ElementsMover::endMovement()
|
|||||||
else
|
else
|
||||||
undo_object = new AddItemCommand<Conductor *>(conductor, diagram_, QPointF());
|
undo_object = new AddItemCommand<Conductor *>(conductor, diagram_, QPointF());
|
||||||
|
|
||||||
//Autonum the new conductor, the undo command associated for this, have for parent undo_object
|
//Get all conductors at the same potential of conductor
|
||||||
ConductorAutoNumerotation can (conductor, diagram_, undo_object);
|
QSet <Conductor *> conductors_list = conductor->relatedPotentialConductors();
|
||||||
can.numerate();
|
|
||||||
|
//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();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -582,35 +582,59 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
|
|||||||
previous_terminal_ = 0;
|
previous_terminal_ = 0;
|
||||||
hovered_color_ = neutralColor;
|
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
|
use_properties = true;
|
||||||
d -> setConductor(false);
|
others_properties = (*conductors_list.begin())->properties();
|
||||||
|
foreach (Conductor *conductor, conductors_list)
|
||||||
//Get item under cursor
|
if (conductor->properties() != others_properties)
|
||||||
QGraphicsItem *qgi = d -> itemAt(e -> scenePos(), QTransform());
|
use_properties = false;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user