forked from qt-creator/qt-creator
ClangFormatPlugin: Don't leak ClangFormatStyleFactory
Detected by memory analyzer. Remove unneeded includes. Change-Id: I270b8a6f1d98fc25297b1f69e899551399437cf0 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -4,92 +4,70 @@
|
||||
#include "clangformatplugin.h"
|
||||
|
||||
#include "clangformatconfigwidget.h"
|
||||
#include "clangformatglobalconfigwidget.h"
|
||||
#include "clangformatconstants.h"
|
||||
#include "clangformatglobalconfigwidget.h"
|
||||
#include "clangformatindenter.h"
|
||||
#include "clangformatsettings.h"
|
||||
#include "clangformatutils.h"
|
||||
#include "tests/clangformat-test.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
|
||||
#include <cppeditor/cppcodestylepreferencesfactory.h>
|
||||
#include <cppeditor/cppcodestylesettingspage.h>
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
#include <cppeditor/cppmodelmanager.h>
|
||||
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <texteditor/icodestylepreferences.h>
|
||||
#include <texteditor/textindenter.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <clang/Format/Format.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/infobar.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QMenu>
|
||||
|
||||
using namespace Core;
|
||||
using namespace CppEditor;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace TextEditor;
|
||||
using namespace Utils;
|
||||
|
||||
namespace ClangFormat {
|
||||
|
||||
class ClangFormatStyleFactory : public CppEditor::CppCodeStylePreferencesFactory
|
||||
class ClangFormatStyleFactory : public CppCodeStylePreferencesFactory
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(ClangFormatStyleFactory)
|
||||
public:
|
||||
TextEditor::Indenter *createIndenter(QTextDocument *doc) const override
|
||||
Indenter *createIndenter(QTextDocument *doc) const override
|
||||
{
|
||||
return new ClangFormatForwardingIndenter(doc);
|
||||
}
|
||||
|
||||
std::pair<CppEditor::CppCodeStyleWidget *, QString> additionalTab(
|
||||
TextEditor::ICodeStylePreferences *codeStyle,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent) const override
|
||||
std::pair<CppCodeStyleWidget *, QString> additionalTab(
|
||||
ICodeStylePreferences *codeStyle, Project *project, QWidget *parent) const override
|
||||
{
|
||||
return {new ClangFormatConfigWidget(codeStyle, project, parent), tr("ClangFormat")};
|
||||
}
|
||||
|
||||
TextEditor::CodeStyleEditorWidget *createAdditionalGlobalSettings(
|
||||
ProjectExplorer::Project *project, QWidget *parent) override
|
||||
CodeStyleEditorWidget *createAdditionalGlobalSettings(
|
||||
Project *project, QWidget *parent) override
|
||||
{
|
||||
return new ClangFormatGlobalConfigWidget(project, parent);
|
||||
}
|
||||
};
|
||||
|
||||
static void replaceCppCodeStyle()
|
||||
ClangFormatPlugin::~ClangFormatPlugin()
|
||||
{
|
||||
using namespace TextEditor;
|
||||
TextEditorSettings::unregisterCodeStyleFactory(CppEditor::Constants::CPP_SETTINGS_ID);
|
||||
TextEditorSettings::registerCodeStyleFactory(new ClangFormatStyleFactory);
|
||||
delete m_factory;
|
||||
}
|
||||
|
||||
void ClangFormatPlugin::initialize()
|
||||
{
|
||||
replaceCppCodeStyle();
|
||||
TextEditorSettings::unregisterCodeStyleFactory(CppEditor::Constants::CPP_SETTINGS_ID);
|
||||
m_factory = new ClangFormatStyleFactory;
|
||||
TextEditorSettings::registerCodeStyleFactory(m_factory);
|
||||
|
||||
ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT);
|
||||
if (contextMenu) {
|
||||
|
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
namespace TextEditor { class ICodeStylePreferencesFactory; }
|
||||
|
||||
namespace ClangFormat {
|
||||
|
||||
class ClangFormatPlugin : public ExtensionSystem::IPlugin
|
||||
@@ -12,8 +14,11 @@ class ClangFormatPlugin : public ExtensionSystem::IPlugin
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangFormat.json")
|
||||
|
||||
~ClangFormatPlugin() override;
|
||||
void initialize() final;
|
||||
QVector<QObject *> createTestObjects() const override;
|
||||
|
||||
TextEditor::ICodeStylePreferencesFactory *m_factory = nullptr;
|
||||
};
|
||||
|
||||
} // namespace ClangTools
|
||||
|
Reference in New Issue
Block a user