mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Simplification du code permettant la mise a jour des conducteurs lors des deplacements et rotations d'elements.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@984 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
b073351872
commit
f610efef8d
@ -134,18 +134,10 @@ void Conductor::update(const QRectF &rect) {
|
||||
@param b Borne
|
||||
@param newpos position de la borne b
|
||||
*/
|
||||
void Conductor::updateWithNewPos(const QRectF &rect, const Terminal *b, const QPointF &newpos) {
|
||||
void Conductor::updateWithNewPos(const QRectF &rect) {
|
||||
QPointF p1, p2;
|
||||
if (b == terminal1) {
|
||||
p1 = newpos;
|
||||
p2 = terminal2 -> dockConductor();
|
||||
} else if (b == terminal2) {
|
||||
p1 = terminal1 -> dockConductor();
|
||||
p2 = newpos;
|
||||
} else {
|
||||
p1 = terminal1 -> dockConductor();
|
||||
p2 = terminal2 -> dockConductor();
|
||||
}
|
||||
if (nbSegments() && !conductor_profiles[currentPathType()].isNull())
|
||||
priv_modifieConductor(p1, terminal1 -> orientation(), p2, terminal2 -> orientation());
|
||||
else
|
||||
|
@ -61,7 +61,7 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
||||
/// @return true si ce conducteur est detruit
|
||||
bool isDestroyed() const { return(destroyed); }
|
||||
Diagram *diagram() const;
|
||||
void updateWithNewPos(const QRectF &, const Terminal *, const QPointF &);
|
||||
void updateWithNewPos(const QRectF &);
|
||||
void update(const QRectF & = QRectF());
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||
QRectF boundingRect() const;
|
||||
|
@ -845,7 +845,7 @@ void Diagram::fetchMovedElements() {
|
||||
if (elements_to_move.contains(other_terminal -> parentElement())) {
|
||||
conductors_to_move << conductor;
|
||||
} else {
|
||||
conductors_to_update.insert(conductor, terminal);
|
||||
conductors_to_update << conductor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -879,9 +879,8 @@ void Diagram::moveElements(const QPointF &diff, QGraphicsItem *dontmove) {
|
||||
}
|
||||
|
||||
// recalcule les autres conducteurs
|
||||
const QHash<Conductor *, Terminal *> &conductors_modify = conductorsToUpdate();
|
||||
foreach(Conductor *conductor, conductors_modify.keys()) {
|
||||
conductor -> updateWithNewPos(QRectF(), conductors_modify[conductor], conductors_modify[conductor] -> dockConductor());
|
||||
foreach(Conductor *conductor, conductorsToUpdate()) {
|
||||
conductor -> updateWithNewPos(QRectF());
|
||||
}
|
||||
|
||||
// deplace les champs de texte
|
||||
@ -1090,7 +1089,7 @@ DiagramContent Diagram::selectedContent() {
|
||||
dc.elements = elementsToMove().toList();
|
||||
dc.textFields = independentTextsToMove().toList();
|
||||
dc.conductorsToMove = conductorsToMove().toList();
|
||||
dc.conductorsToUpdate = conductorsToUpdate();
|
||||
dc.conductorsToUpdate = conductorsToUpdate().toList();
|
||||
|
||||
// recupere les conducteurs selectionnes isoles (= non deplacables mais supprimables)
|
||||
foreach(QGraphicsItem *qgi, items()) {
|
||||
|
@ -79,7 +79,7 @@ class Diagram : public QGraphicsScene {
|
||||
bool moved_elements_fetched;
|
||||
QSet<Element *> elements_to_move;
|
||||
QSet<Conductor *> conductors_to_move;
|
||||
QHash<Conductor *, Terminal *> conductors_to_update;
|
||||
QSet<Conductor *> conductors_to_update;
|
||||
QSet<IndependentTextItem *> texts_to_move;
|
||||
QSet<ElementTextItem *> elements_texts_to_move;
|
||||
QGIManager *qgi_manager;
|
||||
@ -158,7 +158,7 @@ class Diagram : public QGraphicsScene {
|
||||
void fetchMovedElements();
|
||||
const QSet<Element *> &elementsToMove();
|
||||
const QSet<Conductor *> &conductorsToMove();
|
||||
const QHash<Conductor *, Terminal *> &conductorsToUpdate();
|
||||
const QSet<Conductor *> &conductorsToUpdate();
|
||||
const QSet<IndependentTextItem *> &independentTextsToMove();
|
||||
const QSet<ElementTextItem *> &elementTextsToMove();
|
||||
QSet<DiagramTextItem *> selectedTexts() const;
|
||||
@ -285,7 +285,7 @@ inline const QSet<Conductor *> &Diagram::conductorsToMove() {
|
||||
}
|
||||
|
||||
/// @return la liste des conducteurs a modifier (typiquement les conducteurs dont seul un element est deplace)
|
||||
inline const QHash<Conductor *, Terminal *> &Diagram::conductorsToUpdate() {
|
||||
inline const QSet<Conductor *> &Diagram::conductorsToUpdate() {
|
||||
if (!moved_elements_fetched) fetchMovedElements();
|
||||
return(conductors_to_update);
|
||||
}
|
||||
|
@ -353,12 +353,8 @@ void MoveElementsCommand::move(const QPointF &actual_movement) {
|
||||
}
|
||||
|
||||
// recalcule les autres conducteurs
|
||||
foreach(Conductor *conductor, content_to_move.conductorsToUpdate.keys()) {
|
||||
conductor -> updateWithNewPos(
|
||||
QRectF(),
|
||||
content_to_move.conductorsToUpdate[conductor],
|
||||
content_to_move.conductorsToUpdate[conductor] -> dockConductor()
|
||||
);
|
||||
foreach(Conductor *conductor, content_to_move.conductorsToUpdate) {
|
||||
conductor -> updateWithNewPos(QRectF());
|
||||
}
|
||||
|
||||
// deplace les textes
|
||||
|
@ -52,7 +52,7 @@ DiagramContent::~DiagramContent() {
|
||||
QList<Conductor *> DiagramContent::conductors(int filter) const {
|
||||
QList<Conductor *> result;
|
||||
if (filter & ConductorsToMove) result += conductorsToMove;
|
||||
if (filter & ConductorsToUpdate) result += conductorsToUpdate.keys();
|
||||
if (filter & ConductorsToUpdate) result += conductorsToUpdate;
|
||||
if (filter & OtherConductors) result += otherConductors;
|
||||
if (filter & SelectedOnly) {
|
||||
foreach(Conductor *conductor, result) {
|
||||
@ -100,7 +100,7 @@ int DiagramContent::count(int filter) const {
|
||||
if (filter & Elements) foreach(Element *element, elements) { if (element -> isSelected()) ++ count; }
|
||||
if (filter & TextFields) foreach(DiagramTextItem *dti, textFields) { if (dti -> isSelected()) ++ count; }
|
||||
if (filter & ConductorsToMove) foreach(Conductor *conductor, conductorsToMove) { if (conductor -> isSelected()) ++ count; }
|
||||
if (filter & ConductorsToUpdate) foreach(Conductor *conductor, conductorsToUpdate.keys()) { if (conductor -> isSelected()) ++ count; }
|
||||
if (filter & ConductorsToUpdate) foreach(Conductor *conductor, conductorsToUpdate) { if (conductor -> isSelected()) ++ count; }
|
||||
if (filter & OtherConductors) foreach(Conductor *conductor, otherConductors) { if (conductor -> isSelected()) ++ count; }
|
||||
} else {
|
||||
if (filter & Elements) count += elements.count();
|
||||
@ -143,7 +143,7 @@ QDebug &operator<<(QDebug d, DiagramContent &content) {
|
||||
/*
|
||||
FIXME Le double-heritage QObject / QGraphicsItem a casse cet operateur
|
||||
d << " elements :" << c.elements << "\n";
|
||||
d << " conductorsToUpdate :" << c.conductorsToUpdate.keys() << "\n";
|
||||
d << " conductorsToUpdate :" << c.conductorsToUpdate << "\n";
|
||||
d << " conductorsToMove :" << c.conductorsToMove << "\n";
|
||||
d << " otherConductors :" << c.otherConductors << "\n";
|
||||
*/
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <QtGui>
|
||||
class Conductor;
|
||||
class Element;
|
||||
class Terminal;
|
||||
class IndependentTextItem;
|
||||
/**
|
||||
Cette classe est un conteneur pour passer facilement le contenu d'un schema
|
||||
@ -55,7 +54,7 @@ class DiagramContent {
|
||||
/// Champs de texte independants du schema
|
||||
QList<IndependentTextItem *> textFields;
|
||||
/// Conducteurs a mettre a jour du schema
|
||||
QHash<Conductor *, Terminal *> conductorsToUpdate;
|
||||
QList<Conductor *> conductorsToUpdate;
|
||||
/// Conducteurs a deplacer du schema
|
||||
QList<Conductor *> conductorsToMove;
|
||||
/// Conducteurs isoles (ni a deplacer, ni a mettre a jour)
|
||||
|
@ -372,20 +372,14 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
}
|
||||
|
||||
/**
|
||||
Met a jour l'eventuel conducteur relie a la Terminal.
|
||||
Met a jour l'eventuel conducteur relie a la borne.
|
||||
@param newpos Position de l'element parent a prendre en compte
|
||||
*/
|
||||
void Terminal::updateConductor(QPointF newpos) {
|
||||
void Terminal::updateConductor() {
|
||||
if (!scene() || !parentItem()) return;
|
||||
foreach (Conductor *conductor, conductors_) {
|
||||
if (conductor -> isDestroyed()) continue;
|
||||
if (newpos == QPointF()) conductor -> update(QRectF());
|
||||
else {
|
||||
// determine la translation subie par l'element parent
|
||||
QPointF translation = newpos - parentItem() -> pos();
|
||||
// rafraichit le conducteur en tenant compte de la translation
|
||||
conductor -> updateWithNewPos(QRectF(), this, dockConductor() + translation);
|
||||
}
|
||||
conductor -> update(QRectF());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ class Terminal : public QGraphicsItem {
|
||||
QList<Conductor *> conductors() const;
|
||||
QET::Orientation orientation() const;
|
||||
QPointF dockConductor() const;
|
||||
void updateConductor(QPointF = QPointF());
|
||||
void updateConductor();
|
||||
bool isLinkedTo(Terminal *);
|
||||
bool canBeLinkedTo(Terminal *);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user