Skip to content

Commit 156cc71

Browse files
Fix emission of viewToggled() signal for dock widgets that are not part of the state that is restored
1 parent 664a167 commit 156cc71

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

demo/MainWindow.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ void MainWindowPrivate::createContent()
226226
auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
227227
DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
228228
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
229+
//DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
230+
//DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
231+
232+
for (auto DockWidget : DockManager->dockWidgetsMap())
233+
{
234+
_this->connect(DockWidget, SIGNAL(viewToggled(bool)), SLOT(onViewToggled(bool)));
235+
}
229236
}
230237

231238

@@ -375,3 +382,16 @@ void CMainWindow::savePerspective()
375382
d->savePerspectives();
376383
}
377384

385+
386+
//============================================================================
387+
void CMainWindow::onViewToggled(bool Open)
388+
{
389+
auto DockWidget = qobject_cast<ads::CDockWidget*>(sender());
390+
if (!DockWidget)
391+
{
392+
return;
393+
}
394+
395+
qDebug() << DockWidget->objectName() << " viewToggled(" << Open << ")";
396+
}
397+

demo/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private slots:
5858
void on_actionSaveState_triggered(bool);
5959
void on_actionRestoreState_triggered(bool);
6060
void savePerspective();
61+
void onViewToggled(bool Open);
6162
};
6263

6364
#endif // MAINWINDOW_H

src/DockContainerWidget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,13 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
695695
QWidget*& CreatedWidget, bool Testing)
696696
{
697697
bool Ok;
698+
#ifdef ADS_DEBUG_PRINT
698699
int Tabs = s.attributes().value("Tabs").toInt(&Ok);
699700
if (!Ok)
700701
{
701702
return false;
702703
}
703-
704+
#endif
704705

705706
QString CurrentDockWidget = s.attributes().value("Current").toString();
706707
ADS_PRINT("Restore NodeDockArea Tabs: " << Tabs << " Current: "
@@ -745,8 +746,8 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
745746
DockArea->addDockWidget(DockWidget);
746747
DockWidget->setToggleViewActionChecked(!Closed);
747748
DockWidget->setClosedState(Closed);
748-
DockWidget->setProperty("closed", Closed);
749-
DockWidget->setProperty("dirty", false);
749+
DockWidget->setProperty(internal::ClosedProperty, Closed);
750+
DockWidget->setProperty(internal::DirtyProperty, false);
750751
}
751752

752753
if (Testing)

src/DockManager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct DockManagerPrivate
102102

103103
void hideFloatingWidgets()
104104
{
105-
// Hide updates of floating widgets from use
105+
// Hide updates of floating widgets from user
106106
for (auto FloatingWidget : FloatingWidgets)
107107
{
108108
FloatingWidget->hide();
@@ -221,7 +221,9 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi
221221
}
222222

223223
bool Result = true;
224+
#ifdef ADS_DEBUG_PRINT
224225
int DockContainers = s.attributes().value("Containers").toInt();
226+
#endif
225227
ADS_PRINT(DockContainers);
226228
int DockContainerCount = 0;
227229
while (s.readNextStartElement())
@@ -262,13 +264,14 @@ void DockManagerPrivate::restoreDockWidgetsOpenState()
262264
// toggle view action the next time
263265
for (auto DockWidget : DockWidgetsMap)
264266
{
265-
if (DockWidget->property("dirty").toBool())
267+
if (DockWidget->property(internal::DirtyProperty).toBool())
266268
{
267269
DockWidget->flagAsUnassigned();
270+
emit DockWidget->viewToggled(false);
268271
}
269272
else
270273
{
271-
DockWidget->toggleViewInternal(!DockWidget->property("closed").toBool());
274+
DockWidget->toggleViewInternal(!DockWidget->property(internal::ClosedProperty).toBool());
272275
}
273276
}
274277
}

src/FloatingDockContainer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ void CFloatingDockContainer::closeEvent(QCloseEvent *event)
373373
void CFloatingDockContainer::hideEvent(QHideEvent *event)
374374
{
375375
Super::hideEvent(event);
376+
// Prevent toogleView() events during restore state
377+
if (d->DockManager->isRestoringState())
378+
{
379+
return;
380+
}
381+
376382
for (auto DockArea : d->DockContainer->openedDockAreas())
377383
{
378384
for (auto DockWidget : DockArea->openedDockWidgets())

src/ads_globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ namespace internal
100100
{
101101
static const bool RestoreTesting = true;
102102
static const bool Restore = false;
103+
static const char* const ClosedProperty = "close";
104+
static const char* const DirtyProperty = "dirty";
103105

104106
/**
105107
* Replace the from widget in the given splitter with the To widget

0 commit comments

Comments
 (0)