Skip to content

Fix Image->Properties... displaying 1 too many layers for Layer Count

Dan McCarthy requested to merge danmccarthy/krita:Fix-Layer-Count-Num into master

Fixes #447264: "Image -> Properties -> Dimensions, Number of Layers: is one more than it should be"

In Image->Properties, the number of layers displayed does not match the amount of layers in the layer docker. For example, when creating a new document, two layers are shown. Going to Image->Properties... says there are 3 layers.

This is due to the fact that under the hood, all layers are layer nodes descending from a common root layer. However, despite the fact that this rootLayer is an implementation detail, it is counted when calculating the number for the user. This is expected behavior for the nlayers() method (which is used by the Image dialog to get the count) and accounted for in unit tests.

So instead of changing the behavior of nlayers(), I have added an nChildLayers() method that counts the number of layer nodes that descend from the rootLayer without counting the rootLayer itself, and updated the Image Properties dialog to use this function instead. This allows us to get the expected layer count the user can see in the dialog.

Note: I have also included some minor typo fixes from code comments and the HACKING text file.

Test Plan

Steps to test this change:

  • Create a document, and add any number of layers.
  • Click Image from the menu bar, and then Properties....

Expected result with this change:

  • The Number of Layers: text matches the amount of layers created and seen in the Layers docker window.

Expected result in the current version of Krita:

  • The Number of Layers: text is inflated by one, since it is including the root layer.

Area of Impact:

  • With the current implementation, this change should be minimal. It does not change how nlayers() operates, which is depended on elsewhere in the codebase, and simply adds a new function that is only used by the Image Properties dialog.

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.

Demonstration of change:

Image Before/After example with single layer: BeforeAfter-Single
Image Before/After example with nested layer structure: BeforeAfter-Multiple
Edited by Dan McCarthy

Merge request reports