Skip to content

Commit

Permalink
Working move item content tool
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent b276f4c commit 7f0142c
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 32 deletions.
10 changes: 10 additions & 0 deletions python/core/layout/qgslayoutitem.sip
Expand Up @@ -65,6 +65,7 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoNodeMove,
UndoAtlasMargin,
UndoMapRotation,
UndoZoomContent,
};

explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
Expand Down Expand Up @@ -531,7 +532,16 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
%Docstring
Moves the content of the item, by a specified ``dx`` and ``dy`` in layout units.
The default implementation has no effect.
.. seealso:: setMoveContentPreviewOffset()
.. seealso:: zoomContent()
%End

virtual void setMoveContentPreviewOffset( double dx, double dy );
%Docstring
Sets temporary offset for the item, by a specified ``dx`` and ``dy`` in layout units.
This is useful for live updates when moving item content in a QgsLayoutView.
The default implementation has no effect.
.. seealso:: moveContent()
%End

virtual void zoomContent( double factor, QPointF point );
Expand Down
8 changes: 3 additions & 5 deletions python/core/layout/qgslayoutitemmap.sip
Expand Up @@ -250,6 +250,9 @@ class QgsLayoutItemMap : QgsLayoutItem

virtual void moveContent( double dx, double dy );

virtual void setMoveContentPreviewOffset( double dx, double dy );


virtual void zoomContent( double factor, QPointF point );


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



void setOffset( double xOffset, double yOffset );
%Docstring
Sets offset values to shift image (useful for live updates when moving item content)
%End


virtual QRectF boundingRect() const;

Expand Down
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -297,6 +297,7 @@
%Include layout/qgslayoutviewtooladditem.sip
%Include layout/qgslayoutviewtooladdnodeitem.sip
%Include layout/qgslayoutviewtooleditnodes.sip
%Include layout/qgslayoutviewtoolmoveitemcontent.sip
%Include layout/qgslayoutviewtoolpan.sip
%Include layout/qgslayoutviewtoolselect.sip
%Include layout/qgslayoutviewtooltemporarykeypan.sip
Expand Down
45 changes: 45 additions & 0 deletions python/gui/layout/qgslayoutviewtoolmoveitemcontent.sip
@@ -0,0 +1,45 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtoolmoveitemcontent.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLayoutViewToolMoveItemContent : QgsLayoutViewTool
{
%Docstring
Layout view tool for moving and zooming item content.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutviewtoolmoveitemcontent.h"
%End
public:

QgsLayoutViewToolMoveItemContent( QgsLayoutView *view /TransferThis/ );
%Docstring
Constructor for QgsLayoutViewToolMoveItemContent.
%End

virtual void layoutPressEvent( QgsLayoutViewMouseEvent *event );

virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event );

virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );

virtual void wheelEvent( QWheelEvent *event );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtoolmoveitemcontent.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
6 changes: 6 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -26,6 +26,7 @@
#include "qgslayoutviewtooladditem.h"
#include "qgslayoutviewtooladdnodeitem.h"
#include "qgslayoutviewtoolpan.h"
#include "qgslayoutviewtoolmoveitemcontent.h"
#include "qgslayoutviewtoolzoom.h"
#include "qgslayoutviewtoolselect.h"
#include "qgslayoutviewtooleditnodes.h"
Expand Down Expand Up @@ -251,6 +252,11 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mToolsActionGroup->addAction( mActionEditNodesItem );
connect( mActionEditNodesItem, &QAction::triggered, mNodesTool, [ = ] { mView->setTool( mNodesTool ); } );

mMoveContentTool = new QgsLayoutViewToolMoveItemContent( mView );
mMoveContentTool->setAction( mActionMoveItemContent );
mToolsActionGroup->addAction( mActionMoveItemContent );
connect( mActionMoveItemContent, &QAction::triggered, mMoveContentTool, [ = ] { mView->setTool( mMoveContentTool ); } );

//Ctrl+= should also trigger zoom in
QShortcut *ctrlEquals = new QShortcut( QKeySequence( QStringLiteral( "Ctrl+=" ) ), this );
connect( ctrlEquals, &QShortcut::activated, mActionZoomIn, &QAction::trigger );
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -29,6 +29,7 @@ class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;
class QgsLayoutViewToolSelect;
class QgsLayoutViewToolEditNodes;
class QgsLayoutViewToolMoveItemContent;
class QgsLayoutRuler;
class QComboBox;
class QSlider;
Expand Down Expand Up @@ -277,6 +278,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
QgsLayoutViewToolZoom *mZoomTool = nullptr;
QgsLayoutViewToolSelect *mSelectTool = nullptr;
QgsLayoutViewToolEditNodes *mNodesTool = nullptr;
QgsLayoutViewToolMoveItemContent *mMoveContentTool = nullptr;

QMap< QString, QToolButton * > mItemGroupToolButtons;
QMap< QString, QMenu * > mItemGroupSubmenus;
Expand Down
7 changes: 3 additions & 4 deletions src/app/layout/qgslayoutmapwidget.cpp
Expand Up @@ -104,7 +104,6 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )

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

#if 0 //TODO
Expand Down Expand Up @@ -491,9 +490,8 @@ void QgsLayoutMapWidget::mScaleLineEdit_editingFinished()
return;
}

bool conversionSuccess;
double scaleDenominator = mScaleLineEdit->text().toDouble( &conversionSuccess );

bool conversionSuccess = false;
double scaleDenominator = QLocale::system().toDouble( mScaleLineEdit->text(), &conversionSuccess );
if ( !conversionSuccess )
{
return;
Expand Down Expand Up @@ -612,6 +610,7 @@ void QgsLayoutMapWidget::updateGuiElements()
}

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

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

Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoutitem.cpp
Expand Up @@ -802,6 +802,11 @@ void QgsLayoutItem::moveContent( double, double )

}

void QgsLayoutItem::setMoveContentPreviewOffset( double, double )
{

}

void QgsLayoutItem::zoomContent( double, QPointF )
{

Expand Down
10 changes: 10 additions & 0 deletions src/core/layout/qgslayoutitem.h
Expand Up @@ -98,6 +98,7 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
UndoNodeMove, //!< Node move
UndoAtlasMargin, //!< Map atlas margin changed
UndoMapRotation, //!< Map rotation changed
UndoZoomContent, //!< Item content zoomed
};

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

/**
* Sets temporary offset for the item, by a specified \a dx and \a dy in layout units.
* This is useful for live updates when moving item content in a QgsLayoutView.
* The default implementation has no effect.
* \see moveContent()
*/
virtual void setMoveContentPreviewOffset( double dx, double dy );

/**
* Zooms content of item. Does nothing by default.
* \param factor zoom factor, where > 1 results in a zoom in and < 1 results in a zoom out
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayoutitemmap.cpp
Expand Up @@ -300,7 +300,7 @@ void QgsLayoutItemMap::moveContent( double dx, double dy )
transformShift( dx, dy );
mExtent.setXMinimum( mExtent.xMinimum() + dx );
mExtent.setXMaximum( mExtent.xMaximum() + dx );
mExtent.setYMinimum( mExtent.xMinimum() + dy );
mExtent.setYMinimum( mExtent.yMinimum() + dy );
mExtent.setYMaximum( mExtent.yMaximum() + dy );

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

void QgsLayoutItemMap::setOffset( double xOffset, double yOffset )
void QgsLayoutItemMap::setMoveContentPreviewOffset( double xOffset, double yOffset )
{
mXOffset = xOffset;
mYOffset = yOffset;
Expand Down
5 changes: 2 additions & 3 deletions src/core/layout/qgslayoutitemmap.h
Expand Up @@ -265,6 +265,8 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
void setFollowVisibilityPresetName( const QString &name ) { mFollowVisibilityPresetName = name; }

void moveContent( double dx, double dy ) override;
void setMoveContentPreviewOffset( double dx, double dy ) override;

void zoomContent( double factor, QPointF point ) override;


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

//! Sets offset values to shift image (useful for live updates when moving item content)
void setOffset( double xOffset, double yOffset );

#if 0

/**
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -172,6 +172,7 @@ SET(QGIS_GUI_SRCS
layout/qgslayoutviewtooladditem.cpp
layout/qgslayoutviewtooladdnodeitem.cpp
layout/qgslayoutviewtooleditnodes.cpp
layout/qgslayoutviewtoolmoveitemcontent.cpp
layout/qgslayoutviewtoolpan.cpp
layout/qgslayoutviewtoolselect.cpp
layout/qgslayoutviewtooltemporarykeypan.cpp
Expand Down Expand Up @@ -677,6 +678,7 @@ SET(QGIS_GUI_MOC_HDRS
layout/qgslayoutviewtooladditem.h
layout/qgslayoutviewtooladdnodeitem.h
layout/qgslayoutviewtooleditnodes.h
layout/qgslayoutviewtoolmoveitemcontent.h
layout/qgslayoutviewtoolpan.h
layout/qgslayoutviewtoolselect.h
layout/qgslayoutviewtooltemporarykeypan.h
Expand Down
4 changes: 3 additions & 1 deletion src/gui/layout/qgslayoutmousehandles.cpp
Expand Up @@ -689,11 +689,13 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )

void QgsLayoutMouseHandles::resetStatusBar()
{
if ( !mView )
return;

const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems( false );
int selectedCount = selectedItems.size();
if ( selectedCount > 1 )
{

//set status bar message to count of selected items
mView->pushStatusMessage( tr( "%1 items selected" ).arg( selectedCount ) );
}
Expand Down
8 changes: 5 additions & 3 deletions src/gui/layout/qgslayoutruler.cpp
Expand Up @@ -338,15 +338,16 @@ void QgsLayoutRuler::drawGuideAtPos( QPainter *painter, QPoint pos )

void QgsLayoutRuler::createTemporaryGuideItem()
{
mGuideItem.reset( new QGraphicsLineItem() );
delete mGuideItem;
mGuideItem = new QGraphicsLineItem();

mGuideItem->setZValue( QgsLayout::ZGuide );
QPen linePen( Qt::DotLine );
linePen.setColor( QColor( 255, 0, 0, 150 ) );
linePen.setWidthF( 0 );
mGuideItem->setPen( linePen );

mView->currentLayout()->addItem( mGuideItem.get() );
mView->currentLayout()->addItem( mGuideItem );
}

QPointF QgsLayoutRuler::convertLocalPointToLayout( QPoint localPoint ) const
Expand Down Expand Up @@ -735,7 +736,8 @@ void QgsLayoutRuler::mouseReleaseEvent( QMouseEvent *event )
{
mCreatingGuide = false;
QApplication::restoreOverrideCursor();
mGuideItem.reset();
delete mGuideItem;
mGuideItem = nullptr;

// check that cursor left the ruler
switch ( mOrientation )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/layout/qgslayoutruler.h
Expand Up @@ -121,7 +121,7 @@ class GUI_EXPORT QgsLayoutRuler: public QWidget
QgsLayoutGuide *mHoverGuide = nullptr;

bool mCreatingGuide = false;
std::unique_ptr< QGraphicsLineItem > mGuideItem;
QGraphicsLineItem *mGuideItem = nullptr;

//! Polygon for drawing guide markers
QPolygonF mGuideMarker;
Expand Down
19 changes: 11 additions & 8 deletions src/gui/layout/qgslayoutview.cpp
Expand Up @@ -54,7 +54,7 @@ QgsLayoutView::QgsLayoutView( QWidget *parent )
mSpacePanTool = new QgsLayoutViewToolTemporaryKeyPan( this );
mMidMouseButtonPanTool = new QgsLayoutViewToolTemporaryMousePan( this );
mSpaceZoomTool = new QgsLayoutViewToolTemporaryKeyZoom( this );
mSnapMarker.reset( new QgsLayoutViewSnapMarker() );
mSnapMarker = new QgsLayoutViewSnapMarker();

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

viewChanged();

mSnapMarker.reset( new QgsLayoutViewSnapMarker() );
delete mSnapMarker;
mSnapMarker = new QgsLayoutViewSnapMarker();
mSnapMarker->hide();
layout->addItem( mSnapMarker.get() );
layout->addItem( mSnapMarker );

mHorizontalSnapLine.reset( createSnapLine() );
delete mHorizontalSnapLine;
mHorizontalSnapLine = createSnapLine();
mHorizontalSnapLine->hide();
layout->addItem( mHorizontalSnapLine.get() );
mVerticalSnapLine.reset( createSnapLine() );
layout->addItem( mHorizontalSnapLine );
delete mVerticalSnapLine;
mVerticalSnapLine = createSnapLine();
mVerticalSnapLine->hide();
layout->addItem( mVerticalSnapLine.get() );
layout->addItem( mVerticalSnapLine );

if ( mHorizontalRuler )
{
Expand Down Expand Up @@ -771,7 +774,7 @@ void QgsLayoutView::mouseMoveEvent( QMouseEvent *event )
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, false ) );
if ( mTool->flags() & QgsLayoutViewTool::FlagSnaps )
{
me->snapPoint( mHorizontalSnapLine.get(), mVerticalSnapLine.get(), mTool->ignoredSnapItems() );
me->snapPoint( mHorizontalSnapLine, mVerticalSnapLine, mTool->ignoredSnapItems() );
}
if ( mTool->flags() & QgsLayoutViewTool::FlagSnaps )
{
Expand Down
6 changes: 3 additions & 3 deletions src/gui/layout/qgslayoutview.h
Expand Up @@ -470,10 +470,10 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
QgsLayoutRuler *mVerticalRuler = nullptr;
std::unique_ptr< QgsLayoutViewMenuProvider > mMenuProvider;

std::unique_ptr< QgsLayoutViewSnapMarker > mSnapMarker;
QgsLayoutViewSnapMarker *mSnapMarker = nullptr;

std::unique_ptr< QGraphicsLineItem > mHorizontalSnapLine;
std::unique_ptr< QGraphicsLineItem > mVerticalSnapLine;
QGraphicsLineItem *mHorizontalSnapLine = nullptr;
QGraphicsLineItem *mVerticalSnapLine = nullptr;

int mCurrentPage = 0;

Expand Down

0 comments on commit 7f0142c

Please sign in to comment.