Skip to content

Commit 9bdefd6

Browse files
Fixed issue #597 - Crashes when the floating widget moves to the dock manager and then tries to drag it back
1 parent 8fd6919 commit 9bdefd6

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

src/DockContainerWidget.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,15 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
16431643
}
16441644

16451645

1646+
//============================================================================
1647+
QList<QPointer<CDockAreaWidget>> CDockContainerWidget::removeAllDockAreas()
1648+
{
1649+
auto Result = d->DockAreas;
1650+
d->DockAreas.clear();
1651+
return Result;
1652+
}
1653+
1654+
16461655
//============================================================================
16471656
CDockAreaWidget* CDockContainerWidget::dockAreaAt(const QPoint& GlobalPos) const
16481657
{
@@ -1756,7 +1765,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
17561765
if (Dropped)
17571766
{
17581767
// Fix https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/issues/351
1759-
FloatingWidget->hideAndDeleteLater();
1768+
FloatingWidget->finishDropOperation();
17601769

17611770
// If we dropped a floating widget with only one single dock widget, then we
17621771
// drop a top level widget that changes from floating to docked now

src/DockContainerWidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
139139
*/
140140
void removeDockArea(CDockAreaWidget* area);
141141

142+
/**
143+
* Remove all dock areas and returns the list of removed dock areas
144+
*/
145+
QList<QPointer<CDockAreaWidget>> removeAllDockAreas();
146+
142147
/**
143148
* Saves the state into the given stream
144149
*/

src/FloatingDockContainer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ CFloatingDockContainer::~CFloatingDockContainer()
776776
continue;
777777
}
778778

779-
// QPointer delete safety - just in case some dock wigdet in destruction
779+
// QPointer delete safety - just in case some dock widget in destruction
780780
// deletes another related/twin or child dock widget.
781781
std::vector<QPointer<QWidget>> deleteWidgets;
782782
for (auto widget : area->dockWidgets())
@@ -1167,14 +1167,19 @@ QList<CDockWidget*> CFloatingDockContainer::dockWidgets() const
11671167
}
11681168

11691169
//============================================================================
1170-
void CFloatingDockContainer::hideAndDeleteLater()
1170+
void CFloatingDockContainer::finishDropOperation()
11711171
{
11721172
// Widget has been redocked, so it must be hidden right way (see
11731173
// https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/issues/351)
11741174
// but AutoHideChildren must be set to false because "this" still contains
11751175
// dock widgets that shall not be toggled hidden.
11761176
d->AutoHideChildren = false;
11771177
hide();
1178+
// The floating widget will be deleted now. Ensure, that the destructor
1179+
// of the floating widget does not delete any dock areas that have been
1180+
// moved to a new container - simply remove all dock areas before deleting
1181+
// the floating widget
1182+
d->DockContainer->removeAllDockAreas();
11781183
deleteLater();
11791184
if (d->DockManager)
11801185
{

src/FloatingDockContainer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ private Q_SLOTS:
258258
QList<CDockWidget*> dockWidgets() const;
259259

260260
/**
261-
* This function hides the floating bar instantely and delete it later.
261+
* This function hides the floating widget instantly and delete it later.
262262
*/
263-
void hideAndDeleteLater();
263+
void finishDropOperation();
264264

265265
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
266266
/**

0 commit comments

Comments
 (0)