LayoutSaver: Support the user's factory func doing remapping
While restoring a layout, we expect all widgets to exist already, but we allow the user to create them delayed, by providing us a factory function. What we're supporting in this commit is the ability of the user's factory function returning a dock widget with an ID different than the one that was requested. We then save that mapping so the rest of the layout restore works with the new ID.
This commit is contained in:
@@ -776,11 +776,18 @@ void DockWidgetBase::onCloseEvent(QCloseEvent *e)
|
||||
|
||||
DockWidgetBase *DockWidgetBase::deserialize(const LayoutSaver::DockWidget::Ptr &saved)
|
||||
{
|
||||
DockWidgetBase *dw = DockRegistry::self()->dockByName(saved->uniqueName);
|
||||
auto dr = DockRegistry::self();
|
||||
DockWidgetBase *dw = dr->dockByName(saved->uniqueName);
|
||||
if (!dw) {
|
||||
// DockWidget doesn't exist, ask to create it
|
||||
if (auto factoryFunc = Config::self().dockWidgetFactoryFunc()) {
|
||||
// DockWidget doesn't exist, ask to create it
|
||||
dw = factoryFunc(saved->uniqueName);
|
||||
if (dw && dw->uniqueName() != saved->uniqueName) {
|
||||
// Very special case
|
||||
// The user's factory function returned a dock widget with a different ID.
|
||||
// We support it. Save the mapping though.
|
||||
dr->dockWidgetIdRemapping().insert(saved->uniqueName, dw->uniqueName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user