summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiana <iaz3@users.noreply.github.com>2018-05-18 07:45:13 -0400
committerDiana <iaz3@users.noreply.github.com>2018-05-18 07:45:13 -0400
commit6617be8ef9a015dd4109729155fc9a772997b5ed (patch)
treeab024e4423c898fa94ce2eeceba3d29f7977433a /src
parent5a5bfee7126313608d37d533ea98bca9489fa5dc (diff)
Fix a memory leak in updateToolBar
updateToolBar was creating new QActions and QWidgets every call, without cleaning them up. The spacer, help widgets, and toolbuttons only need to be created once. Those have been moved out into the MainWindow constructor updateToolBar is called in various places, importantly when adding/removing executable shortcuts. Also adds a deleteLater() call to clean up executable shortcut actions.
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp66
-rw-r--r--src/mainwindow.h2
2 files changed, 36 insertions, 32 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 5b6525bd..4d1a3b03 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -242,7 +242,28 @@ MainWindow::MainWindow(QSettings &initSettings
updateProblemsButton();
- updateToolBar();
+ // Setup toolbar
+ QWidget *spacer = new QWidget(ui->toolBar);
+ spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
+ QWidget *widget = ui->toolBar->widgetForAction(ui->actionTool);
+ QToolButton *toolBtn = qobject_cast<QToolButton*>(widget);
+
+ if (toolBtn->menu() == nullptr) {
+ actionToToolButton(ui->actionTool);
+ }
+
+ actionToToolButton(ui->actionHelp);
+ createHelpWidget();
+
+ for (QAction *action : ui->toolBar->actions()) {
+ if (action->isSeparator()) {
+ // insert spacers
+ ui->toolBar->insertWidget(action, spacer);
+ m_Sep = action;
+ // m_Sep would only use the last seperator anyway, and we only have the one anyway?
+ break;
+ }
+ }
TaskProgressManager::instance().tryCreateTaskbar();
@@ -560,41 +581,22 @@ void MainWindow::updateToolBar()
for (QAction *action : ui->toolBar->actions()) {
if (action->objectName().startsWith("custom__")) {
ui->toolBar->removeAction(action);
+ action->deleteLater();
}
}
- QWidget *spacer = new QWidget(ui->toolBar);
- spacer->setObjectName("custom__spacer");
- spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
- QWidget *widget = ui->toolBar->widgetForAction(ui->actionTool);
- QToolButton *toolBtn = qobject_cast<QToolButton*>(widget);
-
- if (toolBtn->menu() == nullptr) {
- actionToToolButton(ui->actionTool);
- }
-
- actionToToolButton(ui->actionHelp);
- createHelpWidget();
-
- for (QAction *action : ui->toolBar->actions()) {
- if (action->isSeparator()) {
- // insert spacers
- ui->toolBar->insertWidget(action, spacer);
-
- std::vector<Executable>::iterator begin, end;
- m_OrganizerCore.executablesList()->getExecutables(begin, end);
- for (auto iter = begin; iter != end; ++iter) {
- if (iter->isShownOnToolbar()) {
- QAction *exeAction = new QAction(iconForExecutable(iter->m_BinaryInfo.filePath()),
- iter->m_Title,
- ui->toolBar);
- exeAction->setObjectName(QString("custom__") + iter->m_Title);
- if (!connect(exeAction, SIGNAL(triggered()), this, SLOT(startExeAction()))) {
- qDebug("failed to connect trigger?");
- }
- ui->toolBar->insertAction(action, exeAction);
- }
+ std::vector<Executable>::iterator begin, end;
+ m_OrganizerCore.executablesList()->getExecutables(begin, end);
+ for (auto iter = begin; iter != end; ++iter) {
+ if (iter->isShownOnToolbar()) {
+ QAction *exeAction = new QAction(iconForExecutable(iter->m_BinaryInfo.filePath()),
+ iter->m_Title,
+ ui->toolBar);
+ exeAction->setObjectName(QString("custom__") + iter->m_Title);
+ if (!connect(exeAction, SIGNAL(triggered()), this, SLOT(startExeAction()))) {
+ qDebug("failed to connect trigger?");
}
+ ui->toolBar->insertAction(m_Sep, exeAction);
}
}
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index bbff0d93..02094344 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -304,6 +304,8 @@ private:
Ui::MainWindow *ui;
+ QAction *m_Sep; // Executable Shortcuts are added after this. Non owning.
+
bool m_WasVisible;
MOBase::TutorialControl m_Tutorial;