summaryrefslogtreecommitdiff
path: root/src/plugins/qmljstools
diff options
context:
space:
mode:
authorXavier BESSON <developer@xavi-b.fr>2022-04-02 12:15:26 +0200
committerXavier BESSON <developer@xavi-b.fr>2022-04-07 11:42:37 +0000
commit87e52ad18929110a756bd018793003ad717d3704 (patch)
treeb82e6d4473761c2691095a4a7834fe3c0a550742 /src/plugins/qmljstools
parent4762d54401658e28be7fa04491d5ed6a5491e129 (diff)
downloadqt-creator-87e52ad18929110a756bd018793003ad717d3704.tar.gz
Line length for QML/JS editing automatic formatting
Adding parameters to functions in the QML/JS formatter Adding widget and setting to the QML/JS editing settings Fixes: QTCREATORBUG-23411 Change-Id: Ib9d3ac3b22443e81cd636fbc276c6544dab1511b Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
Diffstat (limited to 'src/plugins/qmljstools')
-rw-r--r--src/plugins/qmljstools/CMakeLists.txt4
-rw-r--r--src/plugins/qmljstools/qmljscodestylepreferences.cpp110
-rw-r--r--src/plugins/qmljstools/qmljscodestylepreferences.h65
-rw-r--r--src/plugins/qmljstools/qmljscodestylepreferencesfactory.cpp9
-rw-r--r--src/plugins/qmljstools/qmljscodestylepreferenceswidget.cpp94
-rw-r--r--src/plugins/qmljstools/qmljscodestylepreferenceswidget.h60
-rw-r--r--src/plugins/qmljstools/qmljscodestylesettings.cpp83
-rw-r--r--src/plugins/qmljstools/qmljscodestylesettings.h58
-rw-r--r--src/plugins/qmljstools/qmljscodestylesettingspage.cpp42
-rw-r--r--src/plugins/qmljstools/qmljscodestylesettingspage.h11
-rw-r--r--src/plugins/qmljstools/qmljscodestylesettingspage.ui33
-rw-r--r--src/plugins/qmljstools/qmljscodestylesettingswidget.cpp70
-rw-r--r--src/plugins/qmljstools/qmljscodestylesettingswidget.h66
-rw-r--r--src/plugins/qmljstools/qmljscodestylesettingswidget.ui76
-rw-r--r--src/plugins/qmljstools/qmljstoolssettings.cpp13
-rw-r--r--src/plugins/qmljstools/qmljstoolssettings.h5
16 files changed, 755 insertions, 44 deletions
diff --git a/src/plugins/qmljstools/CMakeLists.txt b/src/plugins/qmljstools/CMakeLists.txt
index 329f5dbce0..f0c3d6792d 100644
--- a/src/plugins/qmljstools/CMakeLists.txt
+++ b/src/plugins/qmljstools/CMakeLists.txt
@@ -5,6 +5,10 @@ add_qtc_plugin(QmlJSTools
SOURCES
qmljsbundleprovider.cpp qmljsbundleprovider.h
qmljscodestylepreferencesfactory.cpp qmljscodestylepreferencesfactory.h
+ qmljscodestylepreferences.cpp qmljscodestylepreferences.h
+ qmljscodestylepreferenceswidget.cpp qmljscodestylepreferenceswidget.h
+ qmljscodestylesettings.cpp qmljscodestylesettings.h
+ qmljscodestylesettingswidget.cpp qmljscodestylesettingswidget.h qmljscodestylesettingswidget.ui
qmljscodestylesettingspage.cpp qmljscodestylesettingspage.h qmljscodestylesettingspage.ui
qmljsfunctionfilter.cpp qmljsfunctionfilter.h
qmljsindenter.cpp qmljsindenter.h
diff --git a/src/plugins/qmljstools/qmljscodestylepreferences.cpp b/src/plugins/qmljstools/qmljscodestylepreferences.cpp
new file mode 100644
index 0000000000..191b8139f1
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylepreferences.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "qmljscodestylepreferences.h"
+
+namespace QmlJSTools {
+
+QmlJSCodeStylePreferences::QmlJSCodeStylePreferences(QObject *parent) :
+ ICodeStylePreferences(parent)
+{
+ setSettingsSuffix("CodeStyleSettings");
+
+ connect(this, &QmlJSCodeStylePreferences::currentValueChanged,
+ this, &QmlJSCodeStylePreferences::slotCurrentValueChanged);
+}
+
+QVariant QmlJSCodeStylePreferences::value() const
+{
+ QVariant v;
+ v.setValue(codeStyleSettings());
+ return v;
+}
+
+void QmlJSCodeStylePreferences::setValue(const QVariant &data)
+{
+ if (!data.canConvert<QmlJSCodeStyleSettings>())
+ return;
+
+ setCodeStyleSettings(data.value<QmlJSCodeStyleSettings>());
+}
+
+QmlJSCodeStyleSettings QmlJSCodeStylePreferences::codeStyleSettings() const
+{
+ return m_data;
+}
+
+void QmlJSCodeStylePreferences::setCodeStyleSettings(const QmlJSCodeStyleSettings &data)
+{
+ if (m_data == data)
+ return;
+
+ m_data = data;
+
+ QVariant v;
+ v.setValue(data);
+ emit valueChanged(v);
+ emit codeStyleSettingsChanged(m_data);
+ if (!currentDelegate())
+ emit currentValueChanged(v);
+}
+
+QmlJSCodeStyleSettings QmlJSCodeStylePreferences::currentCodeStyleSettings() const
+{
+ QVariant v = currentValue();
+ if (!v.canConvert<QmlJSCodeStyleSettings>()) {
+ // warning
+ return {};
+ }
+ return v.value<QmlJSCodeStyleSettings>();
+}
+
+void QmlJSCodeStylePreferences::slotCurrentValueChanged(const QVariant &value)
+{
+ if (!value.canConvert<QmlJSCodeStyleSettings>())
+ return;
+
+ emit currentCodeStyleSettingsChanged(value.value<QmlJSCodeStyleSettings>());
+}
+
+QVariantMap QmlJSCodeStylePreferences::toMap() const
+{
+ QVariantMap map = ICodeStylePreferences::toMap();
+ if (!currentDelegate()) {
+ const QVariantMap dataMap = m_data.toMap();
+ for (auto it = dataMap.begin(), end = dataMap.end(); it != end; ++it)
+ map.insert(it.key(), it.value());
+ }
+ return map;
+}
+
+void QmlJSCodeStylePreferences::fromMap(const QVariantMap &map)
+{
+ ICodeStylePreferences::fromMap(map);
+ if (!currentDelegate())
+ m_data.fromMap(map);
+}
+
+} // namespace QmlJSTools
diff --git a/src/plugins/qmljstools/qmljscodestylepreferences.h b/src/plugins/qmljstools/qmljscodestylepreferences.h
new file mode 100644
index 0000000000..2c3d2e5d51
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylepreferences.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "qmljstools_global.h"
+#include "qmljscodestylesettings.h"
+
+#include <texteditor/icodestylepreferences.h>
+
+namespace QmlJSTools {
+
+class QMLJSTOOLS_EXPORT QmlJSCodeStylePreferences : public TextEditor::ICodeStylePreferences
+{
+ Q_OBJECT
+public:
+ explicit QmlJSCodeStylePreferences(QObject *parent = nullptr);
+
+ QVariant value() const override;
+ void setValue(const QVariant &) override;
+
+ QmlJSCodeStyleSettings codeStyleSettings() const;
+
+ // tracks parent hierarchy until currentParentSettings is null
+ QmlJSCodeStyleSettings currentCodeStyleSettings() const;
+
+ QVariantMap toMap() const override;
+ void fromMap(const QVariantMap &map) override;
+
+public slots:
+ void setCodeStyleSettings(const QmlJSCodeStyleSettings &data);
+
+signals:
+ void codeStyleSettingsChanged(const QmlJSCodeStyleSettings &);
+ void currentCodeStyleSettingsChanged(const QmlJSCodeStyleSettings &);
+
+private:
+ void slotCurrentValueChanged(const QVariant &);
+
+ QmlJSCodeStyleSettings m_data;
+};
+
+} // namespace QmlJSTools
diff --git a/src/plugins/qmljstools/qmljscodestylepreferencesfactory.cpp b/src/plugins/qmljstools/qmljscodestylepreferencesfactory.cpp
index 72eda62e36..f054a37bd4 100644
--- a/src/plugins/qmljstools/qmljscodestylepreferencesfactory.cpp
+++ b/src/plugins/qmljstools/qmljscodestylepreferencesfactory.cpp
@@ -28,7 +28,7 @@
#include "qmljstoolsconstants.h"
#include "qmljsindenter.h"
-#include <texteditor/simplecodestylepreferences.h>
+#include <qmljscodestylepreferences.h>
#include <qmljseditor/qmljseditorconstants.h>
@@ -68,16 +68,19 @@ QString QmlJSCodeStylePreferencesFactory::displayName()
TextEditor::ICodeStylePreferences *QmlJSCodeStylePreferencesFactory::createCodeStyle() const
{
- return new TextEditor::SimpleCodeStylePreferences();
+ return new QmlJSCodeStylePreferences();
}
TextEditor::CodeStyleEditorWidget *QmlJSCodeStylePreferencesFactory::createEditor(
TextEditor::ICodeStylePreferences *preferences,
QWidget *parent) const
{
+ auto qmlJSPreferences = qobject_cast<QmlJSCodeStylePreferences *>(preferences);
+ if (!qmlJSPreferences)
+ return nullptr;
auto widget = new Internal::QmlJSCodeStylePreferencesWidget(parent);
widget->layout()->setContentsMargins(0, 0, 0, 0);
- widget->setPreferences(preferences);
+ widget->setPreferences(qmlJSPreferences);
return widget;
}
diff --git a/src/plugins/qmljstools/qmljscodestylepreferenceswidget.cpp b/src/plugins/qmljstools/qmljscodestylepreferenceswidget.cpp
new file mode 100644
index 0000000000..656cdba06d
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylepreferenceswidget.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "qmljscodestylepreferenceswidget.h"
+#include "qmljscodestylepreferences.h"
+#include "qmljscodestylesettingswidget.h"
+#include "qmljscodestylesettings.h"
+
+#include <QVBoxLayout>
+#include <QLabel>
+
+namespace QmlJSTools {
+
+QmlJSCodeStylePreferencesWidget::QmlJSCodeStylePreferencesWidget(QWidget *parent) :
+ QWidget(parent)
+{
+ m_codeStyleSettingsWidget = new QmlJSCodeStyleSettingsWidget(this);
+ auto layout = new QVBoxLayout(this);
+ layout->addWidget(m_codeStyleSettingsWidget);
+ layout->setContentsMargins(QMargins());
+ m_codeStyleSettingsWidget->setEnabled(false);
+}
+
+void QmlJSCodeStylePreferencesWidget::setPreferences(QmlJSCodeStylePreferences *preferences)
+{
+ if (m_preferences == preferences)
+ return; // nothing changes
+
+ // cleanup old
+ if (m_preferences) {
+ disconnect(m_preferences, &QmlJSCodeStylePreferences::currentCodeStyleSettingsChanged,
+ m_codeStyleSettingsWidget, &QmlJSCodeStyleSettingsWidget::setCodeStyleSettings);
+ disconnect(m_preferences, &QmlJSCodeStylePreferences::currentPreferencesChanged,
+ this, &QmlJSCodeStylePreferencesWidget::slotCurrentPreferencesChanged);
+ disconnect(m_codeStyleSettingsWidget, &QmlJSCodeStyleSettingsWidget::settingsChanged,
+ this, &QmlJSCodeStylePreferencesWidget::slotSettingsChanged);
+ }
+ m_preferences = preferences;
+ // fillup new
+ if (m_preferences) {
+ slotCurrentPreferencesChanged(m_preferences->currentPreferences());
+
+ m_codeStyleSettingsWidget->setCodeStyleSettings(m_preferences->currentCodeStyleSettings());
+
+ connect(m_preferences, &QmlJSCodeStylePreferences::currentCodeStyleSettingsChanged,
+ m_codeStyleSettingsWidget, &QmlJSCodeStyleSettingsWidget::setCodeStyleSettings);
+ connect(m_preferences, &QmlJSCodeStylePreferences::currentPreferencesChanged,
+ this, &QmlJSCodeStylePreferencesWidget::slotCurrentPreferencesChanged);
+ connect(m_codeStyleSettingsWidget, &QmlJSCodeStyleSettingsWidget::settingsChanged,
+ this, &QmlJSCodeStylePreferencesWidget::slotSettingsChanged);
+ }
+ m_codeStyleSettingsWidget->setEnabled(m_preferences);
+}
+
+void QmlJSCodeStylePreferencesWidget::slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences *preferences)
+{
+ m_codeStyleSettingsWidget->setEnabled(!preferences->isReadOnly() && !m_preferences->currentDelegate());
+}
+
+void QmlJSCodeStylePreferencesWidget::slotSettingsChanged(const QmlJSCodeStyleSettings &settings)
+{
+ if (!m_preferences)
+ return;
+
+ QmlJSCodeStylePreferences *current = qobject_cast<QmlJSCodeStylePreferences*>(m_preferences->currentPreferences());
+ if (!current)
+ return;
+
+ current->setCodeStyleSettings(settings);
+}
+
+} // namespace QmlJSTools
diff --git a/src/plugins/qmljstools/qmljscodestylepreferenceswidget.h b/src/plugins/qmljstools/qmljscodestylepreferenceswidget.h
new file mode 100644
index 0000000000..dd3ae21e80
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylepreferenceswidget.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "qmljstools_global.h"
+
+#include <QWidget>
+
+namespace TextEditor {
+class ICodeStylePreferences;
+}
+
+namespace QmlJSTools {
+class QmlJSCodeStyleSettings;
+class QmlJSCodeStyleSettingsWidget;
+class QmlJSCodeStylePreferences;
+
+namespace Ui { class TabPreferencesWidget; }
+
+class QMLJSTOOLS_EXPORT QmlJSCodeStylePreferencesWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit QmlJSCodeStylePreferencesWidget(QWidget *parent = nullptr);
+
+ void setPreferences(QmlJSCodeStylePreferences *tabPreferences);
+
+private:
+ void slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences* preferences);
+ void slotSettingsChanged(const QmlJSCodeStyleSettings &settings);
+
+ QmlJSCodeStyleSettingsWidget *m_codeStyleSettingsWidget;
+ QmlJSCodeStylePreferences *m_preferences = nullptr;
+};
+
+} // namespace QmlJSTools
diff --git a/src/plugins/qmljstools/qmljscodestylesettings.cpp b/src/plugins/qmljstools/qmljscodestylesettings.cpp
new file mode 100644
index 0000000000..75e09b7b42
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylesettings.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "qmljscodestylesettings.h"
+
+#include "qmljscodestylepreferences.h"
+#include "qmljstoolssettings.h"
+
+#include <projectexplorer/editorconfiguration.h>
+#include <projectexplorer/project.h>
+#include <projectexplorer/projecttree.h>
+
+#include <texteditor/tabsettings.h>
+
+#include <cplusplus/Overview.h>
+
+#include <utils/qtcassert.h>
+#include <utils/settingsutils.h>
+
+static const char lineLengthKey[] = "LineLength";
+
+namespace QmlJSTools {
+
+// ------------------ QmlJSCodeStyleSettingsWidget
+
+QmlJSCodeStyleSettings::QmlJSCodeStyleSettings() = default;
+
+QVariantMap QmlJSCodeStyleSettings::toMap() const
+{
+ return {
+ {lineLengthKey, lineLength}
+ };
+}
+
+void QmlJSCodeStyleSettings::fromMap(const QVariantMap &map)
+{
+ lineLength = map.value(lineLengthKey, lineLength).toInt();
+}
+
+bool QmlJSCodeStyleSettings::equals(const QmlJSCodeStyleSettings &rhs) const
+{
+ return lineLength == rhs.lineLength;
+}
+
+QmlJSCodeStyleSettings QmlJSCodeStyleSettings::currentGlobalCodeStyle()
+{
+ QmlJSCodeStylePreferences *QmlJSCodeStylePreferences = QmlJSToolsSettings::globalCodeStyle();
+ QTC_ASSERT(QmlJSCodeStylePreferences, return QmlJSCodeStyleSettings());
+
+ return QmlJSCodeStylePreferences->currentCodeStyleSettings();
+}
+
+TextEditor::TabSettings QmlJSCodeStyleSettings::currentGlobalTabSettings()
+{
+ QmlJSCodeStylePreferences *QmlJSCodeStylePreferences = QmlJSToolsSettings::globalCodeStyle();
+ QTC_ASSERT(QmlJSCodeStylePreferences, return TextEditor::TabSettings());
+
+ return QmlJSCodeStylePreferences->currentTabSettings();
+}
+
+} // namespace QmlJSTools
diff --git a/src/plugins/qmljstools/qmljscodestylesettings.h b/src/plugins/qmljstools/qmljscodestylesettings.h
new file mode 100644
index 0000000000..35d87519bc
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylesettings.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "qmljstools_global.h"
+
+#include <utils/optional.h>
+
+#include <QVariantMap>
+
+namespace TextEditor { class TabSettings; }
+
+namespace QmlJSTools {
+
+class QMLJSTOOLS_EXPORT QmlJSCodeStyleSettings
+{
+public:
+ QmlJSCodeStyleSettings();
+
+ int lineLength = 80;
+
+ QVariantMap toMap() const;
+ void fromMap(const QVariantMap &map);
+
+ bool equals(const QmlJSCodeStyleSettings &rhs) const;
+ bool operator==(const QmlJSCodeStyleSettings &s) const { return equals(s); }
+ bool operator!=(const QmlJSCodeStyleSettings &s) const { return !equals(s); }
+
+ static QmlJSCodeStyleSettings currentGlobalCodeStyle();
+ static TextEditor::TabSettings currentGlobalTabSettings();
+};
+
+} // namespace CppEditor
+
+Q_DECLARE_METATYPE(QmlJSTools::QmlJSCodeStyleSettings)
diff --git a/src/plugins/qmljstools/qmljscodestylesettingspage.cpp b/src/plugins/qmljstools/qmljscodestylesettingspage.cpp
index a7978b0bc2..a44ecf229d 100644
--- a/src/plugins/qmljstools/qmljscodestylesettingspage.cpp
+++ b/src/plugins/qmljstools/qmljscodestylesettingspage.cpp
@@ -29,11 +29,11 @@
#include "qmljstoolssettings.h"
#include "qmljsindenter.h"
#include "qmljsqtstylecodeformatter.h"
+#include "qmljscodestylepreferences.h"
#include <texteditor/fontsettings.h>
#include <texteditor/snippets/snippetprovider.h>
#include <texteditor/tabsettings.h>
-#include <texteditor/simplecodestylepreferences.h>
#include <texteditor/displaysettings.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/codestyleeditor.h>
@@ -70,13 +70,18 @@ QmlJSCodeStylePreferencesWidget::~QmlJSCodeStylePreferencesWidget()
delete m_ui;
}
-void QmlJSCodeStylePreferencesWidget::setPreferences(ICodeStylePreferences *preferences)
+void QmlJSCodeStylePreferencesWidget::setPreferences(QmlJSCodeStylePreferences *preferences)
{
m_preferences = preferences;
m_ui->tabPreferencesWidget->setPreferences(preferences);
+ m_ui->codeStylePreferencesWidget->setPreferences(preferences);
if (m_preferences)
+ {
connect(m_preferences, &ICodeStylePreferences::currentTabSettingsChanged,
this, &QmlJSCodeStylePreferencesWidget::slotSettingsChanged);
+ connect(m_preferences, &QmlJSCodeStylePreferences::currentCodeStyleSettingsChanged,
+ this, &QmlJSCodeStylePreferencesWidget::slotSettingsChanged);
+ }
updatePreview();
}
@@ -134,15 +139,16 @@ QmlJSCodeStyleSettingsPage::QmlJSCodeStyleSettingsPage()
QWidget *QmlJSCodeStyleSettingsPage::widget()
{
if (!m_widget) {
- SimpleCodeStylePreferences *originalTabPreferences
+ QmlJSCodeStylePreferences *originalPreferences
= QmlJSToolsSettings::globalCodeStyle();
- m_pageTabPreferences = new SimpleCodeStylePreferences(m_widget);
- m_pageTabPreferences->setDelegatingPool(originalTabPreferences->delegatingPool());
- m_pageTabPreferences->setTabSettings(originalTabPreferences->tabSettings());
- m_pageTabPreferences->setCurrentDelegate(originalTabPreferences->currentDelegate());
- m_pageTabPreferences->setId(originalTabPreferences->id());
+ 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_pageTabPreferences);
+ m_preferences);
}
return m_widget;
}
@@ -152,14 +158,18 @@ void QmlJSCodeStyleSettingsPage::apply()
if (m_widget) {
QSettings *s = Core::ICore::settings();
- SimpleCodeStylePreferences *originalTabPreferences = QmlJSToolsSettings::globalCodeStyle();
- if (originalTabPreferences->tabSettings() != m_pageTabPreferences->tabSettings()) {
- originalTabPreferences->setTabSettings(m_pageTabPreferences->tabSettings());
- originalTabPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
+ 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 (originalTabPreferences->currentDelegate() != m_pageTabPreferences->currentDelegate()) {
- originalTabPreferences->setCurrentDelegate(m_pageTabPreferences->currentDelegate());
- originalTabPreferences->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);
}
}
}
diff --git a/src/plugins/qmljstools/qmljscodestylesettingspage.h b/src/plugins/qmljstools/qmljscodestylesettingspage.h
index 2a6f77d2e3..64a8f45173 100644
--- a/src/plugins/qmljstools/qmljscodestylesettingspage.h
+++ b/src/plugins/qmljstools/qmljscodestylesettingspage.h
@@ -37,12 +37,13 @@ QT_END_NAMESPACE
namespace TextEditor {
class FontSettings;
- class TabSettings;
class CodeStyleEditor;
- class ICodeStylePreferences;
}
namespace QmlJSTools {
+class QmlJSCodeStylePreferences;
+class QmlJSCodeStyleSettings;
+
namespace Internal {
namespace Ui { class QmlJSCodeStyleSettingsPage; }
@@ -55,7 +56,7 @@ public:
explicit QmlJSCodeStylePreferencesWidget(QWidget *parent = nullptr);
~QmlJSCodeStylePreferencesWidget() override;
- void setPreferences(TextEditor::ICodeStylePreferences *preferences);
+ void setPreferences(QmlJSCodeStylePreferences* preferences);
private:
void decorateEditor(const TextEditor::FontSettings &fontSettings);
@@ -63,7 +64,7 @@ private:
void slotSettingsChanged();
void updatePreview();
- TextEditor::ICodeStylePreferences *m_preferences = nullptr;
+ QmlJSCodeStylePreferences *m_preferences = nullptr;
Ui::QmlJSCodeStyleSettingsPage *m_ui;
};
@@ -78,7 +79,7 @@ public:
void finish() override;
private:
- TextEditor::ICodeStylePreferences *m_pageTabPreferences = nullptr;
+ QmlJSCodeStylePreferences *m_preferences = nullptr;
QPointer<TextEditor::CodeStyleEditor> m_widget;
};
diff --git a/src/plugins/qmljstools/qmljscodestylesettingspage.ui b/src/plugins/qmljstools/qmljscodestylesettingspage.ui
index beabf9cbe6..90262704ef 100644
--- a/src/plugins/qmljstools/qmljscodestylesettingspage.ui
+++ b/src/plugins/qmljstools/qmljscodestylesettingspage.ui
@@ -24,7 +24,20 @@
</property>
</widget>
</item>
- <item row="0" column="1" rowspan="2">
+ <item row="2" column="0">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>267</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="1" rowspan="3">
<widget class="TextEditor::SnippetEditorWidget" name="previewTextEdit">
<property name="plainText">
<string notr="true">import QtQuick 1.0
@@ -48,17 +61,7 @@ Rectangle {
</widget>
</item>
<item row="1" column="0">
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>267</height>
- </size>
- </property>
- </spacer>
+ <widget class="QmlJSTools::QmlJSCodeStylePreferencesWidget" name="codeStylePreferencesWidget" native="true"/>
</item>
</layout>
</widget>
@@ -74,6 +77,12 @@ Rectangle {
<extends>QPlainTextEdit</extends>
<header location="global">texteditor/snippets/snippeteditor.h</header>
</customwidget>
+ <customwidget>
+ <class>QmlJSTools::QmlJSCodeStylePreferencesWidget</class>
+ <extends>QWidget</extends>
+ <header location="global">qmljscodestylepreferenceswidget.h</header>
+ <container>1</container>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
diff --git a/src/plugins/qmljstools/qmljscodestylesettingswidget.cpp b/src/plugins/qmljstools/qmljscodestylesettingswidget.cpp
new file mode 100644
index 0000000000..1dfbfc324f
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylesettingswidget.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "qmljscodestylesettingswidget.h"
+#include "ui_qmljscodestylesettingswidget.h"
+#include "qmljscodestylesettings.h"
+
+#include <QTextStream>
+
+namespace QmlJSTools {
+
+QmlJSCodeStyleSettingsWidget::QmlJSCodeStyleSettingsWidget(QWidget *parent) :
+ QGroupBox(parent),
+ ui(new Internal::Ui::QmlJSCodeStyleSettingsWidget)
+{
+ ui->setupUi(this);
+
+ auto spinValueChanged = QOverload<int>::of(&QSpinBox::valueChanged);
+ connect(ui->lineLengthSpinBox, spinValueChanged,
+ this, &QmlJSCodeStyleSettingsWidget::slotSettingsChanged);
+}
+
+QmlJSCodeStyleSettingsWidget::~QmlJSCodeStyleSettingsWidget()
+{
+ delete ui;
+}
+
+void QmlJSCodeStyleSettingsWidget::setCodeStyleSettings(const QmlJSCodeStyleSettings& s)
+{
+ QSignalBlocker blocker(this);
+ ui->lineLengthSpinBox->setValue(s.lineLength);
+}
+
+QmlJSCodeStyleSettings QmlJSCodeStyleSettingsWidget::codeStyleSettings() const
+{
+ QmlJSCodeStyleSettings set;
+
+ set.lineLength = ui->lineLengthSpinBox->value();
+
+ return set;
+}
+
+void QmlJSCodeStyleSettingsWidget::slotSettingsChanged()
+{
+ emit settingsChanged(codeStyleSettings());
+}
+
+} // namespace TextEditor
diff --git a/src/plugins/qmljstools/qmljscodestylesettingswidget.h b/src/plugins/qmljstools/qmljscodestylesettingswidget.h
new file mode 100644
index 0000000000..ece704fbf3
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylesettingswidget.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "qmljstools_global.h"
+
+#include <QGroupBox>
+
+namespace QmlJSTools {
+class QmlJSCodeStyleSettings;
+
+namespace Internal { namespace Ui { class QmlJSCodeStyleSettingsWidget; } }
+
+
+class QMLJSTOOLS_EXPORT QmlJSCodeStyleSettingsWidget : public QGroupBox
+{
+ Q_OBJECT
+
+public:
+ enum CodingStyleLink {
+ CppLink,
+ QtQuickLink
+ };
+
+ explicit QmlJSCodeStyleSettingsWidget(QWidget *parent = nullptr);
+ ~QmlJSCodeStyleSettingsWidget() override;
+
+ QmlJSCodeStyleSettings codeStyleSettings() const;
+
+ void setCodingStyleWarningVisible(bool visible);
+ void setCodeStyleSettings(const QmlJSCodeStyleSettings& s);
+
+signals:
+ void settingsChanged(const QmlJSCodeStyleSettings &);
+
+private:
+ void slotSettingsChanged();
+ void codingStyleLinkActivated(const QString &linkString);
+
+ Internal::Ui::QmlJSCodeStyleSettingsWidget *ui;
+};
+
+} // namespace QmlJSTools
diff --git a/src/plugins/qmljstools/qmljscodestylesettingswidget.ui b/src/plugins/qmljstools/qmljscodestylesettingswidget.ui
new file mode 100644
index 0000000000..f7150f12b6
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylesettingswidget.ui
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QmlJSTools::Internal::QmlJSCodeStyleSettingsWidget</class>
+ <widget class="QGroupBox" name="QmlJSTools::Internal::QmlJSCodeStyleSettingsWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>254</width>
+ <height>203</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string notr="true"/>
+ </property>
+ <property name="title">
+ <string>Qml JS Code Style</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" colspan="2">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="lineLengthLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>&amp;Indent size:</string>
+ </property>
+ <property name="buddy">
+ <cstring>lineLengthSpinBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="lineLengthSpinBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimum">
+ <number>0</number>
+ </property>
+ <property name="maximum">
+ <number>999</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>lineLengthSpinBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/plugins/qmljstools/qmljstoolssettings.cpp b/src/plugins/qmljstools/qmljstoolssettings.cpp
index dcfe957027..52717ae9c1 100644
--- a/src/plugins/qmljstools/qmljstoolssettings.cpp
+++ b/src/plugins/qmljstools/qmljstoolssettings.cpp
@@ -25,10 +25,10 @@
#include "qmljstoolssettings.h"
#include "qmljstoolsconstants.h"
+#include "qmljscodestylepreferences.h"
#include "qmljscodestylepreferencesfactory.h"
#include <texteditor/texteditorsettings.h>
-#include <texteditor/simplecodestylepreferences.h>
#include <texteditor/tabsettings.h>
#include <texteditor/codestylepool.h>
@@ -44,7 +44,7 @@ namespace QmlJSTools {
const char idKey[] = "QmlJSGlobal";
-static SimpleCodeStylePreferences *m_globalCodeStyle = nullptr;
+static QmlJSCodeStylePreferences *m_globalCodeStyle = nullptr;
QmlJSToolsSettings::QmlJSToolsSettings()
{
@@ -59,7 +59,7 @@ QmlJSToolsSettings::QmlJSToolsSettings()
TextEditorSettings::registerCodeStylePool(Constants::QML_JS_SETTINGS_ID, pool);
// global code style settings
- m_globalCodeStyle = new SimpleCodeStylePreferences(this);
+ m_globalCodeStyle = new QmlJSCodeStylePreferences(this);
m_globalCodeStyle->setDelegatingPool(pool);
m_globalCodeStyle->setDisplayName(tr("Global", "Settings"));
m_globalCodeStyle->setId(idKey);
@@ -68,7 +68,7 @@ QmlJSToolsSettings::QmlJSToolsSettings()
// built-in settings
// Qt style
- auto qtCodeStyle = new SimpleCodeStylePreferences;
+ auto qtCodeStyle = new QmlJSCodeStylePreferences;
qtCodeStyle->setId("qt");
qtCodeStyle->setDisplayName(tr("Qt"));
qtCodeStyle->setReadOnly(true);
@@ -78,6 +78,9 @@ QmlJSToolsSettings::QmlJSToolsSettings()
qtTabSettings.m_indentSize = 4;
qtTabSettings.m_continuationAlignBehavior = TabSettings::ContinuationAlignWithIndent;
qtCodeStyle->setTabSettings(qtTabSettings);
+ QmlJSCodeStyleSettings qtQmlJSSetings;
+ qtQmlJSSetings.lineLength = 80;
+ qtCodeStyle->setCodeStyleSettings(qtQmlJSSetings);
pool->addCodeStyle(qtCodeStyle);
// default delegate for global preferences
@@ -148,7 +151,7 @@ QmlJSToolsSettings::~QmlJSToolsSettings()
m_globalCodeStyle = nullptr;
}
-SimpleCodeStylePreferences *QmlJSToolsSettings::globalCodeStyle()
+QmlJSCodeStylePreferences *QmlJSToolsSettings::globalCodeStyle()
{
return m_globalCodeStyle;
}
diff --git a/src/plugins/qmljstools/qmljstoolssettings.h b/src/plugins/qmljstools/qmljstoolssettings.h
index 85521d6b5e..7965b48912 100644
--- a/src/plugins/qmljstools/qmljstoolssettings.h
+++ b/src/plugins/qmljstools/qmljstoolssettings.h
@@ -29,9 +29,8 @@
#include <QObject>
-namespace TextEditor { class SimpleCodeStylePreferences; }
-
namespace QmlJSTools {
+class QmlJSCodeStylePreferences;
/**
* This class provides a central place for cpp tools settings.
@@ -44,7 +43,7 @@ public:
explicit QmlJSToolsSettings();
~QmlJSToolsSettings() override;
- static TextEditor::SimpleCodeStylePreferences *globalCodeStyle();
+ static QmlJSCodeStylePreferences *globalCodeStyle();
};
} // namespace QmlJSTools