diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 5939d9541..dbf91af28 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -999,7 +999,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf // remplissage des listes facultatives if (content_ptr) { - content_ptr -> m_elements = added_elements.toSet(); + content_ptr -> m_elements = added_elements; content_ptr -> m_conductors_to_move = added_conductors.toSet(); content_ptr -> m_text_fields = added_texts.toSet(); content_ptr -> m_images = added_images.toSet(); diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index d7946c23d..7266b7325 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -94,7 +94,7 @@ void PasteDiagramCommand::redo() first_redo = false; //this is the first paste, we do some actions for the new element - const QList elmts_list = content.m_elements.toList(); + const QList elmts_list = content.m_elements; for (Element *e : elmts_list) { //make new uuid, because old uuid are the uuid of the copied element diff --git a/sources/diagramcontent.cpp b/sources/diagramcontent.cpp index 6f11f1ab3..67379cab5 100644 --- a/sources/diagramcontent.cpp +++ b/sources/diagramcontent.cpp @@ -238,10 +238,10 @@ int DiagramContent::removeNonMovableItems() { int count_ = 0; - const QSet elements_set = m_elements; + const QList elements_set = m_elements; for(Element *elmt : elements_set) { if (!elmt->isMovable()) { - m_elements.remove(elmt); + m_elements.removeAll(elmt); ++count_; } } diff --git a/sources/diagramcontent.h b/sources/diagramcontent.h index 853d1aa36..0ed5e54db 100644 --- a/sources/diagramcontent.h +++ b/sources/diagramcontent.h @@ -64,7 +64,7 @@ class DiagramContent SelectedOnly = 512 }; - QSet m_elements; + QList m_elements; QSet m_text_fields; QSet m_images; QSet m_shapes; diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index b5afd838f..98c82885c 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -819,7 +819,7 @@ void DiagramView::editSelectionProperties() selection.conductors().first()->editProperty(); // edit element else if (selection.m_elements.size()) - selection.m_elements.toList().first() -> editProperty(); + selection.m_elements.first() -> editProperty(); } else { diff --git a/sources/elementsmover.cpp b/sources/elementsmover.cpp index 402970209..3fc59def3 100644 --- a/sources/elementsmover.cpp +++ b/sources/elementsmover.cpp @@ -143,7 +143,7 @@ void ElementsMover::endMovement() m_moved_content.items(dc::Elements).size() == 1 && diagram_ -> project() -> autoConductor()) { - Element *elmt = m_moved_content.m_elements.toList().first(); + Element *elmt = m_moved_content.m_elements.first(); int acc = elmt->AlignedFreeTerminals().size(); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 87eae8c07..c4919a7fe 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -276,8 +276,8 @@ void QETDiagramEditor::setUpActions() m_grey_background -> setCheckable (true); connect (m_grey_background, &QAction::triggered, [this](bool checked) { Diagram::background_color = checked ? Qt::darkGray : Qt::white; - if (this->currentDiagram() && this->currentDiagram()->diagram()) - this->currentDiagram()->diagram()->update(); + if (this->currentDiagramView() && this->currentDiagramView()->diagram()) + this->currentDiagramView()->diagram()->update(); }); m_draw_grid = new QAction ( QET::Icons::Grid, tr("Afficher la grille"), this); @@ -984,7 +984,7 @@ bool QETDiagramEditor::addProject(QETProject *project, bool update_panel) { // met a jour le panel d'elements if (update_panel) { pa -> elementsPanel().projectWasOpened(project); - if (currentDiagram() != nullptr) + if (currentDiagramView() != nullptr) m_autonumbering_dock->setProject(project, project_view); } @@ -1026,7 +1026,7 @@ ProjectView *QETDiagramEditor::currentProjectView() const { @return Le schema actuellement edite (= l'onglet ouvert dans le projet courant) ou 0 s'il n'y en a pas */ -DiagramView *QETDiagramEditor::currentDiagram() const { +DiagramView *QETDiagramEditor::currentDiagramView() const { if (ProjectView *project_view = currentProjectView()) { return(project_view -> currentDiagram()); } @@ -1041,11 +1041,11 @@ DiagramView *QETDiagramEditor::currentDiagram() const { */ Element *QETDiagramEditor::currentElement() const { - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); if (!dv) return(nullptr); - QList selected_elements = DiagramContent(dv->diagram()).m_elements.toList(); + QList selected_elements = DiagramContent(dv->diagram()).m_elements; if (selected_elements.count() != 1) return(nullptr); @@ -1150,27 +1150,27 @@ void QETDiagramEditor::activateWidget(QWidget *widget) { Effectue l'action "couper" sur le schema en cours */ void QETDiagramEditor::slot_cut() { - if(currentDiagram()) currentDiagram() -> cut(); + if(currentDiagramView()) currentDiagramView() -> cut(); } /** Effectue l'action "copier" sur le diagram en cours */ void QETDiagramEditor::slot_copy() { - if(currentDiagram()) currentDiagram() -> copy(); + if(currentDiagramView()) currentDiagramView() -> copy(); } /** Effectue l'action "coller" sur le schema en cours */ void QETDiagramEditor::slot_paste() { - if(currentDiagram()) currentDiagram() -> paste(); + if(currentDiagramView()) currentDiagramView() -> paste(); } void QETDiagramEditor::zoomGroupTriggered(QAction *action) { QString value = action->data().toString(); - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); if (!dv || value.isEmpty()) return; @@ -1194,7 +1194,7 @@ void QETDiagramEditor::zoomGroupTriggered(QAction *action) void QETDiagramEditor::selectGroupTriggered(QAction *action) { QString value = action->data().toString(); - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); if (!dv || value.isEmpty()) return; @@ -1216,9 +1216,9 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action) { QString value = action->data().toString(); - if (Q_UNLIKELY (!currentDiagram() || !currentDiagram()->diagram() || value.isEmpty())) return; + if (Q_UNLIKELY (!currentDiagramView() || !currentDiagramView()->diagram() || value.isEmpty())) return; - Diagram *d = currentDiagram()->diagram(); + Diagram *d = currentDiagramView()->diagram(); DiagramEventInterface *diagram_event = nullptr; if (value == "line") @@ -1259,7 +1259,7 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action) void QETDiagramEditor::selectionGroupTriggered(QAction *action) { QString value = action->data().toString(); - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); Diagram *diagram = dv->diagram(); DiagramContent dc(diagram); @@ -1288,7 +1288,7 @@ void QETDiagramEditor::selectionGroupTriggered(QAction *action) void QETDiagramEditor::rowColumnGroupTriggered(QAction *action) { QString value = action->data().toString(); - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); if (!dv || value.isEmpty() || dv->diagram()->isReadOnly()) return; @@ -1336,7 +1336,7 @@ void QETDiagramEditor::slot_setVisualisationMode() */ void QETDiagramEditor::slot_updateActions() { - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); ProjectView *pv = currentProjectView(); bool opened_project = pv; @@ -1377,7 +1377,7 @@ void QETDiagramEditor::slot_updateActions() void QETDiagramEditor::slot_updateAutoNumDock() { if ( workspace.subWindowList().indexOf(workspace.activeSubWindow()) != activeSubWindowIndex) { activeSubWindowIndex = workspace.subWindowList().indexOf(workspace.activeSubWindow()); - if (currentProjectView() != nullptr && currentDiagram() != nullptr) { + if (currentProjectView() != nullptr && currentDiagramView() != nullptr) { m_autonumbering_dock->setProject(currentProjectView()->project(),currentProjectView()); } } @@ -1400,7 +1400,7 @@ void QETDiagramEditor::slot_updateUndoStack() */ void QETDiagramEditor::slot_updateComplexActions() { - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); if(!dv) { QList action_list; @@ -1493,7 +1493,7 @@ void QETDiagramEditor::slot_updateComplexActions() */ void QETDiagramEditor::slot_updateModeActions() { - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); if (!dv) grp_visu_sel -> setEnabled(false); @@ -1528,7 +1528,7 @@ void QETDiagramEditor::slot_updateModeActions() Gere les actions ayant besoin du presse-papier */ void QETDiagramEditor::slot_updatePasteAction() { - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); bool editable_diagram = (dv && !dv -> diagram() -> isReadOnly()); // pour coller, il faut un schema ouvert et un schema dans le presse-papier @@ -1738,7 +1738,7 @@ void QETDiagramEditor::editDiagramProperties(Diagram *diagram) { Edite les proprietes des objets selectionnes */ void QETDiagramEditor::editSelectionProperties() { - if (DiagramView *dv = currentDiagram()) { + if (DiagramView *dv = currentDiagramView()) { dv -> editSelectionProperties(); } } @@ -1747,7 +1747,7 @@ void QETDiagramEditor::editSelectionProperties() { Reinitialise les conducteurs selectionnes */ void QETDiagramEditor::slot_resetConductors() { - if (DiagramView *dv = currentDiagram()) { + if (DiagramView *dv = currentDiagramView()) { dv -> resetConductors(); } } @@ -2179,7 +2179,7 @@ void QETDiagramEditor::selectionChanged() { slot_updateComplexActions(); - DiagramView *dv = currentDiagram(); + DiagramView *dv = currentDiagramView(); if (dv && dv->diagram()) m_selection_properties_editor->setDiagram(dv->diagram()); } diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index ac8048d9f..be6278e24 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -77,7 +77,7 @@ class QETDiagramEditor : public QETMainWindow { private: bool addProject(QETProject *, bool = true); ProjectView *currentProjectView() const; - DiagramView *currentDiagram() const; + DiagramView *currentDiagramView() const; Element *currentElement() const; CustomElement * currentCustomElement() const; ProjectView *findProject(DiagramView *) const; diff --git a/sources/ui/multipastedialog.cpp b/sources/ui/multipastedialog.cpp index 2cc004e68..02c06cade 100644 --- a/sources/ui/multipastedialog.cpp +++ b/sources/ui/multipastedialog.cpp @@ -2,6 +2,8 @@ #include "ui_multipastedialog.h" #include "diagram.h" #include "diagramcommands.h" +#include "element.h" +#include "conductorautonumerotation.h" MultiPasteDialog::MultiPasteDialog(Diagram *diagram, QWidget *parent) : QDialog(parent), @@ -74,7 +76,32 @@ void MultiPasteDialog::on_m_button_box_accepted() if(m_pasted_content.count()) { m_diagram->clearSelection(); - m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, m_pasted_content)); + + QUndoCommand *undo = new QUndoCommand(tr("Multi-collage")); + new PasteDiagramCommand(m_diagram, m_pasted_content, undo); + + if(ui->m_auto_connection_cb->isChecked()) + { + for(Element *elmt : m_pasted_content.m_elements) + { + while (!elmt->AlignedFreeTerminals().isEmpty()) + { + QPair pair = elmt->AlignedFreeTerminals().takeFirst(); + + Conductor *conductor = new Conductor(pair.first, pair.second); + new AddItemCommand(conductor, m_diagram, QPointF(), undo); + + //Autonum the new conductor, the undo command associated for this, have for parent undo_object + ConductorAutoNumerotation can (conductor, m_diagram, undo); + can.numerate(); + if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors()) { + conductor->setFreezeLabel(true); + } + } + } + } + + m_diagram->undoStack().push(undo); m_diagram->adjustSceneRect(); m_accept = true; } diff --git a/sources/ui/multipastedialog.ui b/sources/ui/multipastedialog.ui index fb96a846a..f3e34c999 100644 --- a/sources/ui/multipastedialog.ui +++ b/sources/ui/multipastedialog.ui @@ -87,6 +87,13 @@ + + + + Auto-connection + + +