Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ committed Nov 14, 2024
1 parent cc6a4af commit f1805b3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 19 deletions.
12 changes: 12 additions & 0 deletions python/PyQt6/gui/auto_generated/layout/qgslayoutview.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 12 additions & 0 deletions python/gui/auto_generated/layout/qgslayoutview.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4795,8 +4795,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 );
Expand Down
61 changes: 44 additions & 17 deletions src/gui/layout/qgslayoutview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,24 +589,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()
Expand All @@ -618,10 +638,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() );

Expand All @@ -640,8 +657,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()
Expand Down Expand Up @@ -1033,7 +1050,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 )
Expand Down Expand Up @@ -1178,9 +1208,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();
}

Expand Down
10 changes: 10 additions & 0 deletions src/gui/layout/qgslayoutview.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,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
Expand Down

0 comments on commit f1805b3

Please sign in to comment.