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

LayoutItem's positionning should always be relative to page #37567

Open
olivierdalang opened this issue Jul 3, 2020 · 3 comments
Open

LayoutItem's positionning should always be relative to page #37567

olivierdalang opened this issue Jul 3, 2020 · 3 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks

Comments

@olivierdalang
Copy link
Contributor

olivierdalang commented Jul 3, 2020

Describe the bug

In the UI, LayoutItem's positions are relative to a page (which you can choose using a spinbox). Internally however, the position is stored in absolute coordinates (relative to the whole layout).

A/ For the UI, as LayoutItem have no reference/index to their page, the page is determined dynamically, based on the item's position and the pages geometries. This leads to many non deterministic behaviors, (when page sizes change or are deleted, when saving/importing templates, etc.).

B/ Additionally, while coordinates are page-relative in the spinboxes, they seem so be absolute when using expressions (so that a "10" in the spinbox doesn't equal a "10" in expression unless on the first page).

Instead, I suggest we :

  • add a page index variable to LayoutItems, that would act as a hard reference to a page index
  • keep the absolute position private, and only expose the relative position in the API and for xml exports.

For backwards compatibility, if unset, the index would be 0 (first page) for all items, meaning it should be backwards compatible, as position relative to page 0 is the same as absolute position.

The page index would be changed automatically when moving items around in the canvas, but besides that, it would not be changed dynamically (so that theoretically, you can have an item linked to page 1 that appears on page 2).

(As a further step, we could even imaging allowing to position items relative to other map items instead of just pages.)

How to Reproduce

A/

  • create a new layout with two pages of 200x200mm
  • create any MapItem on the first page, roughly in the midde
  • change the first page's height to 300mm by typing 300 in the height spinbox
  • see that the MapItem ends up on the second page
    => while typing 300, the first page's height goes through 3, so that the MapItem temporarily is on the second page, then gets attached to the second page
    (this gets even worse in dynamic setups, for instance in an atlas with a data-defined page height)

B/

  • create a new layout with two pages
  • create a MapItem at 10;10 on the second page
  • set a data-defined value with expression 10 for the Y position
  • see that the MapItem gets moved to the first page

QGIS and OS versions

3.15 master, Windows

@olivierdalang olivierdalang added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jul 3, 2020
@olivierdalang
Copy link
Contributor Author

See PR #37568 that adds an expression to work around this issue

@DelazJ
Copy link
Contributor

DelazJ commented Dec 7, 2020

=> while typing 300, the first page's height goes through 3, so that the MapItem temporarily is on the second page, then gets attached to the second page
(this gets even worse in dynamic setups, for instance in an atlas with a data-defined page height)

This looks quite bad to me. If we cannot attach items to their page, can we not fix this wrong assignment by firing the signal only after the user leaves the widget?

@gioman gioman added the Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks label Dec 7, 2020
@Pedro-Murteira
Copy link

This issue is still valid on QGIS 3.22.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks
Projects
None yet
Development

No branches or pull requests

4 participants