Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Last & Next zoom actions in layouts #58789

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

YoannQDQ
Copy link
Contributor

@YoannQDQ YoannQDQ commented Sep 18, 2024

Description

Adapt QgsMapCanvas zoomToLastExtent / zoomToNextExtent to the QgsLayoutView.

layout_zoom_history

@github-actions github-actions bot added this to the 3.40.0 milestone Sep 18, 2024
Copy link

github-actions bot commented Sep 18, 2024

🪟 Windows builds ready!

Windows builds of this PR are available for testing here. Debug symbols for this build are available here.

(Built from commit dc9abb6)

@nyalldawson nyalldawson added the Frozen Feature freeze - Do not merge! label Sep 18, 2024
@nyalldawson
Copy link
Collaborator

@YoannQDQ got a screencast or screenshot of this in action?

(It's great to see you back! 😁 🥳)

@YoannQDQ
Copy link
Contributor Author

Done! Also fixed pan handling. By the way @nyalldawson I noticed I can no longer edit the label(s) on the issues I create. Could I maybe get the privilege back? Thanks.

Copy link

github-actions bot commented Oct 14, 2024

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit 0353c3f)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit 0353c3f)

@YoannQDQ YoannQDQ added Feature Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks labels Oct 22, 2024
@YoannQDQ YoannQDQ modified the milestones: 3.40.0, 3.42.0 Oct 31, 2024
@YoannQDQ YoannQDQ closed this Nov 5, 2024
@YoannQDQ YoannQDQ reopened this Nov 5, 2024
@YoannQDQ YoannQDQ removed the Frozen Feature freeze - Do not merge! label Nov 5, 2024
src/app/layout/qgslayoutdesignerdialog.cpp Outdated Show resolved Hide resolved
Comment on lines 1181 to 1183
disconnect( this, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutView::extentChanged );
emit zoomLevelChanged();
connect( this, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutView::extentChanged );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong -- won't a resize generally cause a different extent? (eg when resizing to a different aspect ratio).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but actually, the term extentChanged is a bit misleading. What matters is only the center coordinates and the transform, and those won't change if the view is resized.

The problem I had was calling zoomNext or zoomLast can make the scrollbar appear or disappear, which triggers a resizeEvent, creating zoom history wipe or loops.

Also, not sure what is the emit zoomLevelChanged(); purpose here ; should the cache really be invalidated when the view is resized? If not, we can just get rid off those three lines.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I had was calling zoomNext or zoomLast can make the scrollbar appear or disappear, which triggers a resizeEvent, creating zoom history wipe or loops.

I'd handle that by adding a timer in the code which adds an entry to the zoom history. If the last entry was added < say 1 second ago, then we ignore the new one (or even better, replace the previous one!). That would also help with the case of say zooming in using a mouse wheel + ctrl key, which will fire many zoom level changes in a rapid period of time.

Also, not sure what is the emit zoomLevelChanged(); purpose here ; should the cache really be invalidated when the view is resized? If not, we can just get rid off those three lines.

Yes, it should. It triggers re-updating layout items at the new zoom level, because otherwise we'd draw them in a pixelated resized version of their previous render.

Copy link
Contributor Author

@YoannQDQ YoannQDQ Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be missing something, but I don't see how resizing the view impacts the zoom level.
qgis-bin_SV5Kqe3JAY

In the capture above, resizing the view does not resize the content, so invalidating the map item cache seems to serve no purpose.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, sorry! We don't need the zoomElevelChanged signal there.

Comment on lines +70 to +73
connect( this, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutView::extentChanged );

verticalScrollBar()->installEventFilter( this );
horizontalScrollBar()->installEventFilter( this );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could all this logic be moved into the existing QgsLayoutView::viewChanged method? That should already be getting called whenever the view extent is changed, and already handles all the different ways this can happen.

That should also avoid the emit view()->extentChanged(); calls from other classes, which is rather fragile.

Copy link
Contributor Author

@YoannQDQ YoannQDQ Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is viewChanged is called every time the scrollbar moves. So dragging the scrollbar handle will trigger many MANY viewChanged calls, and we dont want them to clutter the zoom level history. Similarly, we do not want to add entries in the history while dragging the view with the pan tool.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above -- I'd handle this by using a timer to "collapse" extents which were used very close to each other.

src/gui/layout/qgslayoutview.cpp Outdated Show resolved Hide resolved
@nyalldawson
Copy link
Collaborator

For bonus points you could handle Qt::BackButton and Qt::ForwardButton in QgsLayoutView::mouseReleaseEvent, just like we do in QgsMapCanvas. 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks
Projects
None yet
3 participants