From 69d53245f25d566566794e8c81ace2b779551867 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 20 Apr 2023 10:54:44 +0200 Subject: [PATCH] Python: Avoid IOptionPageWidget::widget() in settings This is planned to become inaccessible for user code. Change-Id: I2530a6ccf9f46cedff68ae62e8ac3d42d6792e0a Reviewed-by: David Schulz --- src/plugins/python/pythonsettings.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/plugins/python/pythonsettings.cpp b/src/plugins/python/pythonsettings.cpp index ff3a18ef149..714b8158189 100644 --- a/src/plugins/python/pythonsettings.cpp +++ b/src/plugins/python/pythonsettings.cpp @@ -318,34 +318,37 @@ public: setCategory(Constants::C_PYTHON_SETTINGS_CATEGORY); setDisplayCategory(Tr::tr("Python")); setCategoryIconPath(":/python/images/settingscategory_python.png"); - setWidgetCreator([]() { return new InterpreterOptionsWidget(); }); + setWidgetCreator([this] { m_widget = new InterpreterOptionsWidget; return m_widget; }); } QList interpreters() { - if (auto w = static_cast(widget())) - return w->interpreters(); + if (m_widget) + return m_widget->interpreters(); return {}; } void addInterpreter(const Interpreter &interpreter) { - if (auto w = static_cast(widget())) - w->addInterpreter(interpreter); + if (m_widget) + m_widget->addInterpreter(interpreter); } void removeInterpreterFrom(const QString &detectionSource) { - if (auto w = static_cast(widget())) - w->removeInterpreterFrom(detectionSource); + if (m_widget) + m_widget->removeInterpreterFrom(detectionSource); } QList interpreterFrom(const QString &detectionSource) { - if (auto w = static_cast(widget())) - return w->interpreterFrom(detectionSource); + if (m_widget) + return m_widget->interpreterFrom(detectionSource); return {}; } + +private: + InterpreterOptionsWidget *m_widget = nullptr; }; static bool alreadyRegistered(const QList &pythons, const FilePath &pythonExecutable)