Skip to content
Permalink
Browse files

Working move item content tool

  • Loading branch information
nyalldawson committed Oct 21, 2017
1 parent b276f4c commit 7f0142c86a03f82318a9aed1facd5bb6002fd863
@@ -65,6 +65,7 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoNodeMove,
UndoAtlasMargin,
UndoMapRotation,
UndoZoomContent,
};

explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
@@ -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 );
@@ -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 );


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

@@ -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
@@ -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 *
************************************************************************/
@@ -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"
@@ -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 );
@@ -29,6 +29,7 @@ class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;
class QgsLayoutViewToolSelect;
class QgsLayoutViewToolEditNodes;
class QgsLayoutViewToolMoveItemContent;
class QgsLayoutRuler;
class QComboBox;
class QSlider;
@@ -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;
@@ -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
@@ -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;
@@ -612,6 +610,7 @@ void QgsLayoutMapWidget::updateGuiElements()
}

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

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

@@ -802,6 +802,11 @@ void QgsLayoutItem::moveContent( double, double )

}

void QgsLayoutItem::setMoveContentPreviewOffset( double, double )
{

}

void QgsLayoutItem::zoomContent( double, QPointF )
{

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

/**
@@ -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
@@ -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
@@ -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;
@@ -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;


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

/**
@@ -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
@@ -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
@@ -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 ) );
}
@@ -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
@@ -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 )
@@ -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;
@@ -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 );
@@ -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 )
{
@@ -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 )
{
@@ -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;

0 comments on commit 7f0142c

Please sign in to comment.
You can’t perform that action at this time.