mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-06 13:40:52 +01:00
Finish a move element with free terminal aligned with other terminal from other element, will create auto creation of conductor
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3594 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1380,15 +1380,6 @@ void Conductor::setHighlighted(Conductor::Highlight hl) {
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Conductor::autoText
|
||||
*lance l'autoNumerotation sur ce conducteur
|
||||
*/
|
||||
void Conductor::autoText() {
|
||||
ConductorAutoNumerotation can(this);
|
||||
can.numerate();
|
||||
}
|
||||
|
||||
/**
|
||||
Met a jour les proprietes du conducteur apres modification du champ de texte affiche
|
||||
*/
|
||||
@@ -1396,21 +1387,26 @@ void Conductor::displayedTextChanged() {
|
||||
// verifie que le texte a reellement change
|
||||
if (text_item -> toPlainText() == properties_.text) return;
|
||||
|
||||
if (Diagram *my_diagram = diagram()) {
|
||||
if (Diagram *my_diagram = diagram())
|
||||
{
|
||||
int qmbreturn=0;
|
||||
//if conductor isn't alone at this potential
|
||||
//ask user to apply text on every conductors of this potential
|
||||
if (relatedPotentialConductors().size() >= 1){
|
||||
//if conductor isn't alone at this potential
|
||||
//ask user to apply text on every conductors of this potential
|
||||
if (relatedPotentialConductors().size() >= 1)
|
||||
{
|
||||
qmbreturn = QMessageBox::question(diagramEditor(), tr("Textes de conducteurs"),
|
||||
tr("Voulez-vous appliquer le nouveau texte \n"
|
||||
"\340 l'ensemble des conducteurs de ce potentiel ?"),
|
||||
QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes);
|
||||
if (qmbreturn == QMessageBox::Yes){
|
||||
ConductorAutoNumerotation can(this);
|
||||
if (qmbreturn == QMessageBox::Yes)
|
||||
{
|
||||
ConductorAutoNumerotation can(this, my_diagram);
|
||||
can.applyText(text_item -> toPlainText());
|
||||
}
|
||||
}
|
||||
if (qmbreturn == 0 || qmbreturn == QMessageBox::No) {
|
||||
|
||||
if (qmbreturn == 0 || qmbreturn == QMessageBox::No)
|
||||
{
|
||||
// initialise l'objet UndoCommand correspondant
|
||||
ConductorProperties new_properties(properties_);
|
||||
new_properties.text = text_item -> toPlainText();
|
||||
|
||||
@@ -112,7 +112,6 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
||||
void calculateTextItemPosition();
|
||||
virtual Highlight highlight() const;
|
||||
virtual void setHighlighted(Highlight);
|
||||
void autoText();
|
||||
QSet<Conductor *> relatedPotentialConductors(const bool all_diagram = true, QList <Terminal *> *t_list=0);
|
||||
QETDiagramEditor* diagramEditor() const;
|
||||
void editProperty ();
|
||||
|
||||
@@ -494,6 +494,31 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
||||
return(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Element::AlignedFreeTerminals
|
||||
* @return a list of terminal (owned by this element) aligned to other terminal (from other element)
|
||||
* The first Terminal of QPair is a Terminal owned by this element,
|
||||
* this terminal haven't got any conductor docked.
|
||||
* The second Terminal of QPair is a Terminal owned by an other element,
|
||||
* which is aligned with the first Terminal. The second Terminal can have or not docked conductors.
|
||||
*/
|
||||
QList <QPair <Terminal *, Terminal *> > Element::AlignedFreeTerminals() const
|
||||
{
|
||||
QList <QPair <Terminal *, Terminal *> > list;
|
||||
|
||||
foreach (Terminal *terminal, terminals())
|
||||
{
|
||||
if (terminal->conductors().isEmpty())
|
||||
{
|
||||
Terminal *other_terminal = terminal -> alignedWithTerminal();
|
||||
if (other_terminal)
|
||||
list << qMakePair(terminal, other_terminal);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Element::initLink
|
||||
* Initialise the link between this element and other elements.
|
||||
@@ -549,6 +574,10 @@ bool comparPos(const Element *elmt1, const Element *elmt2) {
|
||||
return elmt1->pos().x() <= elmt2->pos().x();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Element::mouseMoveEvent
|
||||
* @param event
|
||||
*/
|
||||
void Element::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QetGraphicsItem::mouseMoveEvent(event);
|
||||
@@ -558,6 +587,10 @@ void Element::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Element::mouseReleaseEvent
|
||||
* @param event
|
||||
*/
|
||||
void Element::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QetGraphicsItem::mouseReleaseEvent(event);
|
||||
|
||||
@@ -94,6 +94,7 @@ class Element : public QetGraphicsItem {
|
||||
/// @return the maximum number of terminals for this element
|
||||
virtual int maxTerminalsCount() const = 0;
|
||||
|
||||
QList <QPair <Terminal *, Terminal *> > AlignedFreeTerminals () const;
|
||||
|
||||
/**
|
||||
*related method and attributes,
|
||||
@@ -121,7 +122,7 @@ class Element : public QetGraphicsItem {
|
||||
signals:
|
||||
void elementInfoChange(DiagramContext old_info, DiagramContext new_info);
|
||||
|
||||
//METHODS related to information
|
||||
//METHODS related to information
|
||||
public:
|
||||
DiagramContext elementInformations ()const {return element_informations_;}
|
||||
DiagramContext& rElementInformations () {return element_informations_;}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "qetgraphicsitem/conductor.h"
|
||||
#include "diagramcommands.h"
|
||||
#include "qetapp.h"
|
||||
#include "conductorautonumerotation.h"
|
||||
|
||||
QColor Terminal::neutralColor = QColor(Qt::blue);
|
||||
QColor Terminal::allowedColor = QColor(Qt::darkGreen);
|
||||
@@ -527,35 +528,44 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
other_terminal -> update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Gere le fait qu'on relache la souris sur la Borne.
|
||||
@param e L'evenement souris correspondant
|
||||
*/
|
||||
void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
//setCursor(Qt::ArrowCursor);
|
||||
* @brief Terminal::mouseReleaseEvent
|
||||
* @param e
|
||||
*/
|
||||
void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
|
||||
{
|
||||
previous_terminal_ = 0;
|
||||
hovered_color_ = neutralColor;
|
||||
// verifie que la scene est bien un Diagram
|
||||
if (Diagram *d = diagram()) {
|
||||
// on arrete de dessiner l'apercu du conducteur
|
||||
hovered_color_ = neutralColor;
|
||||
|
||||
if (Diagram *d = diagram())
|
||||
{
|
||||
//Stop conductor preview
|
||||
d -> setConductor(false);
|
||||
// on recupere l'element sous le pointeur lors du MouseReleaseEvent
|
||||
|
||||
//Get item under cursor
|
||||
QGraphicsItem *qgi = d -> itemAt(e -> scenePos());
|
||||
// s'il n'y a rien, on arrete la
|
||||
if (!qgi) return;
|
||||
// idem si l'element obtenu n'est pas une borne
|
||||
|
||||
//Element must be a terminal
|
||||
Terminal *other_terminal = qgraphicsitem_cast<Terminal *>(qgi);
|
||||
if (!other_terminal) return;
|
||||
// on remet la couleur de hover a sa valeur par defaut
|
||||
|
||||
other_terminal -> hovered_color_ = neutralColor;
|
||||
other_terminal -> hovered_ = false;
|
||||
// on s'arrete la s'il n'est pas possible de relier les bornes
|
||||
other_terminal -> hovered_ = false;
|
||||
|
||||
//We stop her if we can't link this terminal with other terminal
|
||||
if (!canBeLinkedTo(other_terminal)) return;
|
||||
// autrement, on pose un conducteur
|
||||
|
||||
//Create conductor
|
||||
Conductor *new_conductor = new Conductor(this, other_terminal);
|
||||
new_conductor -> setProperties(d -> defaultConductorProperties);
|
||||
d -> undoStack().push(new AddItemCommand<Conductor *>(new_conductor, d));
|
||||
new_conductor -> autoText();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user