diff options
author | Artem Sokolovskii <artem.sokolovskii@qt.io> | 2022-07-28 16:13:35 +0200 |
---|---|---|
committer | Artem Sokolovskii <artem.sokolovskii@qt.io> | 2022-08-05 09:41:14 +0000 |
commit | e572bdd90c6abcf763e6713dc9a38bd49b66db6c (patch) | |
tree | 216a85f1579136d3b9bbae87b2929319e0f90196 /src/plugins/clangformat | |
parent | e24591dbe5bb2b7bea8beefe9d2a7b576471c4b3 (diff) |
ClangFormat: Move global settings in main page
The settings: indenting instead formatting, format while
typing, format edited on file save are moved to Code Style
page.
Change-Id: I28787b44602ce288961c778fe704ad2a1a05913f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/clangformat')
-rw-r--r-- | src/plugins/clangformat/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformat.qbs | 3 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformatconfigwidget.cpp | 68 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformatconfigwidget.h | 3 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformatconfigwidget.ui | 41 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformatglobalconfigwidget.cpp | 99 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformatglobalconfigwidget.h | 55 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformatglobalconfigwidget.ui | 89 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformatplugin.cpp | 7 |
9 files changed, 254 insertions, 112 deletions
diff --git a/src/plugins/clangformat/CMakeLists.txt b/src/plugins/clangformat/CMakeLists.txt index 3c648da592..ebe0bebc71 100644 --- a/src/plugins/clangformat/CMakeLists.txt +++ b/src/plugins/clangformat/CMakeLists.txt @@ -6,6 +6,7 @@ add_qtc_plugin(ClangFormat clangformatbaseindenter.cpp clangformatbaseindenter.h clangformatchecks.ui clangformatconfigwidget.cpp clangformatconfigwidget.h clangformatconfigwidget.ui + clangformatglobalconfigwidget.cpp clangformatglobalconfigwidget.h clangformatglobalconfigwidget.ui clangformatconstants.h clangformatfile.cpp clangformatfile.h clangformatindenter.cpp clangformatindenter.h diff --git a/src/plugins/clangformat/clangformat.qbs b/src/plugins/clangformat/clangformat.qbs index f7d60ad73d..c6b4043698 100644 --- a/src/plugins/clangformat/clangformat.qbs +++ b/src/plugins/clangformat/clangformat.qbs @@ -39,6 +39,9 @@ QtcPlugin { "clangformatconfigwidget.h", "clangformatconfigwidget.ui", "clangformatconstants.h", + "clangformatglobalconfigwidget.cpp", + "clangformatglobalconfigwidget.h", + "clangformatglobalconfigwidget.ui", "clangformatfile.cpp", "clangformatfile.h", "clangformatindenter.cpp", diff --git a/src/plugins/clangformat/clangformatconfigwidget.cpp b/src/plugins/clangformat/clangformatconfigwidget.cpp index 9178156391..0474856365 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.cpp +++ b/src/plugins/clangformat/clangformatconfigwidget.cpp @@ -42,11 +42,8 @@ #include <cppeditor/cpphighlighter.h> #include <cppeditor/cppcodestylesettings.h> #include <cppeditor/cppcodestylesnippets.h> -#include <extensionsystem/pluginmanager.h> -#include <extensionsystem/pluginspec.h> #include <projectexplorer/project.h> #include <projectexplorer/session.h> -#include <projectexplorer/editorconfiguration.h> #include <texteditor/displaysettings.h> #include <texteditor/icodestylepreferences.h> #include <texteditor/snippets/snippeteditor.h> @@ -54,7 +51,6 @@ #include <texteditor/texteditorsettings.h> #include <utils/executeondestruction.h> #include <utils/qtcassert.h> -#include <utils/genericconstants.h> #include <QFile> #include <QMessageBox> @@ -88,8 +84,6 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc initChecksAndPreview(!codeStyle->isReadOnly()); initOverrideCheckBox(); - initCheckBoxes(); - initIndentationOrFormattingCombobox(); showOrHideWidgets(); fillTable(); @@ -132,45 +126,6 @@ void ClangFormatConfigWidget::initChecksAndPreview(bool enabled) m_preview->textDocument()->indenter()->setFileName(fileName); } -void ClangFormatConfigWidget::initCheckBoxes() -{ - if (m_project) { - m_ui->formatOnSave->hide(); - m_ui->formatWhileTyping->hide(); - return; - } - - m_ui->formatOnSave->show(); - m_ui->formatWhileTyping->show(); - - auto setEnableCheckBoxes = [this](int index) { - bool isFormatting = index == static_cast<int>(ClangFormatSettings::Mode::Formatting); - - m_ui->formatOnSave->setEnabled(isFormatting); - m_ui->formatWhileTyping->setEnabled(isFormatting); - }; - setEnableCheckBoxes(m_ui->indentingOrFormatting->currentIndex()); - connect(m_ui->indentingOrFormatting, &QComboBox::currentIndexChanged, - this, setEnableCheckBoxes); - - m_ui->formatOnSave->setChecked(ClangFormatSettings::instance().formatOnSave()); - m_ui->formatWhileTyping->setChecked(ClangFormatSettings::instance().formatWhileTyping()); - - connect(m_ui->formatOnSave, &QCheckBox::toggled, - this, [](bool checked) { - ClangFormatSettings &settings = ClangFormatSettings::instance(); - settings.setFormatOnSave(checked); - settings.write(); - }); - - connect(m_ui->formatWhileTyping, &QCheckBox::toggled, - this, [](bool checked) { - ClangFormatSettings &settings = ClangFormatSettings::instance(); - settings.setFormatWhileTyping(checked); - settings.write(); - }); -} - void ClangFormatConfigWidget::initOverrideCheckBox() { if (m_project) { @@ -219,29 +174,6 @@ void ClangFormatConfigWidget::onTableChanged() saveChanges(sender()); } -void ClangFormatConfigWidget::initIndentationOrFormattingCombobox() -{ - m_ui->indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Indenting), - tr("Indenting only")); - m_ui->indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Formatting), - tr("Full formatting")); - m_ui->indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Disable), - tr("Disable")); - - m_ui->indentingOrFormatting->setCurrentIndex( - static_cast<int>(ClangFormatSettings::instance().mode())); - - const bool isGlobal = !m_project; - m_ui->indentingOrFormatting->setVisible(isGlobal); - m_ui->formattingModeLabel->setVisible(isGlobal); - - connect(m_ui->indentingOrFormatting, &QComboBox::currentIndexChanged, this, [](int index) { - ClangFormatSettings &settings = ClangFormatSettings::instance(); - settings.setMode(static_cast<ClangFormatSettings::Mode>(index)); - settings.write(); - }); -} - static bool projectConfigExists() { return Core::ICore::userResourcePath() diff --git a/src/plugins/clangformat/clangformatconfigwidget.h b/src/plugins/clangformat/clangformatconfigwidget.h index 3b6f2aa163..edfdd8999d 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.h +++ b/src/plugins/clangformat/clangformatconfigwidget.h @@ -65,13 +65,10 @@ private: void showOrHideWidgets(); void initChecksAndPreview(bool enabled); void initOverrideCheckBox(); - void initCheckBoxes(); void connectChecks(); void fillTable(); void saveChanges(QObject *sender); - - void initIndentationOrFormattingCombobox(); void updatePreview(); ProjectExplorer::Project *m_project; diff --git a/src/plugins/clangformat/clangformatconfigwidget.ui b/src/plugins/clangformat/clangformatconfigwidget.ui index a0a042c273..b64026f4ad 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.ui +++ b/src/plugins/clangformat/clangformatconfigwidget.ui @@ -27,47 +27,6 @@ <number>8</number> </property> <item> - <layout class="QHBoxLayout" name="formattingModeLayout"> - <item> - <widget class="QLabel" name="formattingModeLabel"> - <property name="text"> - <string>Formatting mode:</string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="indentingOrFormatting"/> - </item> - <item> - <spacer name="formattingModeSpacer"> - <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> - <item> - <widget class="QCheckBox" name="formatWhileTyping"> - <property name="text"> - <string>Format while typing</string> - </property> - </widget> - </item> - <item> - <widget class="QCheckBox" name="formatOnSave"> - <property name="text"> - <string>Format edited code on file save</string> - </property> - </widget> - </item> - <item> <widget class="QLabel" name="projectHasClangFormat"> <property name="text"> <string/> diff --git a/src/plugins/clangformat/clangformatglobalconfigwidget.cpp b/src/plugins/clangformat/clangformatglobalconfigwidget.cpp new file mode 100644 index 0000000000..91030cb3d8 --- /dev/null +++ b/src/plugins/clangformat/clangformatglobalconfigwidget.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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 "clangformatglobalconfigwidget.h" + +#include "clangformatconstants.h" +#include "clangformatsettings.h" + +#include "ui_clangformatglobalconfigwidget.h" + +#include <projectexplorer/project.h> + +#include <sstream> + +using namespace ProjectExplorer; + +namespace ClangFormat { + +ClangFormatGlobalConfigWidget::ClangFormatGlobalConfigWidget(ProjectExplorer::Project *project, + QWidget *parent) + : CppCodeStyleWidget(parent) + , m_ui(std::make_unique<Ui::ClangFormatGlobalConfigWidget>()) +{ + m_ui->setupUi(this); + + initCheckBoxes(); + initIndentationOrFormattingCombobox(); + + if (project) { + m_ui->settingsGroupBox->hide(); + return; + } + m_ui->settingsGroupBox->show(); +} + +ClangFormatGlobalConfigWidget::~ClangFormatGlobalConfigWidget() = default; + +void ClangFormatGlobalConfigWidget::initCheckBoxes() +{ + auto setEnableCheckBoxes = [this](int index) { + bool isFormatting = index == static_cast<int>(ClangFormatSettings::Mode::Formatting); + + m_ui->formatOnSave->setEnabled(isFormatting); + m_ui->formatWhileTyping->setEnabled(isFormatting); + }; + setEnableCheckBoxes(m_ui->indentingOrFormatting->currentIndex()); + connect(m_ui->indentingOrFormatting, &QComboBox::currentIndexChanged, + this, setEnableCheckBoxes); + + m_ui->formatOnSave->setChecked(ClangFormatSettings::instance().formatOnSave()); + m_ui->formatWhileTyping->setChecked(ClangFormatSettings::instance().formatWhileTyping()); +} + +void ClangFormatGlobalConfigWidget::initIndentationOrFormattingCombobox() +{ + m_ui->indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Indenting), + tr("Indenting only")); + m_ui->indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Formatting), + tr("Full formatting")); + m_ui->indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Disable), + tr("Disable")); + + m_ui->indentingOrFormatting->setCurrentIndex( + static_cast<int>(ClangFormatSettings::instance().mode())); +} + + +void ClangFormatGlobalConfigWidget::apply() +{ + ClangFormatSettings &settings = ClangFormatSettings::instance(); + settings.setFormatOnSave(m_ui->formatOnSave->isChecked()); + settings.setFormatWhileTyping(m_ui->formatWhileTyping->isChecked()); + settings.setMode(static_cast<ClangFormatSettings::Mode>(m_ui->indentingOrFormatting->currentIndex())); + settings.write(); +} + +} // namespace ClangFormat diff --git a/src/plugins/clangformat/clangformatglobalconfigwidget.h b/src/plugins/clangformat/clangformatglobalconfigwidget.h new file mode 100644 index 0000000000..898a6cfa00 --- /dev/null +++ b/src/plugins/clangformat/clangformatglobalconfigwidget.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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 <cppeditor/cppcodestylesettingspage.h> + +#include <memory> + +namespace ProjectExplorer { class Project; } + +namespace ClangFormat { + +namespace Ui { class ClangFormatGlobalConfigWidget; } + +class ClangFormatGlobalConfigWidget : public CppEditor::CppCodeStyleWidget +{ + Q_OBJECT + +public: + explicit ClangFormatGlobalConfigWidget(ProjectExplorer::Project *project = nullptr, + QWidget *parent = nullptr); + ~ClangFormatGlobalConfigWidget() override; + void apply() override; + +private: + void initCheckBoxes(); + void initIndentationOrFormattingCombobox(); + + std::unique_ptr<Ui::ClangFormatGlobalConfigWidget> m_ui; +}; + +} // namespace ClangFormat diff --git a/src/plugins/clangformat/clangformatglobalconfigwidget.ui b/src/plugins/clangformat/clangformatglobalconfigwidget.ui new file mode 100644 index 0000000000..f4beb6ecd0 --- /dev/null +++ b/src/plugins/clangformat/clangformatglobalconfigwidget.ui @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ClangFormat::ClangFormatGlobalConfigWidget</class> + <widget class="QWidget" name="ClangFormat::ClangFormatGlobalConfigWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>489</width> + <height>145</height> + </rect> + </property> + <property name="windowTitle"> + <string/> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="leftMargin"> + <number>8</number> + </property> + <property name="topMargin"> + <number>8</number> + </property> + <property name="rightMargin"> + <number>8</number> + </property> + <property name="bottomMargin"> + <number>8</number> + </property> + <item> + <widget class="QGroupBox" name="settingsGroupBox"> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <property name="title"> + <string>ClangFormat global setting:</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QHBoxLayout" name="formattingModeLayout"> + <item> + <widget class="QLabel" name="formattingModeLabel"> + <property name="text"> + <string>Formatting mode:</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="indentingOrFormatting"/> + </item> + <item> + <spacer name="formattingModeSpacer"> + <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> + <item> + <widget class="QCheckBox" name="formatWhileTyping"> + <property name="text"> + <string>Format while typing</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="formatOnSave"> + <property name="text"> + <string>Format edited code on file save</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/plugins/clangformat/clangformatplugin.cpp b/src/plugins/clangformat/clangformatplugin.cpp index 0b2c2fd5a6..560c98eee6 100644 --- a/src/plugins/clangformat/clangformatplugin.cpp +++ b/src/plugins/clangformat/clangformatplugin.cpp @@ -26,6 +26,7 @@ #include "clangformatplugin.h" #include "clangformatconfigwidget.h" +#include "clangformatglobalconfigwidget.h" #include "clangformatconstants.h" #include "clangformatindenter.h" #include "clangformatsettings.h" @@ -95,6 +96,12 @@ public: { return {new ClangFormatConfigWidget(codeStyle, project, parent), tr("ClangFormat")}; } + + TextEditor::CodeStyleEditorWidget *createAdditionalGlobalSettings( + ProjectExplorer::Project *project, QWidget *parent) + { + return new ClangFormatGlobalConfigWidget(project, parent); + } }; static void replaceCppCodeStyle() |