Skip to content

Commit

Permalink
bookmarks: avoid leaking QDialog on each show
Browse files Browse the repository at this point in the history
  • Loading branch information
vladisslav2011 committed Nov 10, 2024
1 parent 73142fa commit 20a7568
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/qtgui/dockbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <QListWidget>

#include "bookmarks.h"
#include "bookmarkstaglist.h"
#include "dockbookmarks.h"
#include "dockrxopt.h"
#include "qtcolorpicker.h"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/qtgui/dockbookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QDockWidget>
#include <QTableWidgetItem>
#include "qtgui/bookmarkstablemodel.h"
#include "qtgui/bookmarkstaglist.h"
#include <QItemDelegate>
#include <QSettings>
#include "receivers/defines.h"
Expand All @@ -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;
Expand Down

0 comments on commit 20a7568

Please sign in to comment.