From 20a756832eefe6170f1d6d7bf5452ce9e4be4da4 Mon Sep 17 00:00:00 2001 From: Vladslav P Date: Sun, 10 Nov 2024 03:33:52 +0300 Subject: [PATCH] bookmarks: avoid leaking QDialog on each show --- src/qtgui/dockbookmarks.cpp | 39 ++++++++++++++++++------------------- src/qtgui/dockbookmarks.h | 3 +++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/qtgui/dockbookmarks.cpp b/src/qtgui/dockbookmarks.cpp index 23e72ade1..4c5aaf715 100644 --- a/src/qtgui/dockbookmarks.cpp +++ b/src/qtgui/dockbookmarks.cpp @@ -31,7 +31,6 @@ #include #include "bookmarks.h" -#include "bookmarkstaglist.h" #include "dockbookmarks.h" #include "dockrxopt.h" #include "qtcolorpicker.h" @@ -100,6 +99,20 @@ DockBookmarks::DockBookmarks(QWidget *parent) : connect(ui->tableViewFrequencyList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&))); + tagsDialog = new QDialog(this); + tagsDialog->setWindowTitle("Change Bookmark Tags"); + + dialogTaglist = new BookmarksTagList(tagsDialog, false); + + QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok + | QDialogButtonBox::Cancel); + connect(buttonBox, SIGNAL(accepted()), tagsDialog, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), tagsDialog, SLOT(reject())); + + QVBoxLayout *mainLayout = new QVBoxLayout(tagsDialog); + mainLayout->addWidget(dialogTaglist); + mainLayout->addWidget(buttonBox); + // Update GUI Bookmarks::Get().load(); bookmarksTableModel->update(); @@ -319,27 +332,13 @@ void DockBookmarks::changeBookmarkTags(int row, int /*column*/) // Create and show the Dialog for a new Bookmark. // Write the result into variable 'tags'. { - QDialog dialog(this); - dialog.setWindowTitle("Change Bookmark Tags"); - - BookmarksTagList* taglist = new BookmarksTagList(&dialog, false); - taglist->updateTags(); - taglist->setSelectedTags(bmi.tags); - taglist->DeleteTag(TagInfo::strUntagged); - - QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok - | QDialogButtonBox::Cancel); - connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); - - QVBoxLayout *mainLayout = new QVBoxLayout(&dialog); - mainLayout->addWidget(taglist); - mainLayout->addWidget(buttonBox); - - ok = dialog.exec(); + dialogTaglist->updateTags(); + dialogTaglist->setSelectedTags(bmi.tags); + dialogTaglist->DeleteTag(TagInfo::strUntagged); + ok = tagsDialog->exec(); if (ok) { - tags = taglist->getSelectedTags(); + tags = dialogTaglist->getSelectedTags(); // Change Tags of Bookmark bmi.tags.clear(); diff --git a/src/qtgui/dockbookmarks.h b/src/qtgui/dockbookmarks.h index 7d426b93d..f9d376ec0 100644 --- a/src/qtgui/dockbookmarks.h +++ b/src/qtgui/dockbookmarks.h @@ -25,6 +25,7 @@ #include #include #include "qtgui/bookmarkstablemodel.h" +#include "qtgui/bookmarkstaglist.h" #include #include #include "receivers/defines.h" @@ -51,6 +52,8 @@ class DockBookmarks : public QDockWidget private: Ui::DockBookmarks *ui; QMenu* contextmenu; + QDialog* tagsDialog; + BookmarksTagList* dialogTaglist; qint64 m_currentFrequency; bool m_updating; BookmarksTableModel *bookmarksTableModel;