Beautifier: Avoid QObject parent in options page

Change-Id: I7e1162802fb6d7d7dffe143dbcdf6d85dc18d56f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-02-07 18:10:51 +01:00
parent fcafb8b482
commit b2ca5e4983
3 changed files with 16 additions and 15 deletions

View File

@@ -103,7 +103,17 @@ public:
ClangFormat::ClangFormat clangFormatBeautifier; ClangFormat::ClangFormat clangFormatBeautifier;
Uncrustify::Uncrustify uncrustifyBeautifier; Uncrustify::Uncrustify uncrustifyBeautifier;
QList<BeautifierAbstractTool *> m_tools; BeautifierAbstractTool *m_tools[3] {
&artisticStyleBeautifier,
&uncrustifyBeautifier,
&clangFormatBeautifier
};
GeneralOptionsPage optionsPage {{
artisticStyleBeautifier.id(),
uncrustifyBeautifier.id(),
clangFormatBeautifier.id()
}};
}; };
static BeautifierPluginPrivate *dd = nullptr; static BeautifierPluginPrivate *dd = nullptr;
@@ -126,15 +136,7 @@ void BeautifierPlugin::extensionsInitialized()
} }
BeautifierPluginPrivate::BeautifierPluginPrivate() BeautifierPluginPrivate::BeautifierPluginPrivate()
: m_tools({&artisticStyleBeautifier, &uncrustifyBeautifier, &clangFormatBeautifier})
{ {
QStringList toolIds;
toolIds.reserve(m_tools.count());
for (BeautifierAbstractTool *tool : m_tools)
toolIds << tool->id();
new GeneralOptionsPage(toolIds, this);
updateActions(); updateActions();
const Core::EditorManager *editorManager = Core::EditorManager::instance(); const Core::EditorManager *editorManager = Core::EditorManager::instance();
@@ -173,9 +175,9 @@ void BeautifierPluginPrivate::autoFormatOnSave(Core::IDocument *document)
// Find tool to use by id and format file! // Find tool to use by id and format file!
const QString id = generalSettings.autoFormatTool(); const QString id = generalSettings.autoFormatTool();
auto tool = std::find_if(m_tools.constBegin(), m_tools.constEnd(), auto tool = std::find_if(std::begin(m_tools), std::end(m_tools),
[&id](const BeautifierAbstractTool *t){return t->id() == id;}); [&id](const BeautifierAbstractTool *t){return t->id() == id;});
if (tool != m_tools.constEnd()) { if (tool != std::end(m_tools)) {
if (!(*tool)->isApplicable(document)) if (!(*tool)->isApplicable(document))
return; return;
const TextEditor::Command command = (*tool)->command(); const TextEditor::Command command = (*tool)->command();

View File

@@ -66,8 +66,7 @@ void GeneralOptionsPageWidget::apply()
settings->save(); settings->save();
} }
GeneralOptionsPage::GeneralOptionsPage(const QStringList &toolIds, QObject *parent) : GeneralOptionsPage::GeneralOptionsPage(const QStringList &toolIds)
IOptionsPage(parent)
{ {
setId(Constants::OPTION_GENERAL_ID); setId(Constants::OPTION_GENERAL_ID);
setDisplayName(tr("General")); setDisplayName(tr("General"));

View File

@@ -30,10 +30,10 @@
namespace Beautifier { namespace Beautifier {
namespace Internal { namespace Internal {
class GeneralOptionsPage : public Core::IOptionsPage class GeneralOptionsPage final : public Core::IOptionsPage
{ {
public: public:
GeneralOptionsPage(const QStringList &toolIds, QObject *parent); explicit GeneralOptionsPage(const QStringList &toolIds);
}; };
} // namespace Internal } // namespace Internal