Merge branch 'FixesPack_Parenting_Memory_leaks_etc' of https://github.com/ymiroshnyk/Qt-Advanced-Docking-System into ymiroshnyk-FixesPack_Parenting_Memory_leaks_etc

This commit is contained in:
Uwe Kindler 2020-08-24 11:22:50 +02:00
commit bfe6b9bd26
3 changed files with 9 additions and 23 deletions

View File

@ -86,18 +86,6 @@ public:
} }
/**
* Delete widgets without parents in this layout
*/
~CDockAreaLayout()
{
for(auto Widget : m_Widgets)
{
if(!Widget->parent())
delete Widget;
}
}
/** /**
* Returns the number of widgets in this layout * Returns the number of widgets in this layout
*/ */
@ -112,7 +100,6 @@ public:
*/ */
void insertWidget(int index, QWidget* Widget) void insertWidget(int index, QWidget* Widget)
{ {
Widget->setParent(nullptr);
if (index < 0) if (index < 0)
{ {
index = m_Widgets.count(); index = m_Widgets.count();
@ -143,6 +130,8 @@ public:
{ {
LayoutItem->widget()->setParent(nullptr); LayoutItem->widget()->setParent(nullptr);
} }
delete LayoutItem;
m_CurrentWidget = nullptr; m_CurrentWidget = nullptr;
m_CurrentIndex = -1; m_CurrentIndex = -1;
} }
@ -182,11 +171,7 @@ public:
parent->setUpdatesEnabled(false); parent->setUpdatesEnabled(false);
} }
auto LayoutItem = m_ParentLayout->takeAt(1); delete m_ParentLayout->takeAt(1);
if (LayoutItem)
{
LayoutItem->widget()->setParent(nullptr);
}
m_ParentLayout->addWidget(next); m_ParentLayout->addWidget(next);
if (prev) if (prev)
@ -247,7 +232,7 @@ public:
using DockAreaLayout = CDockAreaLayout; using DockAreaLayout = CDockAreaLayout;
static constexpr DockWidgetAreas DefaultAllowedAreas = AllDockAreas; static const DockWidgetAreas DefaultAllowedAreas = AllDockAreas;
/** /**

View File

@ -296,11 +296,11 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi
{ {
// Delete remaining empty floating widgets // Delete remaining empty floating widgets
int FloatingWidgetIndex = DockContainerCount - 1; int FloatingWidgetIndex = DockContainerCount - 1;
int DeleteCount = FloatingWidgets.count() - FloatingWidgetIndex; for (int i = FloatingWidgetIndex; i < FloatingWidgets.count(); ++i)
for (int i = 0; i < DeleteCount; ++i)
{ {
FloatingWidgets[FloatingWidgetIndex + i]->deleteLater(); auto* floatingWidget = FloatingWidgets[i];
_this->removeDockContainer(FloatingWidgets[FloatingWidgetIndex + i]->dockContainer()); _this->removeDockContainer(floatingWidget->dockContainer());
floatingWidget->deleteLater();
} }
} }

View File

@ -542,6 +542,7 @@ void CDockWidget::setDockArea(CDockAreaWidget* DockArea)
{ {
d->DockArea = DockArea; d->DockArea = DockArea;
d->ToggleViewAction->setChecked(DockArea != nullptr && !this->isClosed()); d->ToggleViewAction->setChecked(DockArea != nullptr && !this->isClosed());
setParent(DockArea);
} }