[qet] qet/qet: [5340] Multipaste : improve the conductor autonum, conductors are numerated from top to bottom, and left to right |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5340
Author: blacksun
Date: 2018-04-24 19:23:27 +0200 (Tue, 24 Apr 2018)
Log Message:
-----------
Multipaste : improve the conductor autonum, conductors are numerated from top to bottom, and left to right
Modified Paths:
--------------
trunk/sources/qetgraphicsitem/customelement.cpp
trunk/sources/ui/multipastedialog.cpp
Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp 2018-04-23 13:50:36 UTC (rev 5339)
+++ trunk/sources/qetgraphicsitem/customelement.cpp 2018-04-24 17:23:27 UTC (rev 5340)
@@ -249,10 +249,19 @@
return(m_terminals);
}
-/// @return la liste des conducteurs rattaches a cet element
-QList<Conductor *> CustomElement::conductors() const {
+/**
+ * @brief CustomElement::conductors
+ * @return The list of conductor docked to this element
+ * the list is sorted according to the position of the terminal where the conductor is docked
+ * from top to bottom, and left to right.
+ */
+QList<Conductor *> CustomElement::conductors() const
+{
QList<Conductor *> conductors;
- foreach(Terminal *t, m_terminals) conductors << t -> conductors();
+
+ for(Terminal *t : m_terminals)
+ conductors << t -> conductors();
+
return(conductors);
}
@@ -803,6 +812,16 @@
Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this);
new_terminal -> setZValue(420); // valeur arbitraire pour maintenir les bornes au-dessus des champs de texte
m_terminals << new_terminal;
+
+ //Sort from top to bottom and left to rigth
+ std::sort(m_terminals.begin(), m_terminals.end(), [](Terminal *a, Terminal *b)
+ {
+ if(a->dockConductor().y() == b->dockConductor().y())
+ return (a->dockConductor().x() < b->dockConductor().x());
+ else
+ return (a->dockConductor().y() < b->dockConductor().y());
+ });
+
return(new_terminal);
}
Modified: trunk/sources/ui/multipastedialog.cpp
===================================================================
--- trunk/sources/ui/multipastedialog.cpp 2018-04-23 13:50:36 UTC (rev 5339)
+++ trunk/sources/ui/multipastedialog.cpp 2018-04-24 17:23:27 UTC (rev 5340)
@@ -72,6 +72,7 @@
}
}
m_pasted_content.clear();
+ m_pasted_content_list.clear();
QPointF offset(ui->m_x_sb->value(), ui->m_y_sb->value());
QPointF pos = m_origin+offset;
@@ -82,6 +83,7 @@
m_diagram->fromXml(m_document, pos, false, &dc);
m_pasted_content += dc;
+ m_pasted_content_list << dc;
pos += offset;
}
@@ -109,77 +111,94 @@
m_diagram->clearSelection();
m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, m_pasted_content));
- //Auto-connection
- if(ui->m_auto_connection_cb->isChecked())
+ for(DiagramContent dc : m_pasted_content_list)
{
- for(Element *elmt : m_pasted_content.m_elements)
+ QList<Element *> pasted_elements = dc.m_elements;
+ //Sort the list element by there pos (top -> bottom)
+ std::sort(pasted_elements.begin(), pasted_elements.end(), [](Element *a, Element *b){return (a->pos().y() < b->pos().y());});
+
+ //Auto-connection
+ if(ui->m_auto_connection_cb->isChecked())
{
- while (!elmt->AlignedFreeTerminals().isEmpty())
+ for(Element *elmt : pasted_elements)
{
- QPair <Terminal *, Terminal *> pair = elmt->AlignedFreeTerminals().takeFirst();
-
- Conductor *conductor = new Conductor(pair.first, pair.second);
- m_diagram->undoStack().push(new AddItemCommand<Conductor *>(conductor, m_diagram, QPointF()));
-
+ while (!elmt->AlignedFreeTerminals().isEmpty())
+ {
+ QPair <Terminal *, Terminal *> pair = elmt->AlignedFreeTerminals().takeFirst();
+
+ Conductor *conductor = new Conductor(pair.first, pair.second);
+ m_diagram->undoStack().push(new AddItemCommand<Conductor *>(conductor, m_diagram, QPointF()));
+
//Autonum the new conductor, the undo command associated for this, have for parent undo_object
- ConductorAutoNumerotation can (conductor, m_diagram);
- can.numerate();
- if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors()) {
- conductor->setFreezeLabel(true);
+ ConductorAutoNumerotation can (conductor, m_diagram);
+ can.numerate();
+ if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors()) {
+ conductor->setFreezeLabel(true);
+ }
}
}
}
- }
-
- //Set up the label of element
- //Instead of use the current autonum of project,
- //we try to fetch the same formula of the pasted element, in the several autonum of the project
- //for apply the good formula for each elements
- if(ui->m_auto_num_cb->isChecked())
- {
- for(Element *elmt : m_pasted_content.m_elements)
+
+ //Set up the label of element
+ //Instead of use the current autonum of project,
+ //we try to fetch the same formula of the pasted element, in the several autonum of the project
+ //for apply the good formula for each elements
+ if(ui->m_auto_num_cb->isChecked())
{
- QString formula = elmt->elementInformations()["formula"].toString();
- if(!formula.isEmpty())
+ for(Element *elmt : pasted_elements)
{
- QHash <QString, NumerotationContext> autonums = m_diagram->project()->elementAutoNum();
- QHashIterator<QString, NumerotationContext> hash_iterator(autonums);
-
- while(hash_iterator.hasNext())
+ QString formula = elmt->elementInformations()["formula"].toString();
+ if(!formula.isEmpty())
{
- hash_iterator.next();
- if(autonum::numerotationContextToFormula(hash_iterator.value()) == formula)
+ QHash <QString, NumerotationContext> autonums = m_diagram->project()->elementAutoNum();
+ QHashIterator<QString, NumerotationContext> hash_iterator(autonums);
+
+ while(hash_iterator.hasNext())
{
- m_diagram->project()->setCurrrentElementAutonum(hash_iterator.key());
- elmt->setUpFormula();
+ hash_iterator.next();
+ if(autonum::numerotationContextToFormula(hash_iterator.value()) == formula)
+ {
+ m_diagram->project()->setCurrrentElementAutonum(hash_iterator.key());
+ elmt->setUpFormula();
+ }
}
}
}
}
- }
- //Like elements, we compare formula of pasted conductor with the autonums available in the project.
- if(ui->m_auto_num_cond_cb->isChecked())
- {
- for(Conductor *c : m_pasted_content.conductors())
- {
- QString formula = c->properties().m_formula;
- if(!formula.isEmpty())
+ //Like elements, we compare formula of pasted conductor with the autonums available in the project.
+ if(ui->m_auto_num_cond_cb->isChecked())
+ {
+ //This list is to ensure we not numerate twice the same conductor
+ QList<Conductor *> numerated;
+ //Start with the element at top
+ for(Element *elmt : pasted_elements)
{
- QHash <QString, NumerotationContext> autonums = m_diagram->project()->conductorAutoNum();
- QHashIterator <QString, NumerotationContext> hash_iterator(autonums);
-
- while (hash_iterator.hasNext())
+ for(Conductor *c : elmt->conductors())
{
- hash_iterator.next();
- if(autonum::numerotationContextToFormula(hash_iterator.value()) == formula)
+ if(numerated.contains(c))
+ continue;
+ else
+ numerated << c;
+ QString formula = c->properties().m_formula;
+ if(!formula.isEmpty())
{
- m_diagram->project()->setCurrentConductorAutoNum(hash_iterator.key());
- c->rSequenceNum().clear();
- ConductorAutoNumerotation can(c, m_diagram);
- can.numerate();
- if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors())
+ QHash <QString, NumerotationContext> autonums = m_diagram->project()->conductorAutoNum();
+ QHashIterator <QString, NumerotationContext> hash_iterator(autonums);
+
+ while (hash_iterator.hasNext())
{
- c->setFreezeLabel(true);
+ hash_iterator.next();
+ if(autonum::numerotationContextToFormula(hash_iterator.value()) == formula)
+ {
+ m_diagram->project()->setCurrentConductorAutoNum(hash_iterator.key());
+ c->rSequenceNum().clear();
+ ConductorAutoNumerotation can(c, m_diagram);
+ can.numerate();
+ if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors())
+ {
+ c->setFreezeLabel(true);
+ }
+ }
}
}
}