panels: fixed bug that added panel to list twice and led to double-free
This commit is contained in:
@@ -35,12 +35,10 @@ PanelManager::PanelManager(QObject *parent) :
|
||||
|
||||
void PanelManager::DeleteAllPanels()
|
||||
{
|
||||
foreach (PanelWidget* panel, focus_history_) {
|
||||
// We don't need to run this signal anymore since we're destroying and clearing everything
|
||||
disconnect(panel, &PanelWidget::destroyed, this, &PanelManager::PanelDestroyed);
|
||||
delete panel;
|
||||
}
|
||||
// Prevent any confusion regarding focus history by clearing it first
|
||||
QList<PanelWidget*> copy = focus_history_;
|
||||
focus_history_.clear();
|
||||
qDeleteAll(copy);
|
||||
}
|
||||
|
||||
const QList<PanelWidget *> &PanelManager::panels()
|
||||
|
||||
@@ -175,18 +175,26 @@ T *PanelManager::CreatePanel(QWidget *parent)
|
||||
{
|
||||
T* panel = new T(parent);
|
||||
|
||||
panel->SetMovementLocked(locked_);
|
||||
|
||||
// Sane default for panel geometry
|
||||
panel->resize(parent->size() / 3);
|
||||
panel->move(panel->mapFromGlobal(parent->mapToGlobal(parent->pos())));
|
||||
|
||||
// Connect destroy signal so we can remove it from focus history
|
||||
connect(panel, &PanelWidget::destroyed, this, &PanelManager::PanelDestroyed);
|
||||
|
||||
// Add panel to the bottom of the focus history
|
||||
focus_history_.append(panel);
|
||||
|
||||
panel->SetMovementLocked(locked_);
|
||||
|
||||
// Sane default for panel size
|
||||
panel->resize(parent->size() / 3);
|
||||
|
||||
// We're about to center the panel relative to the parent (usually the main window), but for some
|
||||
// reason this requires the panel to be shown first.
|
||||
panel->show();
|
||||
|
||||
// Center the panel relative to the parent
|
||||
QPoint parent_center = panel->mapFromGlobal(parent->mapToGlobal(parent->rect().center()));
|
||||
QPoint panel_center = panel->rect().center();
|
||||
panel->move(parent_center - panel_center);
|
||||
|
||||
// Connect destroy signal so we can remove it from focus history
|
||||
connect(panel, &PanelWidget::destroyed, this, &PanelManager::PanelDestroyed, Qt::DirectConnection);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user