@@ -96,6 +96,27 @@ struct DockManagerPrivate
9696 */
9797 bool restoreState (const QByteArray &state, int version);
9898
99+ void restoreDockWidgetsOpenState ();
100+ void restoreDockAreasIndices ();
101+ void emitTopLevelEvents ();
102+
103+ void hideFloatingWidgets ()
104+ {
105+ // Hide updates of floating widgets from use
106+ for (auto FloatingWidget : FloatingWidgets)
107+ {
108+ FloatingWidget->hide ();
109+ }
110+ }
111+
112+ void markDockWidgetsDirty ()
113+ {
114+ for (auto DockWidget : DockWidgetsMap)
115+ {
116+ DockWidget->setProperty (" dirty" , true );
117+ }
118+ }
119+
99120 /* *
100121 * Restores the container with the given index
101122 */
@@ -229,31 +250,29 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi
229250
230251
231252// ============================================================================
232- bool DockManagerPrivate::restoreState ( const QByteArray &state, int version )
253+ void DockManagerPrivate::restoreDockWidgetsOpenState ( )
233254{
234- if (!checkFormat (state, version))
235- {
236- qDebug () << " checkFormat: Error checking format!!!!!!!" ;
237- return false ;
238- }
239-
240- // Hide updates of floatingf widgets from use
241- for (auto FloatingWidget : FloatingWidgets)
242- {
243- FloatingWidget->hide ();
244- }
245-
255+ // All dock widgets, that have not been processed in the restore state
256+ // function are invisible to the user now and have no assigned dock area
257+ // They do not belong to any dock container, until the user toggles the
258+ // toggle view action the next time
246259 for (auto DockWidget : DockWidgetsMap)
247260 {
248- DockWidget->setProperty (" dirty" , true );
261+ if (DockWidget->property (" dirty" ).toBool ())
262+ {
263+ DockWidget->flagAsUnassigned ();
264+ }
265+ else
266+ {
267+ DockWidget->toggleViewInternal (!DockWidget->property (" closed" ).toBool ());
268+ }
249269 }
270+ }
250271
251- if (!restoreStateFromXml (state, version))
252- {
253- qDebug () << " restoreState: Error restoring state!!!!!!!" ;
254- return false ;
255- }
256272
273+ // ============================================================================
274+ void DockManagerPrivate::restoreDockAreasIndices ()
275+ {
257276 // Now all dock areas are properly restored and we setup the index of
258277 // The dock areas because the previous toggleView() action has changed
259278 // the dock area index
@@ -265,18 +284,80 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
265284 {
266285 CDockAreaWidget* DockArea = DockContainer->dockArea (i);
267286 QString DockWidgetName = DockArea->property (" currentDockWidget" ).toString ();
268- if (DockWidgetName.isEmpty ())
287+ CDockWidget* DockWidget = nullptr ;
288+ if (!DockWidgetName.isEmpty ())
269289 {
270- continue ;
290+ DockWidget = _this-> findDockWidget (DockWidgetName) ;
271291 }
272292
273- CDockWidget* DockWidget = _this->findDockWidget (DockWidgetName);
274- if (!DockWidget->isClosed ())
293+ if (!DockWidget || DockWidget->isClosed ())
294+ {
295+ int Index = DockArea->indexOfFirstOpenDockWidget ();
296+ if (Index < 0 )
297+ {
298+ continue ;
299+ }
300+ DockArea->setCurrentIndex (Index);
301+ }
302+ else
275303 {
276304 DockArea->internalSetCurrentDockWidget (DockWidget);
277305 }
278306 }
279307 }
308+ }
309+
310+
311+
312+ // ============================================================================
313+ void DockManagerPrivate::emitTopLevelEvents ()
314+ {
315+ // Finally we need to send the topLevelChanged() signals for all dock
316+ // widgets if top level changed
317+ for (auto DockContainer : Containers)
318+ {
319+ CDockWidget* TopLevelDockWidget = DockContainer->topLevelDockWidget ();
320+ if (TopLevelDockWidget)
321+ {
322+ TopLevelDockWidget->emitTopLevelChanged (true );
323+ }
324+ else
325+ {
326+ for (int i = 0 ; i < DockContainer->dockAreaCount (); ++i)
327+ {
328+ auto DockArea = DockContainer->dockArea (i);
329+ for (auto DockWidget : DockArea->dockWidgets ())
330+ {
331+ DockWidget->emitTopLevelChanged (false );
332+ }
333+ }
334+ }
335+ }
336+ }
337+
338+
339+ // ============================================================================
340+ bool DockManagerPrivate::restoreState (const QByteArray &state, int version)
341+ {
342+ if (!checkFormat (state, version))
343+ {
344+ qDebug () << " checkFormat: Error checking format!!!!!!!" ;
345+ return false ;
346+ }
347+
348+ // Hide updates of floating widgets from use
349+ hideFloatingWidgets ();
350+ markDockWidgetsDirty ();
351+
352+ if (!restoreStateFromXml (state, version))
353+ {
354+ qDebug () << " restoreState: Error restoring state!!!!!!!" ;
355+ return false ;
356+ }
357+
358+ restoreDockWidgetsOpenState ();
359+ restoreDockAreasIndices ();
360+ emitTopLevelEvents ();
280361
281362 return true ;
282363}
0 commit comments