Skip to content

Conversation

@rolivav
Copy link

@rolivav rolivav commented Oct 12, 2021

Sorry for the wall of text, since we talked about this before this is my attempt at making you understand the problem and why this feature is needed.

As we know, by default all widgets are supposed to be created at the start of the application and using the save states (or perspectives) the widgets are shown or hidden (and kept alive). I would say this is fine for most applications, but in more complex applications, it raises several problems:

  • Several of the shown widgets could have the same underlying components and connect to the same signals and systems. When debugging a particular slot that is listened to by several instances of the same widget, it becomes quite painful to find the right instance. Being able to close of delete other instances is a very fast way to improve this process.
  • It is common for users to open a complex widget and notice a slow down. They might be in underpowered machines that are not capable of running a lot of widgets at the same time without penalty. The expected result is that they attempt to close widgets to see if the application can run faster. This was the case in our application before ADS was implemented. If the widgets would delete on close it would improve the situation drastically for them.

The DeleteOnClose flag allows this deletion to happen, but with limitations. Using the flag, dock widgets are fully deleted and will lose all context about the place where they were spawned. This behavior is fine for widgets that always have a specific spawning area and that might be infinite in number; it is mainly intended for document widgets and it works wonderfully for that. For regular widgets though, this is not great at all, users expect the widget to reappear in the same place where they closed it.

The new flag is intended to use the default capabilities of ADS and allow for application widgets to be deleted and recreated internally by the dock widgets themselves. This allows to keep the context of the dock widgets as usual, and save them and everything, while at the same time be able to delete and release the resources of these complex widgets. This improves memory usage of the application, allows the user to optimize it a bit and allows for a better debugging experience. Additionally, in my case it allows plugins to retain their position when they are installed or uninstalled, and appear in the same place with minimal impact.

This is a gif of it in action, I added a menu action in the deleteonclose without modifying the other two actions to see how it behaves in comparison.
w3wFtJGNCO

…om a factory when closing and opening the dock widget.
Comment on lines +58 to +59
auto editor = new QTextEdit(QStringLiteral("recreated lorem ipsum......"), dw);
dw->setWidget(editor);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showDockWidget is not called unless the widget was closed previously. Since the factory is only used in showDockWidget, we need to create the widget originally and set it if we want the widget to be there from the beginning. This to me is a feature: it allows to only initialize the widgets that should be there, so we don't get the constructor of hidden widgets called at all until they are shown when restoring the dock system state.

@githubuser0xFFFF githubuser0xFFFF merged commit 03a8eaa into githubuser0xFFFF:master Oct 14, 2021
@githubuser0xFFFF
Copy link
Owner

Thank you for this pull request - nice feature. I merged your pull request with some small changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants