Commit 1362f0d2 authored by hjk's avatar hjk
Browse files

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: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@digia.com>
parent 31682a0c
......@@ -177,7 +177,7 @@ QmlJSCodeStyleSettingsPage::QmlJSCodeStyleSettingsPage(/*QSharedPointer<CppFileS
QWidget *QmlJSCodeStyleSettingsPage::createPage(QWidget *parent)
{
TextEditor::SimpleCodeStylePreferences *originalTabPreferences
= QmlJSToolsSettings::instance()->qmlJSCodeStyle();
= QmlJSToolsSettings::globalCodeStyle();
m_pageTabPreferences = new TextEditor::SimpleCodeStylePreferences(m_widget);
m_pageTabPreferences->setDelegatingPool(originalTabPreferences->delegatingPool());
m_pageTabPreferences->setTabSettings(originalTabPreferences->tabSettings());
......@@ -195,7 +195,7 @@ void QmlJSCodeStyleSettingsPage::apply()
if (m_widget) {
QSettings *s = Core::ICore::settings();
TextEditor::SimpleCodeStylePreferences *originalTabPreferences = QmlJSToolsSettings::instance()->qmlJSCodeStyle();
TextEditor::SimpleCodeStylePreferences *originalTabPreferences = QmlJSToolsSettings::globalCodeStyle();
if (originalTabPreferences->tabSettings() != m_pageTabPreferences->tabSettings()) {
originalTabPreferences->setTabSettings(m_pageTabPreferences->tabSettings());
if (s)
......
......@@ -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;
}
QmlJSToolsSettings *QmlJSToolsSettings::instance()
{
return m_instance;
delete m_globalCodeStyle;
m_globalCodeStyle = 0;
}
TextEditor::SimpleCodeStylePreferences *QmlJSToolsSettings::qmlJSCodeStyle() const
SimpleCodeStylePreferences *QmlJSToolsSettings::globalCodeStyle()
{
return d->m_globalCodeStyle;
return m_globalCodeStyle;
}
} // namespace QmlJSTools
......@@ -35,18 +35,9 @@
#include <QObject>
namespace TextEditor
{
class SimpleCodeStylePreferences;
}
namespace QmlJSTools
{
namespace TextEditor { class SimpleCodeStylePreferences; }
namespace Internal
{
class QmlJSToolsSettingsPrivate;
}
namespace QmlJSTools {
/**
* This class provides a central place for cpp tools settings.
......@@ -59,14 +50,7 @@ public:
explicit QmlJSToolsSettings(QObject *parent);
~QmlJSToolsSettings();
static QmlJSToolsSettings *instance();
TextEditor::SimpleCodeStylePreferences *qmlJSCodeStyle() const;
private:
Internal::QmlJSToolsSettingsPrivate *d;
static QmlJSToolsSettings *m_instance;
static TextEditor::SimpleCodeStylePreferences *globalCodeStyle();
};
} // namespace QmlJSTools
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment