forked from qt-creator/qt-creator
qmljstools: de-noise
De-pimpl qmljstoolssettings, no need to pimpl a simple pointer. Add using namespace TextEditor. Remove direct instance access. Change-Id: I6b07d209a387d31735b95bc35e60a49a3ace7ca2 Reviewed-by: Daniel Teske <daniel.teske@digia.com> Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com>
This commit is contained in:
@@ -43,53 +43,40 @@
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
static const char *idKey = "QmlJSGlobal";
|
||||
|
||||
using namespace QmlJSTools;
|
||||
using TextEditor::TabSettings;
|
||||
using namespace TextEditor;
|
||||
|
||||
namespace QmlJSTools {
|
||||
namespace Internal {
|
||||
|
||||
class QmlJSToolsSettingsPrivate
|
||||
{
|
||||
public:
|
||||
TextEditor::SimpleCodeStylePreferences *m_globalCodeStyle;
|
||||
};
|
||||
const char idKey[] = "QmlJSGlobal";
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlJSTools
|
||||
|
||||
QmlJSToolsSettings *QmlJSToolsSettings::m_instance = 0;
|
||||
static TextEditor::SimpleCodeStylePreferences *m_globalCodeStyle = 0;
|
||||
|
||||
QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
|
||||
: QObject(parent)
|
||||
, d(new Internal::QmlJSToolsSettingsPrivate)
|
||||
{
|
||||
QTC_ASSERT(!m_instance, return);
|
||||
m_instance = this;
|
||||
QTC_ASSERT(!m_globalCodeStyle, return);
|
||||
|
||||
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
|
||||
TextEditorSettings *textEditorSettings = TextEditorSettings::instance();
|
||||
|
||||
// code style factory
|
||||
TextEditor::ICodeStylePreferencesFactory *factory = new QmlJSTools::QmlJSCodeStylePreferencesFactory();
|
||||
ICodeStylePreferencesFactory *factory = new QmlJSCodeStylePreferencesFactory();
|
||||
textEditorSettings->registerCodeStyleFactory(factory);
|
||||
|
||||
// code style pool
|
||||
TextEditor::CodeStylePool *pool = new TextEditor::CodeStylePool(factory, this);
|
||||
CodeStylePool *pool = new CodeStylePool(factory, this);
|
||||
textEditorSettings->registerCodeStylePool(Constants::QML_JS_SETTINGS_ID, pool);
|
||||
|
||||
// global code style settings
|
||||
d->m_globalCodeStyle = new TextEditor::SimpleCodeStylePreferences(this);
|
||||
d->m_globalCodeStyle->setDelegatingPool(pool);
|
||||
d->m_globalCodeStyle->setDisplayName(tr("Global", "Settings"));
|
||||
d->m_globalCodeStyle->setId(idKey);
|
||||
pool->addCodeStyle(d->m_globalCodeStyle);
|
||||
textEditorSettings->registerCodeStyle(QmlJSTools::Constants::QML_JS_SETTINGS_ID, d->m_globalCodeStyle);
|
||||
m_globalCodeStyle = new SimpleCodeStylePreferences(this);
|
||||
m_globalCodeStyle->setDelegatingPool(pool);
|
||||
m_globalCodeStyle->setDisplayName(tr("Global", "Settings"));
|
||||
m_globalCodeStyle->setId(idKey);
|
||||
pool->addCodeStyle(m_globalCodeStyle);
|
||||
textEditorSettings->registerCodeStyle(QmlJSTools::Constants::QML_JS_SETTINGS_ID, m_globalCodeStyle);
|
||||
|
||||
// built-in settings
|
||||
// Qt style
|
||||
TextEditor::SimpleCodeStylePreferences *qtCodeStyle = new TextEditor::SimpleCodeStylePreferences();
|
||||
SimpleCodeStylePreferences *qtCodeStyle = new SimpleCodeStylePreferences();
|
||||
qtCodeStyle->setId(QLatin1String("qt"));
|
||||
qtCodeStyle->setDisplayName(tr("Qt"));
|
||||
qtCodeStyle->setReadOnly(true);
|
||||
@@ -102,13 +89,13 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
|
||||
pool->addCodeStyle(qtCodeStyle);
|
||||
|
||||
// default delegate for global preferences
|
||||
d->m_globalCodeStyle->setCurrentDelegate(qtCodeStyle);
|
||||
m_globalCodeStyle->setCurrentDelegate(qtCodeStyle);
|
||||
|
||||
pool->loadCustomCodeStyles();
|
||||
|
||||
// load global settings (after built-in settings are added to the pool)
|
||||
QSettings *s = Core::ICore::settings();
|
||||
d->m_globalCodeStyle->fromSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
|
||||
m_globalCodeStyle->fromSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
|
||||
|
||||
// legacy handling start (Qt Creator Version < 2.4)
|
||||
const bool legacyTransformed =
|
||||
@@ -137,13 +124,13 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
|
||||
}
|
||||
|
||||
// create custom code style out of old settings
|
||||
TextEditor::ICodeStylePreferences *oldCreator = pool->createCodeStyle(
|
||||
ICodeStylePreferences *oldCreator = pool->createCodeStyle(
|
||||
QLatin1String("legacy"), legacyTabSettings,
|
||||
QVariant(), tr("Old Creator"));
|
||||
|
||||
// change the current delegate and save
|
||||
d->m_globalCodeStyle->setCurrentDelegate(oldCreator);
|
||||
d->m_globalCodeStyle->toSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
|
||||
m_globalCodeStyle->setCurrentDelegate(oldCreator);
|
||||
m_globalCodeStyle->toSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
|
||||
}
|
||||
// mark old settings as transformed
|
||||
s->setValue(QLatin1String("QmlJSTabPreferences/LegacyTransformed"), true);
|
||||
@@ -164,19 +151,13 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
|
||||
|
||||
QmlJSToolsSettings::~QmlJSToolsSettings()
|
||||
{
|
||||
delete d;
|
||||
|
||||
m_instance = 0;
|
||||
delete m_globalCodeStyle;
|
||||
m_globalCodeStyle = 0;
|
||||
}
|
||||
|
||||
QmlJSToolsSettings *QmlJSToolsSettings::instance()
|
||||
SimpleCodeStylePreferences *QmlJSToolsSettings::globalCodeStyle()
|
||||
{
|
||||
return m_instance;
|
||||
return m_globalCodeStyle;
|
||||
}
|
||||
|
||||
TextEditor::SimpleCodeStylePreferences *QmlJSToolsSettings::qmlJSCodeStyle() const
|
||||
{
|
||||
return d->m_globalCodeStyle;
|
||||
}
|
||||
|
||||
|
||||
} // namespace QmlJSTools
|
||||
|
||||
Reference in New Issue
Block a user