Multipaste : improve the conductor autonum, conductors are numerated from top to bottom, and left to right

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5340 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2018-04-24 17:23:27 +00:00
parent 9d2124f593
commit c96593e373
2 changed files with 99 additions and 61 deletions

View File

@@ -249,10 +249,19 @@ QList<Terminal *> CustomElement::terminals() const {
return(m_terminals); 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; QList<Conductor *> conductors;
foreach(Terminal *t, m_terminals) conductors << t -> conductors();
for(Terminal *t : m_terminals)
conductors << t -> conductors();
return(conductors); return(conductors);
} }
@@ -803,6 +812,16 @@ Terminal *CustomElement::parseTerminal(QDomElement &e) {
Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this); 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 new_terminal -> setZValue(420); // valeur arbitraire pour maintenir les bornes au-dessus des champs de texte
m_terminals << new_terminal; 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); return(new_terminal);
} }

View File

@@ -72,6 +72,7 @@ void MultiPasteDialog::updatePreview()
} }
} }
m_pasted_content.clear(); m_pasted_content.clear();
m_pasted_content_list.clear();
QPointF offset(ui->m_x_sb->value(), ui->m_y_sb->value()); QPointF offset(ui->m_x_sb->value(), ui->m_y_sb->value());
QPointF pos = m_origin+offset; QPointF pos = m_origin+offset;
@@ -82,6 +83,7 @@ void MultiPasteDialog::updatePreview()
m_diagram->fromXml(m_document, pos, false, &dc); m_diagram->fromXml(m_document, pos, false, &dc);
m_pasted_content += dc; m_pasted_content += dc;
m_pasted_content_list << dc;
pos += offset; pos += offset;
} }
@@ -109,10 +111,16 @@ void MultiPasteDialog::on_m_button_box_accepted()
m_diagram->clearSelection(); m_diagram->clearSelection();
m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, m_pasted_content)); m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, m_pasted_content));
for(DiagramContent dc : m_pasted_content_list)
{
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 //Auto-connection
if(ui->m_auto_connection_cb->isChecked()) if(ui->m_auto_connection_cb->isChecked())
{ {
for(Element *elmt : m_pasted_content.m_elements) for(Element *elmt : pasted_elements)
{ {
while (!elmt->AlignedFreeTerminals().isEmpty()) while (!elmt->AlignedFreeTerminals().isEmpty())
{ {
@@ -137,7 +145,7 @@ void MultiPasteDialog::on_m_button_box_accepted()
//for apply the good formula for each elements //for apply the good formula for each elements
if(ui->m_auto_num_cb->isChecked()) if(ui->m_auto_num_cb->isChecked())
{ {
for(Element *elmt : m_pasted_content.m_elements) for(Element *elmt : pasted_elements)
{ {
QString formula = elmt->elementInformations()["formula"].toString(); QString formula = elmt->elementInformations()["formula"].toString();
if(!formula.isEmpty()) if(!formula.isEmpty())
@@ -160,8 +168,17 @@ void MultiPasteDialog::on_m_button_box_accepted()
//Like elements, we compare formula of pasted conductor with the autonums available in the project. //Like elements, we compare formula of pasted conductor with the autonums available in the project.
if(ui->m_auto_num_cond_cb->isChecked()) if(ui->m_auto_num_cond_cb->isChecked())
{ {
for(Conductor *c : m_pasted_content.conductors()) //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)
{ {
for(Conductor *c : elmt->conductors())
{
if(numerated.contains(c))
continue;
else
numerated << c;
QString formula = c->properties().m_formula; QString formula = c->properties().m_formula;
if(!formula.isEmpty()) if(!formula.isEmpty())
{ {
@@ -186,6 +203,8 @@ void MultiPasteDialog::on_m_button_box_accepted()
} }
} }
} }
}
}
m_diagram->adjustSceneRect(); m_diagram->adjustSceneRect();
m_accept = true; m_accept = true;