diff --git a/sources/diagram.cpp b/sources/diagram.cpp index dbf91af28..5327f597b 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -1000,7 +1000,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf // remplissage des listes facultatives if (content_ptr) { content_ptr -> m_elements = added_elements; - content_ptr -> m_conductors_to_move = added_conductors.toSet(); + content_ptr -> m_conductors_to_move = added_conductors; content_ptr -> m_text_fields = added_texts.toSet(); content_ptr -> m_images = added_images.toSet(); content_ptr -> m_shapes = added_shapes.toSet(); diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index c952a0844..09c5609b5 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -109,7 +109,7 @@ void PasteDiagramCommand::redo() e -> rElementInformations().addValue("location", ""); //Reset the text of conductors - const QList conductors_list = content.m_conductors_to_move.toList(); + const QList conductors_list = content.m_conductors_to_move; for (Conductor *c : conductors_list) { ConductorProperties cp = c -> properties(); diff --git a/sources/diagramcontent.cpp b/sources/diagramcontent.cpp index 67379cab5..f05469659 100644 --- a/sources/diagramcontent.cpp +++ b/sources/diagramcontent.cpp @@ -81,9 +81,9 @@ DiagramContent::DiagramContent(Diagram *diagram) : other_terminal = conductor->terminal1; //If the two elements of conductor are movable - if (m_elements.contains(other_terminal -> parentElement())) + if (m_elements.contains(other_terminal -> parentElement()) && !m_conductors_to_move.contains(conductor)) m_conductors_to_move << conductor; - else + else if (!m_conductors_to_update.contains(conductor)) m_conductors_to_update << conductor; } } @@ -160,16 +160,18 @@ QList DiagramContent::selectedTextsGroup() const */ QList DiagramContent::conductors(int filter) const { - QSet result; + QList result; if (filter & ConductorsToMove) result += m_conductors_to_move; if (filter & ConductorsToUpdate) result += m_conductors_to_update; if (filter & OtherConductors) result += m_other_conductors; if (filter & SelectedOnly) { - for(Conductor *conductor : result) { - if (!conductor->isSelected()) result.remove(conductor); + for(Conductor *conductor : result) + { + if (!conductor->isSelected()) + result.removeAll(conductor); } } - return(result.toList()); + return(result); } /** diff --git a/sources/diagramcontent.h b/sources/diagramcontent.h index 0ed5e54db..feb6cefe0 100644 --- a/sources/diagramcontent.h +++ b/sources/diagramcontent.h @@ -68,9 +68,9 @@ class DiagramContent QSet m_text_fields; QSet m_images; QSet m_shapes; - QSet m_conductors_to_update; - QSet m_conductors_to_move; - QSet m_other_conductors; + QList m_conductors_to_update; + QList m_conductors_to_move; + QList m_other_conductors; QSet m_element_texts; QSet m_texts_groups; QList m_selected_items; diff --git a/sources/elementsmover.cpp b/sources/elementsmover.cpp index 3fc59def3..bd12740bd 100644 --- a/sources/elementsmover.cpp +++ b/sources/elementsmover.cpp @@ -194,4 +194,5 @@ void ElementsMover::endMovement() // There is no movement in progress now movement_running_ = false; + m_moved_content.clear(); } diff --git a/sources/ui/multipastedialog.cpp b/sources/ui/multipastedialog.cpp index 61547329c..a1e82b6af 100644 --- a/sources/ui/multipastedialog.cpp +++ b/sources/ui/multipastedialog.cpp @@ -1,3 +1,20 @@ +/* + Copyright 2006-2018 The QElectroTech team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ #include "multipastedialog.h" #include "ui_multipastedialog.h" #include "diagram.h" @@ -76,6 +93,8 @@ void MultiPasteDialog::on_m_button_box_accepted() { if(m_pasted_content.count()) { + m_diagram->undoStack().beginMacro(tr("Multi-collage")); + QSettings settings; bool erase_label = settings.value("diagramcommands/erase-label-on-copy", true).toBool(); //Ensure when 'auto_num' is checked, the settings 'save_label' is to true. @@ -88,9 +107,7 @@ void MultiPasteDialog::on_m_button_box_accepted() m_diagram->clearSelection(); - - QUndoCommand *undo = new QUndoCommand(tr("Multi-collage")); - new PasteDiagramCommand(m_diagram, m_pasted_content, undo); + m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, m_pasted_content)); //Auto-connection if(ui->m_auto_connection_cb->isChecked()) @@ -102,10 +119,10 @@ void MultiPasteDialog::on_m_button_box_accepted() QPair pair = elmt->AlignedFreeTerminals().takeFirst(); Conductor *conductor = new Conductor(pair.first, pair.second); - new AddItemCommand(conductor, m_diagram, QPointF(), undo); + m_diagram->undoStack().push(new AddItemCommand(conductor, m_diagram, QPointF())); //Autonum the new conductor, the undo command associated for this, have for parent undo_object - ConductorAutoNumerotation can (conductor, m_diagram, undo); + ConductorAutoNumerotation can (conductor, m_diagram); can.numerate(); if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors()) { conductor->setFreezeLabel(true); @@ -114,8 +131,6 @@ void MultiPasteDialog::on_m_button_box_accepted() } } - m_diagram->undoStack().push(undo); - //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 @@ -142,8 +157,39 @@ void MultiPasteDialog::on_m_button_box_accepted() } } } + //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()) + { + QHash autonums = m_diagram->project()->conductorAutoNum(); + QHashIterator hash_iterator(autonums); + + while (hash_iterator.hasNext()) + { + 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); + } + } + } + } + } + } + m_diagram->adjustSceneRect(); m_accept = true; settings.setValue("diagramcommands/erase-label-on-copy", erase_label); + m_diagram->undoStack().endMacro(); } } diff --git a/sources/ui/multipastedialog.h b/sources/ui/multipastedialog.h index 2767e759d..f27e16b46 100644 --- a/sources/ui/multipastedialog.h +++ b/sources/ui/multipastedialog.h @@ -1,3 +1,20 @@ +/* + Copyright 2006-2018 The QElectroTech team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ #ifndef MULTIPASTEDIALOG_H #define MULTIPASTEDIALOG_H @@ -16,14 +33,14 @@ class MultiPasteDialog : public QDialog Q_OBJECT public: - explicit MultiPasteDialog(Diagram *diagram, QWidget *parent = 0); + explicit MultiPasteDialog(Diagram *diagram, QWidget *parent = nullptr); ~MultiPasteDialog(); void updatePreview(); - private slots: + private slots: void on_m_button_box_accepted(); - private: + private: Ui::MultiPasteDialog *ui; Diagram *m_diagram = nullptr; DiagramContent m_pasted_content; diff --git a/sources/ui/multipastedialog.ui b/sources/ui/multipastedialog.ui index 03d0ad692..49edbc07f 100644 --- a/sources/ui/multipastedialog.ui +++ b/sources/ui/multipastedialog.ui @@ -101,6 +101,13 @@ + + + + Auto-numérotation des conducteurs + + +