diff --git a/python/PyQt6/gui/auto_generated/layout/qgslayoutview.sip.in b/python/PyQt6/gui/auto_generated/layout/qgslayoutview.sip.in index 61ee8dbabe66..d26ca09e2227 100644 --- a/python/PyQt6/gui/auto_generated/layout/qgslayoutview.sip.in +++ b/python/PyQt6/gui/auto_generated/layout/qgslayoutview.sip.in @@ -354,7 +354,19 @@ Zooms to the next zoom level .. versionadded:: 3.42 %End + bool canZoomLast() const; +%Docstring +Whether zoom last is available + +.. versionadded:: 3.42 +%End + bool canZoomNext() const; +%Docstring +Whether zoom next is available + +.. versionadded:: 3.42 +%End void emitZoomLevelChanged(); diff --git a/python/gui/auto_generated/layout/qgslayoutview.sip.in b/python/gui/auto_generated/layout/qgslayoutview.sip.in index ca7ce79be52e..a73ebfba49e5 100644 --- a/python/gui/auto_generated/layout/qgslayoutview.sip.in +++ b/python/gui/auto_generated/layout/qgslayoutview.sip.in @@ -354,7 +354,19 @@ Zooms to the next zoom level .. versionadded:: 3.42 %End + bool canZoomLast() const; +%Docstring +Whether zoom last is available + +.. versionadded:: 3.42 +%End + bool canZoomNext() const; +%Docstring +Whether zoom next is available + +.. versionadded:: 3.42 +%End void emitZoomLevelChanged(); diff --git a/src/app/layout/qgslayoutdesignerdialog.cpp b/src/app/layout/qgslayoutdesignerdialog.cpp index 0168d26648d7..405eaa00e456 100644 --- a/src/app/layout/qgslayoutdesignerdialog.cpp +++ b/src/app/layout/qgslayoutdesignerdialog.cpp @@ -4575,8 +4575,8 @@ void QgsLayoutDesignerDialog::toggleActions( bool layoutAvailable ) mActionZoomOut->setEnabled( layoutAvailable ); mActionZoomActual->setEnabled( layoutAvailable ); mActionZoomToWidth->setEnabled( layoutAvailable ); - mActionZoomLast->setEnabled( layoutAvailable ); - mActionZoomNext->setEnabled( layoutAvailable ); + mActionZoomLast->setEnabled( layoutAvailable && mView->canZoomLast() ); + mActionZoomNext->setEnabled( layoutAvailable && mView->canZoomNext() ); mActionAddPages->setEnabled( layoutAvailable ); mActionShowGrid->setEnabled( layoutAvailable ); mActionSnapGrid->setEnabled( layoutAvailable ); diff --git a/src/gui/layout/qgslayoutview.cpp b/src/gui/layout/qgslayoutview.cpp index 84228c50bac1..01b56d3b4e1b 100644 --- a/src/gui/layout/qgslayoutview.cpp +++ b/src/gui/layout/qgslayoutview.cpp @@ -586,24 +586,44 @@ void QgsLayoutView::zoomActual() void QgsLayoutView::zoomLast() { + if ( !canZoomLast() ) + return; mLastTransformIndex--; centerOn( mLastTransform[mLastTransformIndex].first ); - setTransform( mLastTransform[mLastTransformIndex].second ); - invalidateCachedRenders(); + if ( transform() != mLastTransform[mLastTransformIndex].second ) + { + setTransform( mLastTransform[mLastTransformIndex].second ); + invalidateCachedRenders(); + } // update controls' enabled state - emit zoomLastStatusChanged( mLastTransformIndex > 0 ); - emit zoomNextStatusChanged( mLastTransformIndex < mLastTransform.size() - 1 ); + emit zoomLastStatusChanged( canZoomLast() ); + emit zoomNextStatusChanged( canZoomNext() ); } void QgsLayoutView::zoomNext() { + if ( !canZoomNext() ) + return; mLastTransformIndex++; centerOn( mLastTransform[mLastTransformIndex].first ); - setTransform( mLastTransform[mLastTransformIndex].second ); - invalidateCachedRenders(); + if ( transform() != mLastTransform[mLastTransformIndex].second ) + { + setTransform( mLastTransform[mLastTransformIndex].second ); + invalidateCachedRenders(); + } // update controls' enabled state - emit zoomLastStatusChanged( mLastTransformIndex > 0 ); - emit zoomNextStatusChanged( mLastTransformIndex < mLastTransform.size() - 1 ); + emit zoomLastStatusChanged( canZoomLast() ); + emit zoomNextStatusChanged( canZoomNext() ); +} + +bool QgsLayoutView::canZoomNext() const +{ + return mLastTransformIndex < mLastTransform.size() - 1; +} + +bool QgsLayoutView::canZoomLast() const +{ + return mLastTransformIndex > 0; } void QgsLayoutView::emitZoomLevelChanged() @@ -615,10 +635,7 @@ void QgsLayoutView::onExtentChanged() { //clear all transforms items after current index - for ( int i = mLastTransform.size() - 1; i > mLastTransformIndex; i-- ) - { - mLastTransform.removeAt( i ); - } + mLastTransform = mLastTransform.mid( 0, mLastTransformIndex + 1 ); QPointF center = mapToScene( viewport()->rect().center() ); @@ -637,8 +654,8 @@ void QgsLayoutView::onExtentChanged() mLastTransformIndex = mLastTransform.size() - 1; // update controls' enabled state - emit zoomLastStatusChanged( mLastTransformIndex > 0 ); - emit zoomNextStatusChanged( mLastTransformIndex < mLastTransform.size() - 1 ); + emit zoomLastStatusChanged( canZoomLast() ); + emit zoomNextStatusChanged( canZoomNext() ); } void QgsLayoutView::selectAll() @@ -1030,7 +1047,20 @@ void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event ) } if ( !mTool || !event->isAccepted() ) + { + + if ( event->button() == Qt::BackButton ) + { + zoomLast(); + return; + } + else if ( event->button() == Qt::ForwardButton ) + { + zoomNext(); + return; + } QGraphicsView::mouseReleaseEvent( event ); + } } void QgsLayoutView::mouseMoveEvent( QMouseEvent *event ) @@ -1175,9 +1205,6 @@ void QgsLayoutView::keyReleaseEvent( QKeyEvent *event ) void QgsLayoutView::resizeEvent( QResizeEvent *event ) { QGraphicsView::resizeEvent( event ); - disconnect( this, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutView::extentChanged ); - emit zoomLevelChanged(); - connect( this, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutView::extentChanged ); viewChanged(); } diff --git a/src/gui/layout/qgslayoutview.h b/src/gui/layout/qgslayoutview.h index e29e0f97d8a5..9417f6eff46a 100644 --- a/src/gui/layout/qgslayoutview.h +++ b/src/gui/layout/qgslayoutview.h @@ -352,7 +352,17 @@ class GUI_EXPORT QgsLayoutView : public QGraphicsView */ void zoomNext(); + /** + * Whether zoom last is available + * \since QGIS 3.42 + */ + bool canZoomLast() const; + /** + * Whether zoom next is available + * \since QGIS 3.42 + */ + bool canZoomNext() const; /** * Emits the zoomLevelChanged() signal. This should be called after