[qet] qet/qet: [5319] Diagram editor : add new action in the context menu : multiple paste.

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


Revision: 5319
Author:   blacksun
Date:     2018-04-08 18:50:52 +0200 (Sun, 08 Apr 2018)
Log Message:
-----------
Diagram editor : add new action in the context menu : multiple paste.

Modified Paths:
--------------
    trunk/sources/diagramcontent.cpp
    trunk/sources/diagramcontent.h
    trunk/sources/diagramview.cpp
    trunk/sources/diagramview.h

Added Paths:
-----------
    trunk/sources/ui/multipastedialog.cpp
    trunk/sources/ui/multipastedialog.h
    trunk/sources/ui/multipastedialog.ui

Modified: trunk/sources/diagramcontent.cpp
===================================================================
--- trunk/sources/diagramcontent.cpp	2018-04-08 13:11:17 UTC (rev 5318)
+++ trunk/sources/diagramcontent.cpp	2018-04-08 16:50:52 UTC (rev 5319)
@@ -265,6 +265,51 @@
 	return count_;
 }
 
+DiagramContent &DiagramContent::operator+=(const DiagramContent &other)
+{
+	for(Element *elmt : other.m_elements)
+		if(!m_elements.contains(elmt))
+			m_elements << elmt;
+	
+	for(IndependentTextItem *iti : other.m_text_fields)
+		if(!m_text_fields.contains(iti))
+			m_text_fields << iti;
+	
+	for(DiagramImageItem *dii : other.m_images)
+		if(!m_images.contains(dii))
+			m_images << dii;
+	
+	for(QetShapeItem *qsi : other.m_shapes)
+		if(!m_shapes.contains(qsi))
+			m_shapes << qsi;
+	
+	for(Conductor *c : other.m_conductors_to_update)
+		if(!m_conductors_to_update.contains(c))
+			m_conductors_to_update << c;
+	
+	for(Conductor *c : other.m_conductors_to_move)
+		if(!m_conductors_to_move.contains(c))
+			m_conductors_to_move << c;
+	
+	for(Conductor *c : other.m_other_conductors)
+		if(!m_other_conductors.contains(c))
+			m_other_conductors << c;
+	
+	for(DynamicElementTextItem *deti : other.m_element_texts)
+		if(!m_element_texts.contains(deti))
+			m_element_texts << deti;
+	
+	for(ElementTextItemGroup *etig : other.m_texts_groups)
+		if(!m_texts_groups.contains(etig))
+			m_texts_groups << etig;
+	
+	for(QGraphicsItem *qgi : other.m_selected_items)
+		if(!m_selected_items.contains(qgi))
+			m_selected_items << qgi;
+	
+	return *this;
+}
+
 /**
  * @brief DiagramContent::items
  * @param filter

Modified: trunk/sources/diagramcontent.h
===================================================================
--- trunk/sources/diagramcontent.h	2018-04-08 13:11:17 UTC (rev 5318)
+++ trunk/sources/diagramcontent.h	2018-04-08 16:50:52 UTC (rev 5319)
@@ -85,6 +85,8 @@
 		int count(int = All) const;
 		void clear();
 		int removeNonMovableItems();
+		
+		DiagramContent& operator+=(const DiagramContent& other);
 };
 QDebug &operator<<(QDebug, DiagramContent &);
 #endif

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2018-04-08 13:11:17 UTC (rev 5318)
+++ trunk/sources/diagramview.cpp	2018-04-08 16:50:52 UTC (rev 5319)
@@ -44,6 +44,7 @@
 #include "qetshapeitem.h"
 #include "undocommand/deleteqgraphicsitemcommand.h"
 #include "dynamicelementtextitem.h"
+#include "multipastedialog.h"
 
 /**
 	Constructeur
@@ -86,6 +87,12 @@
 	m_context_menu = new QMenu(this);
 	m_paste_here = new QAction(QET::Icons::EditPaste, tr("Coller ici", "context menu action"), this);
 	connect(m_paste_here, SIGNAL(triggered()), this, SLOT(pasteHere()));
+	
+	m_multi_paste = new QAction(QET::Icons::EditPaste, tr("Collage multiple"), this);
+	connect(m_multi_paste, &QAction::triggered, [this]() {
+		MultiPasteDialog d(this->m_diagram, this);
+		d.exec();
+	});
 
 	connect(m_diagram, SIGNAL(showDiagram(Diagram*)), this, SIGNAL(showDiagram(Diagram*)));
 	connect(m_diagram, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
@@ -1061,6 +1068,7 @@
 		} else {
 			m_context_menu -> addAction(qde -> m_cut);
 			m_context_menu -> addAction(qde -> m_copy);
+			m_context_menu->addAction(m_multi_paste);
 			m_context_menu -> addSeparator();
 			m_context_menu -> addAction(qde -> m_conductor_reset);
 			m_context_menu -> addSeparator();

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2018-04-08 13:11:17 UTC (rev 5318)
+++ trunk/sources/diagramview.h	2018-04-08 16:50:52 UTC (rev 5319)
@@ -53,6 +53,7 @@
 		DVEventInterface *m_event_interface = nullptr;
 		QMenu            *m_context_menu = nullptr;
 		QAction          *m_paste_here = nullptr;
+		QAction			 *m_multi_paste = nullptr;
 		QPoint            m_paste_here_pos;
 		QPointF           m_rubber_band_origin;
 		bool              m_fresh_focus_in,

Added: trunk/sources/ui/multipastedialog.cpp
===================================================================
--- trunk/sources/ui/multipastedialog.cpp	                        (rev 0)
+++ trunk/sources/ui/multipastedialog.cpp	2018-04-08 16:50:52 UTC (rev 5319)
@@ -0,0 +1,81 @@
+#include "multipastedialog.h"
+#include "ui_multipastedialog.h"
+#include "diagram.h"
+#include "diagramcommands.h"
+
+MultiPasteDialog::MultiPasteDialog(Diagram *diagram, QWidget *parent) :
+	QDialog(parent),
+	ui(new Ui::MultiPasteDialog),
+	m_diagram(diagram)
+{
+	ui->setupUi(this);
+	
+	connect(ui->m_x_sb, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MultiPasteDialog::updatePreview);
+	connect(ui->m_y_sb, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MultiPasteDialog::updatePreview);
+	connect(ui->m_copy_count, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MultiPasteDialog::updatePreview);
+	
+	QRectF br;
+	for (QGraphicsItem *item : m_diagram->selectedItems())
+		br = br.united(item->mapToScene(item->boundingRect()).boundingRect());
+	m_origin = br.topLeft();
+	
+	m_document = m_diagram->toXml(false);
+	updatePreview();
+}
+
+MultiPasteDialog::~MultiPasteDialog()
+{
+	if(m_accept == false)
+	{
+		for(QGraphicsItem *item : m_pasted_content.items())
+		{
+			if(item->scene() && item->scene() == m_diagram)
+			{
+				m_diagram->removeItem(item);
+				delete item;
+			}
+		}
+	}
+	
+	delete ui;
+}
+
+void MultiPasteDialog::updatePreview()
+{
+		//First of all we remove all precedent items added from the previous preview.
+	for(QGraphicsItem *item : m_pasted_content.items())
+	{
+		if(item->scene() && item->scene() == m_diagram)
+		{
+			m_diagram->removeItem(item);
+			delete item;
+		}
+	}
+	m_pasted_content.clear();
+	
+	QPointF offset(ui->m_x_sb->value(), ui->m_y_sb->value());
+	QPointF pos = m_origin+offset;
+	
+	for(int i=0 ; i<ui->m_copy_count->value() ; i++)
+	{		
+		DiagramContent dc;
+		m_diagram->fromXml(m_document, pos, false, &dc);
+		
+		m_pasted_content += dc;
+		pos += offset;
+	}
+	
+	if(m_pasted_content.count())
+		m_diagram->adjustSceneRect();
+}
+
+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));
+		m_diagram->adjustSceneRect();
+		m_accept = true;
+	}
+}

Added: trunk/sources/ui/multipastedialog.h
===================================================================
--- trunk/sources/ui/multipastedialog.h	                        (rev 0)
+++ trunk/sources/ui/multipastedialog.h	2018-04-08 16:50:52 UTC (rev 5319)
@@ -0,0 +1,35 @@
+#ifndef MULTIPASTEDIALOG_H
+#define MULTIPASTEDIALOG_H
+
+#include <QDialog>
+#include "diagramcontent.h"
+#include "QDomDocument"
+
+class Diagram;
+
+namespace Ui {
+	class MultiPasteDialog;
+}
+
+class MultiPasteDialog : public QDialog
+{
+	Q_OBJECT
+	
+	public:
+		explicit MultiPasteDialog(Diagram *diagram, QWidget *parent = 0);
+		~MultiPasteDialog();
+		void updatePreview();
+	
+		private slots:
+		void on_m_button_box_accepted();
+		
+		private:
+		Ui::MultiPasteDialog *ui;
+		Diagram *m_diagram = nullptr;
+		DiagramContent m_pasted_content;
+		QPointF m_origin;
+		QDomDocument m_document;
+		bool m_accept = false;
+};
+
+#endif // MULTIPASTEDIALOG_H

Added: trunk/sources/ui/multipastedialog.ui
===================================================================
--- trunk/sources/ui/multipastedialog.ui	                        (rev 0)
+++ trunk/sources/ui/multipastedialog.ui	2018-04-08 16:50:52 UTC (rev 5319)
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MultiPasteDialog</class>
+ <widget class="QDialog" name="MultiPasteDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>261</width>
+    <height>110</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Collage multiple</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Décalage</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QSpinBox" name="m_x_sb">
+       <property name="suffix">
+        <string>px</string>
+       </property>
+       <property name="prefix">
+        <string>x:  </string>
+       </property>
+       <property name="minimum">
+        <number>-1000</number>
+       </property>
+       <property name="maximum">
+        <number>1000</number>
+       </property>
+       <property name="singleStep">
+        <number>10</number>
+       </property>
+       <property name="value">
+        <number>100</number>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QSpinBox" name="m_y_sb">
+       <property name="suffix">
+        <string>px</string>
+       </property>
+       <property name="prefix">
+        <string>y:  </string>
+       </property>
+       <property name="minimum">
+        <number>-1000</number>
+       </property>
+       <property name="maximum">
+        <number>1000</number>
+       </property>
+       <property name="singleStep">
+        <number>10</number>
+       </property>
+       <property name="value">
+        <number>0</number>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <item>
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>Nombre de copie</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QSpinBox" name="m_copy_count">
+       <property name="minimum">
+        <number>1</number>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="m_button_box">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>m_button_box</sender>
+   <signal>accepted()</signal>
+   <receiver>MultiPasteDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>m_button_box</sender>
+   <signal>rejected()</signal>
+   <receiver>MultiPasteDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>


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