Delete Extra Widgets on Close (#1490)

This commit is contained in:
Florian Märkl 2019-04-27 11:46:29 +02:00 committed by GitHub
parent dff08963a1
commit 1cc6abee44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 5 deletions

View File

@ -315,24 +315,25 @@ void MainWindow::updateTasksIndicator()
void MainWindow::on_actionExtraGraph_triggered()
{
QDockWidget *extraDock = new GraphWidget(this, 0);
auto *extraDock = new GraphWidget(this, nullptr);
addExtraWidget(extraDock);
}
void MainWindow::on_actionExtraHexdump_triggered()
{
QDockWidget *extraDock = new HexdumpWidget(this, 0);
auto *extraDock = new HexdumpWidget(this, nullptr);
addExtraWidget(extraDock);
}
void MainWindow::on_actionExtraDisassembly_triggered()
{
QDockWidget *extraDock = new DisassemblyWidget(this, 0);
auto *extraDock = new DisassemblyWidget(this, nullptr);
addExtraWidget(extraDock);
}
void MainWindow::addExtraWidget(QDockWidget *extraDock)
void MainWindow::addExtraWidget(CutterDockWidget *extraDock)
{
extraDock->setTransient(true);
addDockWidget(Qt::TopDockWidgetArea, extraDock);
auto restoreExtraDock = qhelpers::forceWidth(extraDock->widget(), 600);
qApp->processEvents();

View File

@ -96,7 +96,7 @@ public:
void addToDockWidgetList(QDockWidget *dockWidget);
void addDockWidgetAction(QDockWidget *dockWidget, QAction *action);
void addExtraWidget(QDockWidget *extraDock);
void addExtraWidget(CutterDockWidget *extraDock);
void addPluginDockWidget(QDockWidget *dockWidget, QAction *action);
enum class MenuType { File, Edit, View, Windows, Debug, Help, Plugins };

View File

@ -68,6 +68,9 @@ void CutterDockWidget::closeEvent(QCloseEvent *event)
this->action->setChecked(false);
}
QDockWidget::closeEvent(event);
if (isTransient) {
deleteLater();
}
}
QAction *CutterDockWidget::getBoundAction() const

View File

@ -17,6 +17,12 @@ public:
bool eventFilter(QObject *object, QEvent *event) override;
bool isVisibleToUser() { return isVisibleToUserCurrent; }
/**
* @brief Set whether the Widget should be deleted after it is closed.
* This is especially important for extra widgets.
*/
void setTransient(bool v) { isTransient = v; }
/**
* @brief Convenience method for creating and registering a RefreshDeferrer without any parameters
* @param refreshNowFunc lambda taking no parameters, called when a refresh should occur
@ -64,6 +70,8 @@ protected:
private:
QAction *action;
bool isTransient = false;
bool isVisibleToUserCurrent = false;
void updateIsVisibleToUser();
};