forked from qt-creator/qt-creator
Debugger: Do setParent(0) on disabled dock widgets
When disabling a dock widget, we don't want it to show up in the Views menu anymore and we don't want it to interfere with other views. setParent(0) accomplishes this. However, when showing a different perspective we need to properly parent all the widgets that belong to it. Task-number: QTCREATORBUG-16027 Change-Id: I68e8cd4e6ade1dd8b23fb789f03edc39671aee91 Reviewed-by: hjk <hjk@theqtcompany.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -79,22 +79,15 @@ DebuggerMainWindow::DebuggerMainWindow()
|
|||||||
|
|
||||||
DebuggerMainWindow::~DebuggerMainWindow()
|
DebuggerMainWindow::~DebuggerMainWindow()
|
||||||
{
|
{
|
||||||
// We keep track of widgets for operations that haven't been activated, yet, and make sure we
|
// As we have to setParent(0) on dock widget that are not selected,
|
||||||
// don't leak any.
|
// we keep track of all and make sure we don't leak any
|
||||||
foreach (const Perspective &perspective, m_perspectiveForPerspectiveId) {
|
foreach (const Perspective &perspective, m_perspectiveForPerspectiveId) {
|
||||||
foreach (const Perspective::Operation &operation, perspective.operations()) {
|
foreach (const Perspective::Operation &operation, perspective.operations()) {
|
||||||
if (operation.widget) {
|
if (operation.widget && !operation.widget->parentWidget()) {
|
||||||
// There are two possible states: Either addDockForWidget(widget) has
|
// These are from inactive perspectives. We call setParent(0) when deactivating
|
||||||
// been called on an operation.widget (e.g. when the perspective gets
|
// a perspective so that the widgets can't be accidentally enabled in the wrong
|
||||||
// activated for the first time), or not. In the first case we don't
|
// perspectives. That's why we have to delete them manually here.
|
||||||
// have to explicitly delete it as we have called setParent(this) on
|
delete operation.widget;
|
||||||
// it. In the second case, if the widget didn't have a parent before,
|
|
||||||
// we have to delete it.
|
|
||||||
if (!operation.widget->parentWidget()) {
|
|
||||||
// These are from perspectives that were never activated and didn't
|
|
||||||
// have a parent to begin with.
|
|
||||||
delete operation.widget;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,9 +259,10 @@ void DebuggerMainWindow::loadPerspectiveHelper(const QByteArray &perspectiveId,
|
|||||||
foreach (QDockWidget *dockWidget, m_dockForDockId) {
|
foreach (QDockWidget *dockWidget, m_dockForDockId) {
|
||||||
QTC_ASSERT(dockWidget, continue);
|
QTC_ASSERT(dockWidget, continue);
|
||||||
dockWidget->setFloating(false);
|
dockWidget->setFloating(false);
|
||||||
dockWidget->setParent(this);
|
|
||||||
removeDockWidget(dockWidget);
|
removeDockWidget(dockWidget);
|
||||||
dockWidget->hide();
|
dockWidget->hide();
|
||||||
|
// Prevent saveState storing the data of the wrong children.
|
||||||
|
dockWidget->setParent(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ICore::removeAdditionalContext(Context(Id::fromName(m_currentPerspectiveId)));
|
ICore::removeAdditionalContext(Context(Id::fromName(m_currentPerspectiveId)));
|
||||||
@@ -303,6 +297,8 @@ void DebuggerMainWindow::loadPerspectiveHelper(const QByteArray &perspectiveId,
|
|||||||
|
|
||||||
ActionManager::actionContainer(Core::Constants::M_WINDOW_VIEWS)->addAction(cmd);
|
ActionManager::actionContainer(Core::Constants::M_WINDOW_VIEWS)->addAction(cmd);
|
||||||
}
|
}
|
||||||
|
// Restore parent/child relation, so that the widget hierarchy is clear.
|
||||||
|
dock->setParent(this);
|
||||||
if (operation.operationType == Perspective::Raise) {
|
if (operation.operationType == Perspective::Raise) {
|
||||||
dock->raise();
|
dock->raise();
|
||||||
continue;
|
continue;
|
||||||
@@ -361,7 +357,6 @@ QDockWidget *DebuggerMainWindow::registerDockWidget(const QByteArray &dockId, QW
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(!widget->objectName().isEmpty(), return 0);
|
QTC_ASSERT(!widget->objectName().isEmpty(), return 0);
|
||||||
QDockWidget *dockWidget = addDockForWidget(widget);
|
QDockWidget *dockWidget = addDockForWidget(widget);
|
||||||
dockWidget->setParent(this);
|
|
||||||
m_dockForDockId[dockId] = dockWidget;
|
m_dockForDockId[dockId] = dockWidget;
|
||||||
return dockWidget;
|
return dockWidget;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user