diff options
author | hjk <hjk@qt.io> | 2019-03-25 09:58:16 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2019-04-08 12:00:04 +0000 |
commit | 421e025c35f8f530719e153b60a7e27af99b5ef6 (patch) | |
tree | bd4ab700f234f7d8c93983e66523a112b11eb458 /src/plugins/beautifier/uncrustify | |
parent | db4b02167a14a68c0817bac955f5aff502d10714 (diff) | |
download | qt-creator-421e025c35f8f530719e153b60a7e27af99b5ef6.tar.gz |
Beautifier: Reduce indirections
The two-phase initialization of the tools is not needed, as the
second phase is called directly after construction.
Also, the settings objects' lifetime is identical to the tools,
no need to handle that dynamically.
Change-Id: Iedfe8a95d68f9a667ef60ad9a107d0bae142b2cc
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/beautifier/uncrustify')
-rw-r--r-- | src/plugins/beautifier/uncrustify/uncrustify.cpp | 39 | ||||
-rw-r--r-- | src/plugins/beautifier/uncrustify/uncrustify.h | 9 |
2 files changed, 17 insertions, 31 deletions
diff --git a/src/plugins/beautifier/uncrustify/uncrustify.cpp b/src/plugins/beautifier/uncrustify/uncrustify.cpp index daeffdf2df..e2d2488224 100644 --- a/src/plugins/beautifier/uncrustify/uncrustify.cpp +++ b/src/plugins/beautifier/uncrustify/uncrustify.cpp @@ -29,7 +29,6 @@ #include "uncrustifyconstants.h" #include "uncrustifyoptionspage.h" -#include "uncrustifysettings.h" #include "../beautifierconstants.h" #include "../beautifierplugin.h" @@ -58,16 +57,6 @@ namespace Internal { namespace Uncrustify { Uncrustify::Uncrustify() - : m_settings(new UncrustifySettings) -{ -} - -Uncrustify::~Uncrustify() -{ - delete m_settings; -} - -bool Uncrustify::initialize() { Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::Uncrustify::MENU_ID); menu->menu()->setTitle(tr("&Uncrustify")); @@ -87,12 +76,10 @@ bool Uncrustify::initialize() Core::ActionManager::actionContainer(Constants::MENU_ID)->addMenu(menu); - connect(m_settings, &UncrustifySettings::supportedMimeTypesChanged, + connect(&m_settings, &UncrustifySettings::supportedMimeTypesChanged, [this] { updateActions(Core::EditorManager::currentEditor()); }); - new UncrustifyOptionsPage(m_settings, this); - - return true; + new UncrustifyOptionsPage(&m_settings, this); } QString Uncrustify::id() const @@ -102,7 +89,7 @@ QString Uncrustify::id() const void Uncrustify::updateActions(Core::IEditor *editor) { - const bool enabled = editor && m_settings->isApplicable(editor->document()); + const bool enabled = editor && m_settings.isApplicable(editor->document()); m_formatFile->setEnabled(enabled); m_formatRange->setEnabled(enabled); } @@ -144,17 +131,17 @@ void Uncrustify::formatSelectedText() tc.movePosition(QTextCursor::EndOfLine); const int endPos = tc.position(); formatCurrentFile(command(cfgFileName, true), startPos, endPos); - } else if (m_settings->formatEntireFileFallback()) { + } else if (m_settings.formatEntireFileFallback()) { formatFile(); } } QString Uncrustify::configurationFile() const { - if (m_settings->useCustomStyle()) - return m_settings->styleFileName(m_settings->customStyle()); + if (m_settings.useCustomStyle()) + return m_settings.styleFileName(m_settings.customStyle()); - if (m_settings->useOtherFiles()) { + if (m_settings.useOtherFiles()) { if (const ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject()) { const Utils::FileNameList files = project->files(ProjectExplorer::Project::AllFiles); @@ -168,13 +155,13 @@ QString Uncrustify::configurationFile() const } } - if (m_settings->useSpecificConfigFile()) { - const Utils::FileName file = m_settings->specificConfigFile(); + if (m_settings.useSpecificConfigFile()) { + const Utils::FileName file = m_settings.specificConfigFile(); if (file.exists()) return file.toString(); } - if (m_settings->useHomeFile()) { + if (m_settings.useHomeFile()) { const QString file = QDir::home().filePath("uncrustify.cfg"); if (QFile::exists(file)) return file; @@ -191,15 +178,15 @@ Command Uncrustify::command() const bool Uncrustify::isApplicable(const Core::IDocument *document) const { - return m_settings->isApplicable(document); + return m_settings.isApplicable(document); } Command Uncrustify::command(const QString &cfgFile, bool fragment) const { Command command; - command.setExecutable(m_settings->command()); + command.setExecutable(m_settings.command()); command.setProcessing(Command::PipeProcessing); - if (m_settings->version() >= 62) { + if (m_settings.version() >= 62) { command.addOption("--assume"); command.addOption("%file"); } else { diff --git a/src/plugins/beautifier/uncrustify/uncrustify.h b/src/plugins/beautifier/uncrustify/uncrustify.h index e35434fc81..ece235fb8b 100644 --- a/src/plugins/beautifier/uncrustify/uncrustify.h +++ b/src/plugins/beautifier/uncrustify/uncrustify.h @@ -27,22 +27,21 @@ #include "../beautifierabstracttool.h" +#include "uncrustifysettings.h" + QT_FORWARD_DECLARE_CLASS(QAction) namespace Beautifier { namespace Internal { namespace Uncrustify { -class UncrustifySettings; - class Uncrustify : public BeautifierAbstractTool { Q_OBJECT public: Uncrustify(); - ~Uncrustify() override; - bool initialize() override; + QString id() const override; void updateActions(Core::IEditor *editor) override; TextEditor::Command command() const override; @@ -53,7 +52,7 @@ private: void formatSelectedText(); QAction *m_formatFile = nullptr; QAction *m_formatRange = nullptr; - UncrustifySettings *m_settings; + UncrustifySettings m_settings; QString configurationFile() const; TextEditor::Command command(const QString &cfgFile, bool fragment = false) const; }; |