Diagram editor : add new action in the context menu : multiple paste.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5319 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2018-04-08 16:50:52 +00:00
parent b9e24cd08f
commit 12e7a7002e
7 changed files with 322 additions and 0 deletions

View File

@ -265,6 +265,51 @@ int DiagramContent::removeNonMovableItems()
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

View File

@ -85,6 +85,8 @@ class DiagramContent
int count(int = All) const;
void clear();
int removeNonMovableItems();
DiagramContent& operator+=(const DiagramContent& other);
};
QDebug &operator<<(QDebug, DiagramContent &);
#endif

View File

@ -44,6 +44,7 @@
#include "qetshapeitem.h"
#include "undocommand/deleteqgraphicsitemcommand.h"
#include "dynamicelementtextitem.h"
#include "multipastedialog.h"
/**
Constructeur
@ -86,6 +87,12 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
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 @@ void DiagramView::contextMenuEvent(QContextMenuEvent *e) {
} 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();

View File

@ -53,6 +53,7 @@ class DiagramView : public QGraphicsView
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,

View File

@ -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;
}
}

View File

@ -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

View File

@ -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>