Skip to content
Permalink
Browse files
Pasting items from layout context menu pastes them at menu origin
instead of final cursor position
  • Loading branch information
nyalldawson committed Dec 6, 2017
1 parent ac6c131 commit 17656f2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
@@ -212,6 +212,18 @@ class QgsLayoutView: QGraphicsView

A list of pasted items is returned.

.. seealso:: copySelectedItems()
.. seealso:: hasItemsInClipboard()
:rtype: list of QgsLayoutItem
%End

QList< QgsLayoutItem * > pasteItems( QPointF layoutPoint );
%Docstring
Pastes items from clipboard, at the specified ``layoutPoint``,
in layout units.

A list of pasted items is returned.

.. seealso:: copySelectedItems()
.. seealso:: hasItemsInClipboard()
:rtype: list of QgsLayoutItem
@@ -94,9 +94,10 @@ QMenu *QgsLayoutAppMenuProvider::createContextMenu( QWidget *parent, QgsLayout *
else if ( mDesigner->view()->hasItemsInClipboard() )
{
QAction *pasteAction = new QAction( tr( "Paste" ), menu );
connect( pasteAction, &QAction::triggered, this, [this]()
connect( pasteAction, &QAction::triggered, this, [this, menu]()
{
mDesigner->paste();
QPointF pt = mDesigner->view()->mapToScene( mDesigner->view()->mapFromGlobal( menu->pos() ) );
mDesigner->view()->pasteItems( pt );
} );
menu->addAction( pasteAction );
menu->addSeparator();
@@ -369,6 +369,26 @@ QList< QgsLayoutItem * > QgsLayoutView::pasteItems( QgsLayoutView::PasteMode mod
return pastedItems;
}

QList<QgsLayoutItem *> QgsLayoutView::pasteItems( QPointF layoutPoint )
{
QList< QgsLayoutItem * > pastedItems;
QDomDocument doc;
QClipboard *clipboard = QApplication::clipboard();
if ( doc.setContent( clipboard->mimeData()->data( QStringLiteral( "text/xml" ) ) ) )
{
QDomElement docElem = doc.documentElement();
if ( docElem.tagName() == QLatin1String( "LayoutItemClipboard" ) )
{
currentLayout()->undoStack()->beginMacro( tr( "Paste Items" ) );
currentLayout()->undoStack()->beginCommand( currentLayout(), tr( "Paste Items" ) );
pastedItems = currentLayout()->addItemsFromXml( docElem, doc, QgsReadWriteContext(), &layoutPoint, false );
currentLayout()->undoStack()->endCommand();
currentLayout()->undoStack()->endMacro();
}
}
return pastedItems;
}

bool QgsLayoutView::hasItemsInClipboard() const
{
QDomDocument doc;
@@ -247,6 +247,17 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
*/
QList< QgsLayoutItem * > pasteItems( PasteMode mode );

/**
* Pastes items from clipboard, at the specified \a layoutPoint,
* in layout units.
*
* A list of pasted items is returned.
*
* \see copySelectedItems()
* \see hasItemsInClipboard()
*/
QList< QgsLayoutItem * > pasteItems( QPointF layoutPoint );

/**
* Returns true if the current clipboard contains layout items.
* \see pasteItems()

0 comments on commit 17656f2

Please sign in to comment.