[qet] qet/qet: [5331] Multi paste dialog : add a check box for allows auto connection of the pasted elements.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 5331
Author:   blacksun
Date:     2018-04-12 18:24:44 +0200 (Thu, 12 Apr 2018)
Log Message:
-----------
Multi paste dialog : add a check box for allows auto connection of the pasted elements.

Modified Paths:
--------------
    trunk/sources/diagram.cpp
    trunk/sources/diagramcommands.cpp
    trunk/sources/diagramcontent.cpp
    trunk/sources/diagramcontent.h
    trunk/sources/diagramview.cpp
    trunk/sources/elementsmover.cpp
    trunk/sources/qetdiagrameditor.cpp
    trunk/sources/qetdiagrameditor.h
    trunk/sources/ui/multipastedialog.cpp
    trunk/sources/ui/multipastedialog.ui

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/diagram.cpp	2018-04-12 16:24:44 UTC (rev 5331)
@@ -999,7 +999,7 @@
 	
 	// 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();

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/diagramcommands.cpp	2018-04-12 16:24:44 UTC (rev 5331)
@@ -94,7 +94,7 @@
 		first_redo = false;
 
 			//this is the first paste, we do some actions for the new element
-		const QList <Element *> elmts_list = content.m_elements.toList();
+		const QList <Element *> elmts_list = content.m_elements;
 		for (Element *e : elmts_list)
 		{
 				//make new uuid, because old uuid are the uuid of the copied element

Modified: trunk/sources/diagramcontent.cpp
===================================================================
--- trunk/sources/diagramcontent.cpp	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/diagramcontent.cpp	2018-04-12 16:24:44 UTC (rev 5331)
@@ -238,10 +238,10 @@
 {
 	int count_ = 0;
 	
-	const QSet<Element *> elements_set = m_elements;
+	const QList<Element *> elements_set = m_elements;
 	for(Element *elmt : elements_set) {
 		if (!elmt->isMovable()) {
-			m_elements.remove(elmt);
+			m_elements.removeAll(elmt);
 			++count_;
 		}
 	}

Modified: trunk/sources/diagramcontent.h
===================================================================
--- trunk/sources/diagramcontent.h	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/diagramcontent.h	2018-04-12 16:24:44 UTC (rev 5331)
@@ -64,7 +64,7 @@
 			SelectedOnly = 512
 		};
 		
-		QSet<Element *> m_elements;
+		QList<Element *> m_elements;
 		QSet<IndependentTextItem *> m_text_fields;
 		QSet<DiagramImageItem *> m_images;
 		QSet<QetShapeItem *> m_shapes;

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/diagramview.cpp	2018-04-12 16:24:44 UTC (rev 5331)
@@ -819,7 +819,7 @@
 			selection.conductors().first()->editProperty();
 		// edit element
 		else if (selection.m_elements.size())
-			selection.m_elements.toList().first() -> editProperty();
+			selection.m_elements.first() -> editProperty();
 	}
 
 	else {

Modified: trunk/sources/elementsmover.cpp
===================================================================
--- trunk/sources/elementsmover.cpp	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/elementsmover.cpp	2018-04-12 16:24:44 UTC (rev 5331)
@@ -143,7 +143,7 @@
 		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();
 

Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/qetdiagrameditor.cpp	2018-04-12 16:24:44 UTC (rev 5331)
@@ -276,8 +276,8 @@
 	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 @@
 	// 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 @@
 	@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 @@
 */
 Element *QETDiagramEditor::currentElement() const
 {
-	DiagramView *dv = currentDiagram();
+	DiagramView *dv = currentDiagramView();
 	if (!dv)
 		return(nullptr);
 	
-	QList<Element *> selected_elements = DiagramContent(dv->diagram()).m_elements.toList();
+	QList<Element *> selected_elements = DiagramContent(dv->diagram()).m_elements;
 	if (selected_elements.count() != 1)
 		return(nullptr);
 	
@@ -1150,7 +1150,7 @@
 	Effectue l'action "couper" sur le schema en cours
 */
 void QETDiagramEditor::slot_cut() {
-	if(currentDiagram()) currentDiagram() -> cut();
+	if(currentDiagramView()) currentDiagramView() -> cut();
 }
 
 /**
@@ -1157,7 +1157,7 @@
 	Effectue l'action "copier" sur le diagram en cours
 */
 void QETDiagramEditor::slot_copy() {
-	if(currentDiagram()) currentDiagram() -> copy();
+	if(currentDiagramView()) currentDiagramView() -> copy();
 }
 
 /**
@@ -1164,13 +1164,13 @@
 	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::selectGroupTriggered(QAction *action)
 {
 	QString value = action->data().toString();
-	DiagramView *dv = currentDiagram();
+	DiagramView *dv = currentDiagramView();
 
 	if (!dv || value.isEmpty()) return;
 
@@ -1216,9 +1216,9 @@
 {
 	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::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::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_updateActions()
 {
-	DiagramView *dv = currentDiagram();
+	DiagramView *dv = currentDiagramView();
 	ProjectView *pv = currentProjectView();
 
 	bool opened_project = pv;
@@ -1377,7 +1377,7 @@
 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_updateComplexActions()
 {
-	DiagramView *dv = currentDiagram();
+	DiagramView *dv = currentDiagramView();
 	if(!dv)
 	{
 		QList <QAction *> action_list;
@@ -1493,7 +1493,7 @@
  */
 void QETDiagramEditor::slot_updateModeActions()
 {
-	DiagramView *dv = currentDiagram();
+	DiagramView *dv = currentDiagramView();
 	
 	if (!dv)
 		grp_visu_sel -> setEnabled(false);
@@ -1528,7 +1528,7 @@
 	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 @@
 	Edite les proprietes des objets selectionnes
 */
 void QETDiagramEditor::editSelectionProperties() {
-	if (DiagramView *dv = currentDiagram()) {
+	if (DiagramView *dv = currentDiagramView()) {
 		dv -> editSelectionProperties();
 	}
 }
@@ -1747,7 +1747,7 @@
 	Reinitialise les conducteurs selectionnes
 */
 void QETDiagramEditor::slot_resetConductors() {
-	if (DiagramView *dv = currentDiagram()) {
+	if (DiagramView *dv = currentDiagramView()) {
 		dv -> resetConductors();
 	}
 }
@@ -2179,7 +2179,7 @@
 {
 	slot_updateComplexActions();
 
-	DiagramView *dv = currentDiagram();
+	DiagramView *dv = currentDiagramView();
 	if (dv && dv->diagram())
 		m_selection_properties_editor->setDiagram(dv->diagram());
 }

Modified: trunk/sources/qetdiagrameditor.h
===================================================================
--- trunk/sources/qetdiagrameditor.h	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/qetdiagrameditor.h	2018-04-12 16:24:44 UTC (rev 5331)
@@ -77,7 +77,7 @@
 	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;

Modified: trunk/sources/ui/multipastedialog.cpp
===================================================================
--- trunk/sources/ui/multipastedialog.cpp	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/ui/multipastedialog.cpp	2018-04-12 16:24:44 UTC (rev 5331)
@@ -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 @@
     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 <Terminal *, Terminal *> pair = elmt->AlignedFreeTerminals().takeFirst();
+			
+					Conductor *conductor = new Conductor(pair.first, pair.second);
+					new AddItemCommand<Conductor *>(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;
 	}

Modified: trunk/sources/ui/multipastedialog.ui
===================================================================
--- trunk/sources/ui/multipastedialog.ui	2018-04-12 16:01:00 UTC (rev 5330)
+++ trunk/sources/ui/multipastedialog.ui	2018-04-12 16:24:44 UTC (rev 5331)
@@ -88,6 +88,13 @@
     </layout>
    </item>
    <item>
+    <widget class="QCheckBox" name="m_auto_connection_cb">
+     <property name="text">
+      <string>Auto-connection</string>
+     </property>
+    </widget>
+   </item>
+   <item>
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/