From 2e27de027e642c7db06724fd54f2f7f6578e8092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Mocquillon?= Date: Sat, 25 Jul 2020 13:58:42 +0000 Subject: [PATCH] Add members in AdvancedPage class to avoid memory leak when the list of cells names is updated as we recreated a completer at each notification event --- CHANGELOG.md | 1 + apps/launcher/advancedpage.cpp | 12 ++++++------ apps/launcher/advancedpage.hpp | 4 ++++ components/contentselector/view/combobox.cpp | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c98dfbe3d..e75b20dad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Feature #5524: Resume failed script execution after reload Feature #5525: Search fields tweaks (utf-8) Task #5480: Drop Qt4 support + Task #5520: Improve cell name autocompleter implementation 0.46.0 ------ diff --git a/apps/launcher/advancedpage.cpp b/apps/launcher/advancedpage.cpp index e9db74cae..00d0df048 100644 --- a/apps/launcher/advancedpage.cpp +++ b/apps/launcher/advancedpage.cpp @@ -19,15 +19,15 @@ Launcher::AdvancedPage::AdvancedPage(Files::ConfigurationManager &cfg, setupUi(this); loadSettings(); + mCellNameCompleter.setModel(&mCellNameCompleterModel); + startDefaultCharacterAtField->setCompleter(&mCellNameCompleter); } void Launcher::AdvancedPage::loadCellsForAutocomplete(QStringList cellNames) { - // Set up an auto-completer for the "Start default character at" field - auto *completer = new QCompleter(cellNames); - completer->setCompletionMode(QCompleter::PopupCompletion); - completer->setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive); - startDefaultCharacterAtField->setCompleter(completer); - + // Update the list of suggestions for the "Start default character at" field + mCellNameCompleterModel.setStringList(cellNames); + mCellNameCompleter.setCompletionMode(QCompleter::PopupCompletion); + mCellNameCompleter.setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive); } void Launcher::AdvancedPage::on_skipMenuCheckBox_stateChanged(int state) { diff --git a/apps/launcher/advancedpage.hpp b/apps/launcher/advancedpage.hpp index 3f5e5bfa7..25cb66d9d 100644 --- a/apps/launcher/advancedpage.hpp +++ b/apps/launcher/advancedpage.hpp @@ -2,6 +2,8 @@ #define ADVANCEDPAGE_H #include +#include +#include #include "ui_advancedpage.h" @@ -35,6 +37,8 @@ namespace Launcher Files::ConfigurationManager &mCfgMgr; Config::GameSettings &mGameSettings; Settings::Manager &mEngineSettings; + QCompleter mCellNameCompleter; + QStringListModel mCellNameCompleterModel; /** * Load the cells associated with the given content files for use in autocomplete diff --git a/components/contentselector/view/combobox.cpp b/components/contentselector/view/combobox.cpp index 959eca289..1ef9f9bd7 100644 --- a/components/contentselector/view/combobox.cpp +++ b/components/contentselector/view/combobox.cpp @@ -8,6 +8,7 @@ ContentSelectorView::ComboBox::ComboBox(QWidget *parent) : { mValidator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore setValidator(mValidator); + setEditable(true); setCompleter(0); setEnabled (true);