Page MenuHomePhabricator

Control category/view toolbar visibility through preferences
Closed, ResolvedPublic

Description

We'd like to control the visibility of tool bars in MITK applications through preferences to ease access to this functionality also to other parts of MITK. This task is dedicated to the first step in that direction: Enumerate all tool bars in the preferences with a checkbox for visibility and apply visibility as soon as preference changes are applied.

Unfortunately the actual Qt tool bars are hidden behind multiple layers of abstraction and interfaces that are partly explicitly made private to prevent access. Multiple BlueBerry classes would need substantial interface and dependency changes to allow for an easy interface access. Ideally, no extra code should be necessary in the window advisors derivates of our applications, which ultimately set up everything. With a simple contract, we can circumvent all these changes. The toolbars already use QWidget::objectName() to set their name/id to "<category> View Toolbar", which is a bit arbitrary (and already has a typo) for our purposes. I propose to simply change their name to "<category>", which is an easy and clear contract and then use Qt to query all toolbars of all Workbench windows and compare their names accordingly. Access to the QMainWindow through BlueBerry is possible and already done at a few places.

Revisions and Commits

rMITK MITK
Restricted Differential Revision
Restricted Differential Revision

Event Timeline

kislinsk triaged this task as Normal priority.Nov 28 2023, 1:10 PM
kislinsk created this task.
kislinsk added a revision: Restricted Differential Revision.Nov 28 2023, 1:25 PM

Since it is already buried in the Diff by Jenkins comments, I paste it here as well:

In D890#33845, @kislinsk wrote:

Brainstorming on how to effectively apply these preferences (and other future preferences in that direction) at application startup:

  • (A) Plugin with eager activation policy that applies preferences
    • Is everything we need already up and running at this early stage?
  • (B) Workbench Window Advisors themselves query and care for preferences
    • I don't really like this idea as it encourages code duplication again and another burden for future applications devs
  • (C) ?

Turns out, eager plugins start too early to be of any use here (A). Regarding (B), preferences are already queried in the Workbench Window Advisors for the visibility of the category labels in tool bars, so it would be like two lines to get the preferences applied also at application startup, at the price of having to do it in each Workbench Window Advisor:

auto* toolBarsPrefs = prefService->GetSystemPreferences()->Node("org.mitk.gui.qt.application/toolbars");
toolbar->setVisible(toolBarsPrefs->GetBool(category.toStdString(), true));

Deleted branch from rMITK MITK: feature/T30284-ToolBarVisibilityThroughPreferences.