forked from qt-creator/qt-creator
QmlJSTools: Use IOptionPage::setWidgetCreator() for settings
Change-Id: I57442416da54acd49cfcfd172fc67f28fee4f7b8 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "qmljscodestylepreferences.h"
|
#include "qmljscodestylepreferences.h"
|
||||||
#include "qmljscodestylepreferenceswidget.h"
|
#include "qmljscodestylepreferenceswidget.h"
|
||||||
#include "qmljsindenter.h"
|
|
||||||
#include "qmljsqtstylecodeformatter.h"
|
#include "qmljsqtstylecodeformatter.h"
|
||||||
#include "qmljstoolsconstants.h"
|
#include "qmljstoolsconstants.h"
|
||||||
#include "qmljstoolssettings.h"
|
#include "qmljstoolssettings.h"
|
||||||
@@ -25,13 +24,13 @@
|
|||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace QmlJSTools {
|
namespace QmlJSTools::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
// ------------------ CppCodeStyleSettingsWidget
|
// QmlJSCodeStylePreferencesWidget
|
||||||
|
|
||||||
QmlJSCodeStylePreferencesWidget::QmlJSCodeStylePreferencesWidget(
|
QmlJSCodeStylePreferencesWidget::QmlJSCodeStylePreferencesWidget(
|
||||||
const TextEditor::ICodeStylePreferencesFactory *factory, QWidget *parent)
|
const TextEditor::ICodeStylePreferencesFactory *factory, QWidget *parent)
|
||||||
@@ -120,7 +119,51 @@ void QmlJSCodeStylePreferencesWidget::updatePreview()
|
|||||||
tc.endEditBlock();
|
tc.endEditBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------ CppCodeStyleSettingsPage
|
// QmlJSCodeStyleSettingsPageWidget
|
||||||
|
|
||||||
|
class QmlJSCodeStyleSettingsPageWidget : public Core::IOptionsPageWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QmlJSCodeStyleSettingsPageWidget()
|
||||||
|
{
|
||||||
|
|
||||||
|
QmlJSCodeStylePreferences *originalPreferences
|
||||||
|
= QmlJSToolsSettings::globalCodeStyle();
|
||||||
|
m_preferences.setDelegatingPool(originalPreferences->delegatingPool());
|
||||||
|
m_preferences.setCodeStyleSettings(originalPreferences->codeStyleSettings());
|
||||||
|
m_preferences.setTabSettings(originalPreferences->tabSettings());
|
||||||
|
m_preferences.setCurrentDelegate(originalPreferences->currentDelegate());
|
||||||
|
m_preferences.setId(originalPreferences->id());
|
||||||
|
|
||||||
|
auto vbox = new QVBoxLayout(this);
|
||||||
|
vbox->addWidget(new CodeStyleEditor(
|
||||||
|
TextEditorSettings::codeStyleFactory(QmlJSTools::Constants::QML_JS_SETTINGS_ID),
|
||||||
|
&m_preferences));
|
||||||
|
}
|
||||||
|
|
||||||
|
void apply() final
|
||||||
|
{
|
||||||
|
QSettings *s = Core::ICore::settings();
|
||||||
|
|
||||||
|
QmlJSCodeStylePreferences *originalPreferences = QmlJSToolsSettings::globalCodeStyle();
|
||||||
|
if (originalPreferences->codeStyleSettings() != m_preferences.codeStyleSettings()) {
|
||||||
|
originalPreferences->setCodeStyleSettings(m_preferences.codeStyleSettings());
|
||||||
|
originalPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
|
||||||
|
}
|
||||||
|
if (originalPreferences->tabSettings() != m_preferences.tabSettings()) {
|
||||||
|
originalPreferences->setTabSettings(m_preferences.tabSettings());
|
||||||
|
originalPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
|
||||||
|
}
|
||||||
|
if (originalPreferences->currentDelegate() != m_preferences.currentDelegate()) {
|
||||||
|
originalPreferences->setCurrentDelegate(m_preferences.currentDelegate());
|
||||||
|
originalPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QmlJSCodeStylePreferences m_preferences;
|
||||||
|
};
|
||||||
|
|
||||||
|
// QmlJSCodeStyleSettingsPage
|
||||||
|
|
||||||
QmlJSCodeStyleSettingsPage::QmlJSCodeStyleSettingsPage()
|
QmlJSCodeStyleSettingsPage::QmlJSCodeStyleSettingsPage()
|
||||||
{
|
{
|
||||||
@@ -129,50 +172,7 @@ QmlJSCodeStyleSettingsPage::QmlJSCodeStyleSettingsPage()
|
|||||||
setCategory(QmlJSEditor::Constants::SETTINGS_CATEGORY_QML);
|
setCategory(QmlJSEditor::Constants::SETTINGS_CATEGORY_QML);
|
||||||
setDisplayCategory(Tr::tr("Qt Quick"));
|
setDisplayCategory(Tr::tr("Qt Quick"));
|
||||||
setCategoryIconPath(":/qmljstools/images/settingscategory_qml.png");
|
setCategoryIconPath(":/qmljstools/images/settingscategory_qml.png");
|
||||||
|
setWidgetCreator([] { return new QmlJSCodeStyleSettingsPageWidget; });
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *QmlJSCodeStyleSettingsPage::widget()
|
} // QmlJSTools::Internal
|
||||||
{
|
|
||||||
if (!m_widget) {
|
|
||||||
QmlJSCodeStylePreferences *originalPreferences
|
|
||||||
= QmlJSToolsSettings::globalCodeStyle();
|
|
||||||
m_preferences = new QmlJSCodeStylePreferences(m_widget);
|
|
||||||
m_preferences->setDelegatingPool(originalPreferences->delegatingPool());
|
|
||||||
m_preferences->setCodeStyleSettings(originalPreferences->codeStyleSettings());
|
|
||||||
m_preferences->setTabSettings(originalPreferences->tabSettings());
|
|
||||||
m_preferences->setCurrentDelegate(originalPreferences->currentDelegate());
|
|
||||||
m_preferences->setId(originalPreferences->id());
|
|
||||||
m_widget = new CodeStyleEditor(TextEditorSettings::codeStyleFactory(QmlJSTools::Constants::QML_JS_SETTINGS_ID),
|
|
||||||
m_preferences);
|
|
||||||
}
|
|
||||||
return m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlJSCodeStyleSettingsPage::apply()
|
|
||||||
{
|
|
||||||
if (m_widget) {
|
|
||||||
QSettings *s = Core::ICore::settings();
|
|
||||||
|
|
||||||
QmlJSCodeStylePreferences *originalPreferences = QmlJSToolsSettings::globalCodeStyle();
|
|
||||||
if (originalPreferences->codeStyleSettings() != m_preferences->codeStyleSettings()) {
|
|
||||||
originalPreferences->setCodeStyleSettings(m_preferences->codeStyleSettings());
|
|
||||||
originalPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
|
|
||||||
}
|
|
||||||
if (originalPreferences->tabSettings() != m_preferences->tabSettings()) {
|
|
||||||
originalPreferences->setTabSettings(m_preferences->tabSettings());
|
|
||||||
originalPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
|
|
||||||
}
|
|
||||||
if (originalPreferences->currentDelegate() != m_preferences->currentDelegate()) {
|
|
||||||
originalPreferences->setCurrentDelegate(m_preferences->currentDelegate());
|
|
||||||
originalPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlJSCodeStyleSettingsPage::finish()
|
|
||||||
{
|
|
||||||
delete m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace QmlJSTools
|
|
||||||
|
|||||||
@@ -6,16 +6,8 @@
|
|||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
#include <texteditor/icodestylepreferencesfactory.h>
|
#include <texteditor/icodestylepreferencesfactory.h>
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QSettings;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
class FontSettings;
|
class FontSettings;
|
||||||
class CodeStyleEditor;
|
|
||||||
class SimpleCodeStylePreferencesWidget;
|
class SimpleCodeStylePreferencesWidget;
|
||||||
class SnippetEditorWidget;
|
class SnippetEditorWidget;
|
||||||
}
|
}
|
||||||
@@ -54,14 +46,6 @@ class QmlJSCodeStyleSettingsPage : public Core::IOptionsPage
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QmlJSCodeStyleSettingsPage();
|
QmlJSCodeStyleSettingsPage();
|
||||||
|
|
||||||
QWidget *widget() override;
|
|
||||||
void apply() override;
|
|
||||||
void finish() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QmlJSCodeStylePreferences *m_preferences = nullptr;
|
|
||||||
QPointer<TextEditor::CodeStyleEditor> m_widget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user