Skip to content

Commit 7f0142c

Browse files
committed
Working move item content tool
1 parent b276f4c commit 7f0142c

20 files changed

+312
-32
lines changed

python/core/layout/qgslayoutitem.sip

+10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
6565
UndoNodeMove,
6666
UndoAtlasMargin,
6767
UndoMapRotation,
68+
UndoZoomContent,
6869
};
6970

7071
explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
@@ -531,7 +532,16 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
531532
%Docstring
532533
Moves the content of the item, by a specified ``dx`` and ``dy`` in layout units.
533534
The default implementation has no effect.
535+
.. seealso:: setMoveContentPreviewOffset()
534536
.. seealso:: zoomContent()
537+
%End
538+
539+
virtual void setMoveContentPreviewOffset( double dx, double dy );
540+
%Docstring
541+
Sets temporary offset for the item, by a specified ``dx`` and ``dy`` in layout units.
542+
This is useful for live updates when moving item content in a QgsLayoutView.
543+
The default implementation has no effect.
544+
.. seealso:: moveContent()
535545
%End
536546

537547
virtual void zoomContent( double factor, QPointF point );

python/core/layout/qgslayoutitemmap.sip

+3-5
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ class QgsLayoutItemMap : QgsLayoutItem
250250

251251
virtual void moveContent( double dx, double dy );
252252

253+
virtual void setMoveContentPreviewOffset( double dx, double dy );
254+
255+
253256
virtual void zoomContent( double factor, QPointF point );
254257

255258

@@ -386,11 +389,6 @@ True if a draw is already in progress
386389

387390

388391

389-
void setOffset( double xOffset, double yOffset );
390-
%Docstring
391-
Sets offset values to shift image (useful for live updates when moving item content)
392-
%End
393-
394392

395393
virtual QRectF boundingRect() const;
396394

python/gui/gui_auto.sip

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@
297297
%Include layout/qgslayoutviewtooladditem.sip
298298
%Include layout/qgslayoutviewtooladdnodeitem.sip
299299
%Include layout/qgslayoutviewtooleditnodes.sip
300+
%Include layout/qgslayoutviewtoolmoveitemcontent.sip
300301
%Include layout/qgslayoutviewtoolpan.sip
301302
%Include layout/qgslayoutviewtoolselect.sip
302303
%Include layout/qgslayoutviewtooltemporarykeypan.sip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/layout/qgslayoutviewtoolmoveitemcontent.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
class QgsLayoutViewToolMoveItemContent : QgsLayoutViewTool
12+
{
13+
%Docstring
14+
Layout view tool for moving and zooming item content.
15+
.. versionadded:: 3.0
16+
%End
17+
18+
%TypeHeaderCode
19+
#include "qgslayoutviewtoolmoveitemcontent.h"
20+
%End
21+
public:
22+
23+
QgsLayoutViewToolMoveItemContent( QgsLayoutView *view /TransferThis/ );
24+
%Docstring
25+
Constructor for QgsLayoutViewToolMoveItemContent.
26+
%End
27+
28+
virtual void layoutPressEvent( QgsLayoutViewMouseEvent *event );
29+
30+
virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event );
31+
32+
virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );
33+
34+
virtual void wheelEvent( QWheelEvent *event );
35+
36+
37+
};
38+
39+
/************************************************************************
40+
* This file has been generated automatically from *
41+
* *
42+
* src/gui/layout/qgslayoutviewtoolmoveitemcontent.h *
43+
* *
44+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
45+
************************************************************************/

src/app/layout/qgslayoutdesignerdialog.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgslayoutviewtooladditem.h"
2727
#include "qgslayoutviewtooladdnodeitem.h"
2828
#include "qgslayoutviewtoolpan.h"
29+
#include "qgslayoutviewtoolmoveitemcontent.h"
2930
#include "qgslayoutviewtoolzoom.h"
3031
#include "qgslayoutviewtoolselect.h"
3132
#include "qgslayoutviewtooleditnodes.h"
@@ -251,6 +252,11 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
251252
mToolsActionGroup->addAction( mActionEditNodesItem );
252253
connect( mActionEditNodesItem, &QAction::triggered, mNodesTool, [ = ] { mView->setTool( mNodesTool ); } );
253254

255+
mMoveContentTool = new QgsLayoutViewToolMoveItemContent( mView );
256+
mMoveContentTool->setAction( mActionMoveItemContent );
257+
mToolsActionGroup->addAction( mActionMoveItemContent );
258+
connect( mActionMoveItemContent, &QAction::triggered, mMoveContentTool, [ = ] { mView->setTool( mMoveContentTool ); } );
259+
254260
//Ctrl+= should also trigger zoom in
255261
QShortcut *ctrlEquals = new QShortcut( QKeySequence( QStringLiteral( "Ctrl+=" ) ), this );
256262
connect( ctrlEquals, &QShortcut::activated, mActionZoomIn, &QAction::trigger );

src/app/layout/qgslayoutdesignerdialog.h

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class QgsLayoutViewToolPan;
2929
class QgsLayoutViewToolZoom;
3030
class QgsLayoutViewToolSelect;
3131
class QgsLayoutViewToolEditNodes;
32+
class QgsLayoutViewToolMoveItemContent;
3233
class QgsLayoutRuler;
3334
class QComboBox;
3435
class QSlider;
@@ -277,6 +278,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
277278
QgsLayoutViewToolZoom *mZoomTool = nullptr;
278279
QgsLayoutViewToolSelect *mSelectTool = nullptr;
279280
QgsLayoutViewToolEditNodes *mNodesTool = nullptr;
281+
QgsLayoutViewToolMoveItemContent *mMoveContentTool = nullptr;
280282

281283
QMap< QString, QToolButton * > mItemGroupToolButtons;
282284
QMap< QString, QMenu * > mItemGroupSubmenus;

src/app/layout/qgslayoutmapwidget.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
104104

105105
if ( item )
106106
{
107-
mLabel->setText( tr( "Map %1" ).arg( item->id() ) );
108107
connect( item, &QgsLayoutObject::changed, this, &QgsLayoutMapWidget::updateGuiElements );
109108

110109
#if 0 //TODO
@@ -491,9 +490,8 @@ void QgsLayoutMapWidget::mScaleLineEdit_editingFinished()
491490
return;
492491
}
493492

494-
bool conversionSuccess;
495-
double scaleDenominator = mScaleLineEdit->text().toDouble( &conversionSuccess );
496-
493+
bool conversionSuccess = false;
494+
double scaleDenominator = QLocale::system().toDouble( mScaleLineEdit->text(), &conversionSuccess );
497495
if ( !conversionSuccess )
498496
{
499497
return;
@@ -612,6 +610,7 @@ void QgsLayoutMapWidget::updateGuiElements()
612610
}
613611

614612
blockAllSignals( true );
613+
mLabel->setText( tr( "Map %1" ).arg( item->id() ) );
615614

616615
whileBlocking( mCrsSelector )->setCrs( mMapItem->presetCrs() );
617616

src/core/layout/qgslayoutitem.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,11 @@ void QgsLayoutItem::moveContent( double, double )
802802

803803
}
804804

805+
void QgsLayoutItem::setMoveContentPreviewOffset( double, double )
806+
{
807+
808+
}
809+
805810
void QgsLayoutItem::zoomContent( double, QPointF )
806811
{
807812

src/core/layout/qgslayoutitem.h

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
9898
UndoNodeMove, //!< Node move
9999
UndoAtlasMargin, //!< Map atlas margin changed
100100
UndoMapRotation, //!< Map rotation changed
101+
UndoZoomContent, //!< Item content zoomed
101102
};
102103

103104
/**
@@ -528,10 +529,19 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
528529
/**
529530
* Moves the content of the item, by a specified \a dx and \a dy in layout units.
530531
* The default implementation has no effect.
532+
* \see setMoveContentPreviewOffset()
531533
* \see zoomContent()
532534
*/
533535
virtual void moveContent( double dx, double dy );
534536

537+
/**
538+
* Sets temporary offset for the item, by a specified \a dx and \a dy in layout units.
539+
* This is useful for live updates when moving item content in a QgsLayoutView.
540+
* The default implementation has no effect.
541+
* \see moveContent()
542+
*/
543+
virtual void setMoveContentPreviewOffset( double dx, double dy );
544+
535545
/**
536546
* Zooms content of item. Does nothing by default.
537547
* \param factor zoom factor, where > 1 results in a zoom in and < 1 results in a zoom out

src/core/layout/qgslayoutitemmap.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void QgsLayoutItemMap::moveContent( double dx, double dy )
300300
transformShift( dx, dy );
301301
mExtent.setXMinimum( mExtent.xMinimum() + dx );
302302
mExtent.setXMaximum( mExtent.xMaximum() + dx );
303-
mExtent.setYMinimum( mExtent.xMinimum() + dy );
303+
mExtent.setYMinimum( mExtent.yMinimum() + dy );
304304
mExtent.setYMaximum( mExtent.yMaximum() + dy );
305305

306306
//in case data defined extents are set, these override the calculated values
@@ -746,7 +746,7 @@ QgsMapSettings QgsLayoutItemMap::mapSettings( const QgsRectangle &extent, QSizeF
746746
return jobMapSettings;
747747
}
748748

749-
void QgsLayoutItemMap::setOffset( double xOffset, double yOffset )
749+
void QgsLayoutItemMap::setMoveContentPreviewOffset( double xOffset, double yOffset )
750750
{
751751
mXOffset = xOffset;
752752
mYOffset = yOffset;

src/core/layout/qgslayoutitemmap.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
265265
void setFollowVisibilityPresetName( const QString &name ) { mFollowVisibilityPresetName = name; }
266266

267267
void moveContent( double dx, double dy ) override;
268+
void setMoveContentPreviewOffset( double dx, double dy ) override;
269+
268270
void zoomContent( double factor, QPointF point ) override;
269271

270272

@@ -390,9 +392,6 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
390392
QgsRectangle extent() const {return mExtent;}
391393
#endif
392394

393-
//! Sets offset values to shift image (useful for live updates when moving item content)
394-
void setOffset( double xOffset, double yOffset );
395-
396395
#if 0
397396

398397
/**

src/gui/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ SET(QGIS_GUI_SRCS
172172
layout/qgslayoutviewtooladditem.cpp
173173
layout/qgslayoutviewtooladdnodeitem.cpp
174174
layout/qgslayoutviewtooleditnodes.cpp
175+
layout/qgslayoutviewtoolmoveitemcontent.cpp
175176
layout/qgslayoutviewtoolpan.cpp
176177
layout/qgslayoutviewtoolselect.cpp
177178
layout/qgslayoutviewtooltemporarykeypan.cpp
@@ -677,6 +678,7 @@ SET(QGIS_GUI_MOC_HDRS
677678
layout/qgslayoutviewtooladditem.h
678679
layout/qgslayoutviewtooladdnodeitem.h
679680
layout/qgslayoutviewtooleditnodes.h
681+
layout/qgslayoutviewtoolmoveitemcontent.h
680682
layout/qgslayoutviewtoolpan.h
681683
layout/qgslayoutviewtoolselect.h
682684
layout/qgslayoutviewtooltemporarykeypan.h

src/gui/layout/qgslayoutmousehandles.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -689,11 +689,13 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
689689

690690
void QgsLayoutMouseHandles::resetStatusBar()
691691
{
692+
if ( !mView )
693+
return;
694+
692695
const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems( false );
693696
int selectedCount = selectedItems.size();
694697
if ( selectedCount > 1 )
695698
{
696-
697699
//set status bar message to count of selected items
698700
mView->pushStatusMessage( tr( "%1 items selected" ).arg( selectedCount ) );
699701
}

src/gui/layout/qgslayoutruler.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,16 @@ void QgsLayoutRuler::drawGuideAtPos( QPainter *painter, QPoint pos )
338338

339339
void QgsLayoutRuler::createTemporaryGuideItem()
340340
{
341-
mGuideItem.reset( new QGraphicsLineItem() );
341+
delete mGuideItem;
342+
mGuideItem = new QGraphicsLineItem();
342343

343344
mGuideItem->setZValue( QgsLayout::ZGuide );
344345
QPen linePen( Qt::DotLine );
345346
linePen.setColor( QColor( 255, 0, 0, 150 ) );
346347
linePen.setWidthF( 0 );
347348
mGuideItem->setPen( linePen );
348349

349-
mView->currentLayout()->addItem( mGuideItem.get() );
350+
mView->currentLayout()->addItem( mGuideItem );
350351
}
351352

352353
QPointF QgsLayoutRuler::convertLocalPointToLayout( QPoint localPoint ) const
@@ -735,7 +736,8 @@ void QgsLayoutRuler::mouseReleaseEvent( QMouseEvent *event )
735736
{
736737
mCreatingGuide = false;
737738
QApplication::restoreOverrideCursor();
738-
mGuideItem.reset();
739+
delete mGuideItem;
740+
mGuideItem = nullptr;
739741

740742
// check that cursor left the ruler
741743
switch ( mOrientation )

src/gui/layout/qgslayoutruler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class GUI_EXPORT QgsLayoutRuler: public QWidget
121121
QgsLayoutGuide *mHoverGuide = nullptr;
122122

123123
bool mCreatingGuide = false;
124-
std::unique_ptr< QGraphicsLineItem > mGuideItem;
124+
QGraphicsLineItem *mGuideItem = nullptr;
125125

126126
//! Polygon for drawing guide markers
127127
QPolygonF mGuideMarker;

src/gui/layout/qgslayoutview.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ QgsLayoutView::QgsLayoutView( QWidget *parent )
5454
mSpacePanTool = new QgsLayoutViewToolTemporaryKeyPan( this );
5555
mMidMouseButtonPanTool = new QgsLayoutViewToolTemporaryMousePan( this );
5656
mSpaceZoomTool = new QgsLayoutViewToolTemporaryKeyZoom( this );
57-
mSnapMarker.reset( new QgsLayoutViewSnapMarker() );
57+
mSnapMarker = new QgsLayoutViewSnapMarker();
5858

5959
mPreviewEffect = new QgsPreviewEffect( this );
6060
viewport()->setGraphicsEffect( mPreviewEffect );
@@ -81,16 +81,19 @@ void QgsLayoutView::setCurrentLayout( QgsLayout *layout )
8181

8282
viewChanged();
8383

84-
mSnapMarker.reset( new QgsLayoutViewSnapMarker() );
84+
delete mSnapMarker;
85+
mSnapMarker = new QgsLayoutViewSnapMarker();
8586
mSnapMarker->hide();
86-
layout->addItem( mSnapMarker.get() );
87+
layout->addItem( mSnapMarker );
8788

88-
mHorizontalSnapLine.reset( createSnapLine() );
89+
delete mHorizontalSnapLine;
90+
mHorizontalSnapLine = createSnapLine();
8991
mHorizontalSnapLine->hide();
90-
layout->addItem( mHorizontalSnapLine.get() );
91-
mVerticalSnapLine.reset( createSnapLine() );
92+
layout->addItem( mHorizontalSnapLine );
93+
delete mVerticalSnapLine;
94+
mVerticalSnapLine = createSnapLine();
9295
mVerticalSnapLine->hide();
93-
layout->addItem( mVerticalSnapLine.get() );
96+
layout->addItem( mVerticalSnapLine );
9497

9598
if ( mHorizontalRuler )
9699
{
@@ -771,7 +774,7 @@ void QgsLayoutView::mouseMoveEvent( QMouseEvent *event )
771774
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, false ) );
772775
if ( mTool->flags() & QgsLayoutViewTool::FlagSnaps )
773776
{
774-
me->snapPoint( mHorizontalSnapLine.get(), mVerticalSnapLine.get(), mTool->ignoredSnapItems() );
777+
me->snapPoint( mHorizontalSnapLine, mVerticalSnapLine, mTool->ignoredSnapItems() );
775778
}
776779
if ( mTool->flags() & QgsLayoutViewTool::FlagSnaps )
777780
{

src/gui/layout/qgslayoutview.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
470470
QgsLayoutRuler *mVerticalRuler = nullptr;
471471
std::unique_ptr< QgsLayoutViewMenuProvider > mMenuProvider;
472472

473-
std::unique_ptr< QgsLayoutViewSnapMarker > mSnapMarker;
473+
QgsLayoutViewSnapMarker *mSnapMarker = nullptr;
474474

475-
std::unique_ptr< QGraphicsLineItem > mHorizontalSnapLine;
476-
std::unique_ptr< QGraphicsLineItem > mVerticalSnapLine;
475+
QGraphicsLineItem *mHorizontalSnapLine = nullptr;
476+
QGraphicsLineItem *mVerticalSnapLine = nullptr;
477477

478478
int mCurrentPage = 0;
479479

0 commit comments

Comments
 (0)