From 1daa76ae3234656aa09e0aa57beaa1d11589cc52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Mon, 21 Aug 2023 17:09:12 +0100 Subject: [PATCH] Qt: Make IOConsoleDialog a single instance When opening a console dialog, make it reuse an existing instance if it is already open. This is required because the output of the Lua code currently only goes into a single GUI dialog (the last one open). And in general it feels correct. This depends on the QAction holding the pointer reference, which seems reasonable because it is a dynamic menu action. --- ui/qt/funnel_statistics.cpp | 16 +++++++++++++--- ui/qt/funnel_statistics.h | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ui/qt/funnel_statistics.cpp b/ui/qt/funnel_statistics.cpp index 97ec2cbb9c..4265cdf364 100644 --- a/ui/qt/funnel_statistics.cpp +++ b/ui/qt/funnel_statistics.cpp @@ -224,11 +224,21 @@ FunnelConsoleAction::~FunnelConsoleAction() } void FunnelConsoleAction::triggerCallback() { - IOConsoleDialog *dialog = new IOConsoleDialog(*qobject_cast(parent()), + if (!dialog_) { + dialog_ = new IOConsoleDialog(*qobject_cast(parent()), this->text(), eval_cb_, open_cb_, close_cb_, callback_data_); - dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); + dialog_->setAttribute(Qt::WA_DeleteOnClose); + } + + if (dialog_->isMinimized()) { + dialog_->showNormal(); + } + else { + dialog_->show(); + } + dialog_->raise(); + dialog_->activateWindow(); } static QHash > funnel_actions_; diff --git a/ui/qt/funnel_statistics.h b/ui/qt/funnel_statistics.h index 5d508d5e38..f3f907c985 100644 --- a/ui/qt/funnel_statistics.h +++ b/ui/qt/funnel_statistics.h @@ -13,8 +13,10 @@ #include #include #include +#include #include +#include "io_console_dialog.h" #include "capture_file.h" #include @@ -111,6 +113,7 @@ private: funnel_console_open_cb_t open_cb_; funnel_console_close_cb_t close_cb_; void *callback_data_; + QPointer dialog_; }; extern "C" {