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:
hjk
2012-09-24 12:06:49 +02:00
parent 31682a0c13
commit 1362f0d27b
3 changed files with 29 additions and 64 deletions

View File

@@ -177,7 +177,7 @@ QmlJSCodeStyleSettingsPage::QmlJSCodeStyleSettingsPage(/*QSharedPointer<CppFileS
QWidget *QmlJSCodeStyleSettingsPage::createPage(QWidget *parent) QWidget *QmlJSCodeStyleSettingsPage::createPage(QWidget *parent)
{ {
TextEditor::SimpleCodeStylePreferences *originalTabPreferences TextEditor::SimpleCodeStylePreferences *originalTabPreferences
= QmlJSToolsSettings::instance()->qmlJSCodeStyle(); = QmlJSToolsSettings::globalCodeStyle();
m_pageTabPreferences = new TextEditor::SimpleCodeStylePreferences(m_widget); m_pageTabPreferences = new TextEditor::SimpleCodeStylePreferences(m_widget);
m_pageTabPreferences->setDelegatingPool(originalTabPreferences->delegatingPool()); m_pageTabPreferences->setDelegatingPool(originalTabPreferences->delegatingPool());
m_pageTabPreferences->setTabSettings(originalTabPreferences->tabSettings()); m_pageTabPreferences->setTabSettings(originalTabPreferences->tabSettings());
@@ -195,7 +195,7 @@ void QmlJSCodeStyleSettingsPage::apply()
if (m_widget) { if (m_widget) {
QSettings *s = Core::ICore::settings(); QSettings *s = Core::ICore::settings();
TextEditor::SimpleCodeStylePreferences *originalTabPreferences = QmlJSToolsSettings::instance()->qmlJSCodeStyle(); TextEditor::SimpleCodeStylePreferences *originalTabPreferences = QmlJSToolsSettings::globalCodeStyle();
if (originalTabPreferences->tabSettings() != m_pageTabPreferences->tabSettings()) { if (originalTabPreferences->tabSettings() != m_pageTabPreferences->tabSettings()) {
originalTabPreferences->setTabSettings(m_pageTabPreferences->tabSettings()); originalTabPreferences->setTabSettings(m_pageTabPreferences->tabSettings());
if (s) if (s)

View File

@@ -43,53 +43,40 @@
#include <QSettings> #include <QSettings>
static const char *idKey = "QmlJSGlobal"; using namespace TextEditor;
using namespace QmlJSTools;
using TextEditor::TabSettings;
namespace QmlJSTools { namespace QmlJSTools {
namespace Internal {
class QmlJSToolsSettingsPrivate const char idKey[] = "QmlJSGlobal";
{
public:
TextEditor::SimpleCodeStylePreferences *m_globalCodeStyle;
};
} // namespace Internal static TextEditor::SimpleCodeStylePreferences *m_globalCodeStyle = 0;
} // namespace QmlJSTools
QmlJSToolsSettings *QmlJSToolsSettings::m_instance = 0;
QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent) QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
: QObject(parent) : QObject(parent)
, d(new Internal::QmlJSToolsSettingsPrivate)
{ {
QTC_ASSERT(!m_instance, return); QTC_ASSERT(!m_globalCodeStyle, return);
m_instance = this;
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance(); TextEditorSettings *textEditorSettings = TextEditorSettings::instance();
// code style factory // code style factory
TextEditor::ICodeStylePreferencesFactory *factory = new QmlJSTools::QmlJSCodeStylePreferencesFactory(); ICodeStylePreferencesFactory *factory = new QmlJSCodeStylePreferencesFactory();
textEditorSettings->registerCodeStyleFactory(factory); textEditorSettings->registerCodeStyleFactory(factory);
// code style pool // 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); textEditorSettings->registerCodeStylePool(Constants::QML_JS_SETTINGS_ID, pool);
// global code style settings // global code style settings
d->m_globalCodeStyle = new TextEditor::SimpleCodeStylePreferences(this); m_globalCodeStyle = new SimpleCodeStylePreferences(this);
d->m_globalCodeStyle->setDelegatingPool(pool); m_globalCodeStyle->setDelegatingPool(pool);
d->m_globalCodeStyle->setDisplayName(tr("Global", "Settings")); m_globalCodeStyle->setDisplayName(tr("Global", "Settings"));
d->m_globalCodeStyle->setId(idKey); m_globalCodeStyle->setId(idKey);
pool->addCodeStyle(d->m_globalCodeStyle); pool->addCodeStyle(m_globalCodeStyle);
textEditorSettings->registerCodeStyle(QmlJSTools::Constants::QML_JS_SETTINGS_ID, d->m_globalCodeStyle); textEditorSettings->registerCodeStyle(QmlJSTools::Constants::QML_JS_SETTINGS_ID, m_globalCodeStyle);
// built-in settings // built-in settings
// Qt style // Qt style
TextEditor::SimpleCodeStylePreferences *qtCodeStyle = new TextEditor::SimpleCodeStylePreferences(); SimpleCodeStylePreferences *qtCodeStyle = new SimpleCodeStylePreferences();
qtCodeStyle->setId(QLatin1String("qt")); qtCodeStyle->setId(QLatin1String("qt"));
qtCodeStyle->setDisplayName(tr("Qt")); qtCodeStyle->setDisplayName(tr("Qt"));
qtCodeStyle->setReadOnly(true); qtCodeStyle->setReadOnly(true);
@@ -102,13 +89,13 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
pool->addCodeStyle(qtCodeStyle); pool->addCodeStyle(qtCodeStyle);
// default delegate for global preferences // default delegate for global preferences
d->m_globalCodeStyle->setCurrentDelegate(qtCodeStyle); m_globalCodeStyle->setCurrentDelegate(qtCodeStyle);
pool->loadCustomCodeStyles(); pool->loadCustomCodeStyles();
// load global settings (after built-in settings are added to the pool) // load global settings (after built-in settings are added to the pool)
QSettings *s = Core::ICore::settings(); 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) // legacy handling start (Qt Creator Version < 2.4)
const bool legacyTransformed = const bool legacyTransformed =
@@ -137,13 +124,13 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
} }
// create custom code style out of old settings // create custom code style out of old settings
TextEditor::ICodeStylePreferences *oldCreator = pool->createCodeStyle( ICodeStylePreferences *oldCreator = pool->createCodeStyle(
QLatin1String("legacy"), legacyTabSettings, QLatin1String("legacy"), legacyTabSettings,
QVariant(), tr("Old Creator")); QVariant(), tr("Old Creator"));
// change the current delegate and save // change the current delegate and save
d->m_globalCodeStyle->setCurrentDelegate(oldCreator); m_globalCodeStyle->setCurrentDelegate(oldCreator);
d->m_globalCodeStyle->toSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s); m_globalCodeStyle->toSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
} }
// mark old settings as transformed // mark old settings as transformed
s->setValue(QLatin1String("QmlJSTabPreferences/LegacyTransformed"), true); s->setValue(QLatin1String("QmlJSTabPreferences/LegacyTransformed"), true);
@@ -164,19 +151,13 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
QmlJSToolsSettings::~QmlJSToolsSettings() QmlJSToolsSettings::~QmlJSToolsSettings()
{ {
delete d; delete m_globalCodeStyle;
m_globalCodeStyle = 0;
m_instance = 0;
} }
QmlJSToolsSettings *QmlJSToolsSettings::instance() SimpleCodeStylePreferences *QmlJSToolsSettings::globalCodeStyle()
{ {
return m_instance; return m_globalCodeStyle;
} }
TextEditor::SimpleCodeStylePreferences *QmlJSToolsSettings::qmlJSCodeStyle() const } // namespace QmlJSTools
{
return d->m_globalCodeStyle;
}

View File

@@ -35,18 +35,9 @@
#include <QObject> #include <QObject>
namespace TextEditor namespace TextEditor { class SimpleCodeStylePreferences; }
{
class SimpleCodeStylePreferences;
}
namespace QmlJSTools namespace QmlJSTools {
{
namespace Internal
{
class QmlJSToolsSettingsPrivate;
}
/** /**
* This class provides a central place for cpp tools settings. * This class provides a central place for cpp tools settings.
@@ -59,14 +50,7 @@ public:
explicit QmlJSToolsSettings(QObject *parent); explicit QmlJSToolsSettings(QObject *parent);
~QmlJSToolsSettings(); ~QmlJSToolsSettings();
static QmlJSToolsSettings *instance(); static TextEditor::SimpleCodeStylePreferences *globalCodeStyle();
TextEditor::SimpleCodeStylePreferences *qmlJSCodeStyle() const;
private:
Internal::QmlJSToolsSettingsPrivate *d;
static QmlJSToolsSettings *m_instance;
}; };
} // namespace QmlJSTools } // namespace QmlJSTools