Skip to content

Commit

Permalink
Fixed issue #597 - Crashes when the floating widget moves to the dock…
Browse files Browse the repository at this point in the history
… manager and then tries to drag it back
  • Loading branch information
githubuser0xFFFF committed Jan 16, 2024
1 parent 8fd6919 commit 9bdefd6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/DockContainerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,15 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
}


//============================================================================
QList<QPointer<CDockAreaWidget>> CDockContainerWidget::removeAllDockAreas()
{
auto Result = d->DockAreas;
d->DockAreas.clear();
return Result;
}


//============================================================================
CDockAreaWidget* CDockContainerWidget::dockAreaAt(const QPoint& GlobalPos) const
{
Expand Down Expand Up @@ -1756,7 +1765,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
if (Dropped)
{
// Fix https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/issues/351
FloatingWidget->hideAndDeleteLater();
FloatingWidget->finishDropOperation();

// If we dropped a floating widget with only one single dock widget, then we
// drop a top level widget that changes from floating to docked now
Expand Down
5 changes: 5 additions & 0 deletions src/DockContainerWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
*/
void removeDockArea(CDockAreaWidget* area);

/**
* Remove all dock areas and returns the list of removed dock areas
*/
QList<QPointer<CDockAreaWidget>> removeAllDockAreas();

/**
* Saves the state into the given stream
*/
Expand Down
9 changes: 7 additions & 2 deletions src/FloatingDockContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ CFloatingDockContainer::~CFloatingDockContainer()
continue;
}

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

//============================================================================
void CFloatingDockContainer::hideAndDeleteLater()
void CFloatingDockContainer::finishDropOperation()
{
// Widget has been redocked, so it must be hidden right way (see
// https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/issues/351)
// but AutoHideChildren must be set to false because "this" still contains
// dock widgets that shall not be toggled hidden.
d->AutoHideChildren = false;
hide();
// The floating widget will be deleted now. Ensure, that the destructor
// of the floating widget does not delete any dock areas that have been
// moved to a new container - simply remove all dock areas before deleting
// the floating widget
d->DockContainer->removeAllDockAreas();
deleteLater();
if (d->DockManager)
{
Expand Down
4 changes: 2 additions & 2 deletions src/FloatingDockContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ private Q_SLOTS:
QList<CDockWidget*> dockWidgets() const;

/**
* This function hides the floating bar instantely and delete it later.
* This function hides the floating widget instantly and delete it later.
*/
void hideAndDeleteLater();
void finishDropOperation();

#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
/**
Expand Down

0 comments on commit 9bdefd6

Please sign in to comment.