Refactor internals of KPluginFactory
Open, Needs TriagePublic

Description

Currently the code has some issues:

  • two QMultiHash are used to store the create method pointers. Considering that in normal usecases we have up to 3 plugins in total registered this seems like complete overkill.
  • having a QPair is just ugly for the hash values
  • the codepaths for CreateInstanceFunction and CreateInstanceWithMetaDataFunction are basically duplicated and only the types & some minor changes in the method signatures. Because of this we need two QMultiHash objects.
  • The warnings for the registered plugins are missing context - one can not tell which plugin/factory has emitted the error. Also registering the plugins using keywords is discouraged and will be removed in kF6.

I have made a draft for unifying the CreateInstance functions, https://invent.kde.org/frameworks/kcoreaddons/-/tree/work/alex/kplugifactory_unify_pointers My idea is to always use a metadata parameter and if the constructor does not support it we just discard it. This way we only have a container of CreateInstanceWithMetaDataFunction function pointers. Because this touches public API it has to wait for KF6. Consumers should not be affected, because the allowed constructor signatures don't change.

After that and with T14744 the QMultiHash can be refactored to a simple std::vector with a struct of the QMetaObject and create function.

The logging can already be done, https://invent.kde.org/frameworks/kcoreaddons/-/merge_requests/147

alex created this task.Oct 17 2021, 5:52 PM
alex moved this task from Backlog to Waiting on KF6 Branching on the KF6 board.Oct 19 2021, 6:39 PM
alex added a comment.Oct 20 2021, 7:18 AM

The logging can already be done, https://invent.kde.org/frameworks/kcoreaddons/-/merge_requests/147

The MR has landed and I fixed all affected code plugins in Plasma.

alex moved this task from Waiting on KF6 Branching to In Progress on the KF6 board.Feb 5 2023, 8:29 PM
alex moved this task from In Progress to Done on the KF6 board.Feb 17 2023, 1:58 PM