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;
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;
@@ -126,15 +136,7 @@ void BeautifierPlugin::extensionsInitialized()
}
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();
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!
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;});
if (tool != m_tools.constEnd()) {
if (tool != std::end(m_tools)) {
if (!(*tool)->isApplicable(document))
return;
const TextEditor::Command command = (*tool)->command();

View File

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

View File

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