Skip to content

Add indexForResourceId() to models

I added indexForResourceId() entry to models. This will be used to make sure that the context menu doesn't require a whole resource. In theory one could get an index by iterating through the whole model and check if the id is the same; but I think it would be better to just make one more function in the model. That's more tidy, I think.

Note:

  • there is a difference in accessing the source model functions in different functions in proxy models. I wonder which one should I use here:

    • use sourceModel->indexForResourceId() and then mapFromSource() to get the index, or
    • iterate through the whole model to get the index with the proper resource id.

    The second method might be faster, since the proxy models are usually filtering by something. The first one is more clean though and more similar to others, and it would ensure there is no repeat in code.

  • I've made this MR to ensure I get a confirmation from @rempt that it's fine to add this function to resource models.

Test Plan

  • I think I might've forget about adding it to unit tests... damn, I'll have to remember to add it. But no existing unit tests failed, so that's something :)

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.

Merge request reports