forked from qt-creator/qt-creator
ClangFormat: Fix unsaving properties for global settings
- Fixed behavior "Formatting mode" combobox settings isn't saved after pressing "Ok" button when no one project is open. Now it works as expected, settings save after press "Ok" button. - Added additional applying interface for ICodeStylePreferenceFactory which allows pass-through apply call from dialog to the editor. Note: it doesn't work with read-only code style profiles Change-Id: If4f0c85e3105550db4ffd9860e94b678f0d9b386 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -201,11 +201,6 @@ void ClangFormatConfigWidget::showCombobox()
|
||||
m_ui->indentingOrFormatting->insertItem(indentIndex(), tr("Indenting only"));
|
||||
m_ui->indentingOrFormatting->insertItem(formatIndex(), tr("Full formatting"));
|
||||
|
||||
connect(m_ui->indentingOrFormatting, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int) {
|
||||
if (m_project)
|
||||
apply();
|
||||
});
|
||||
|
||||
if (ClangFormatSettings::instance().formatCodeInsteadOfIndent())
|
||||
m_ui->indentingOrFormatting->setCurrentIndex(formatIndex());
|
||||
else
|
||||
|
@@ -97,8 +97,9 @@ TextEditor::ICodeStylePreferences *CppCodeStylePreferencesFactory::createCodeSty
|
||||
return new CppCodeStylePreferences();
|
||||
}
|
||||
|
||||
QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
|
||||
QWidget *parent) const
|
||||
TextEditor::CodeStyleEditorWidget *CppCodeStylePreferencesFactory::createEditor(
|
||||
TextEditor::ICodeStylePreferences *preferences,
|
||||
QWidget *parent) const
|
||||
{
|
||||
auto cppPreferences = qobject_cast<CppCodeStylePreferences *>(preferences);
|
||||
if (!cppPreferences)
|
||||
@@ -129,7 +130,8 @@ QString CppCodeStylePreferencesFactory::previewText() const
|
||||
return QLatin1String(defaultPreviewText);
|
||||
}
|
||||
|
||||
std::pair<CppCodeStyleWidget *, QString> CppCodeStylePreferencesFactory::additionalTab(QWidget *parent) const
|
||||
std::pair<CppCodeStyleWidget *, QString> CppCodeStylePreferencesFactory::additionalTab(
|
||||
QWidget *parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return {nullptr, ""};
|
||||
|
@@ -40,8 +40,8 @@ public:
|
||||
Utils::Id languageId() override;
|
||||
QString displayName() override;
|
||||
TextEditor::ICodeStylePreferences *createCodeStyle() const override;
|
||||
QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
|
||||
QWidget *parent) const override;
|
||||
TextEditor::CodeStyleEditorWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
|
||||
QWidget *parent) const override;
|
||||
TextEditor::Indenter *createIndenter(QTextDocument *doc) const override;
|
||||
QString snippetProviderGroupId() const override;
|
||||
QString previewText() const override;
|
||||
|
@@ -97,7 +97,7 @@ static void applyRefactorings(QTextDocument *textDocument, TextEditorWidget *edi
|
||||
// ------------------ CppCodeStyleSettingsWidget
|
||||
|
||||
CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
: TextEditor::CodeStyleEditorWidget(parent),
|
||||
m_ui(new Ui::CppCodeStyleSettingsPage)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
@@ -363,9 +363,17 @@ void CppCodeStylePreferencesWidget::addTab(CppCodeStyleWidget *page, QString tab
|
||||
connect(this, &CppCodeStylePreferencesWidget::tabSettingsChanged,
|
||||
page, &CppCodeStyleWidget::setTabSettings);
|
||||
|
||||
connect(this, &CppCodeStylePreferencesWidget::applyEmitted,
|
||||
page, &CppCodeStyleWidget::apply);
|
||||
|
||||
page->synchronize();
|
||||
}
|
||||
|
||||
void CppCodeStylePreferencesWidget::apply()
|
||||
{
|
||||
emit applyEmitted();
|
||||
}
|
||||
|
||||
// ------------------ CppCodeStyleSettingsPage
|
||||
|
||||
CppCodeStyleSettingsPage::CppCodeStyleSettingsPage()
|
||||
|
@@ -66,7 +66,7 @@ namespace Internal {
|
||||
|
||||
namespace Ui { class CppCodeStyleSettingsPage; }
|
||||
|
||||
class CppCodeStylePreferencesWidget : public QWidget
|
||||
class CppCodeStylePreferencesWidget : public TextEditor::CodeStyleEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
|
||||
void setCodeStyle(CppCodeStylePreferences *codeStylePreferences);
|
||||
void addTab(CppCodeStyleWidget *page, QString tabName);
|
||||
void apply() override;
|
||||
|
||||
private:
|
||||
void decorateEditors(const TextEditor::FontSettings &fontSettings);
|
||||
@@ -96,6 +97,7 @@ private:
|
||||
signals:
|
||||
void codeStyleSettingsChanged(const CppEditor::CppCodeStyleSettings &);
|
||||
void tabSettingsChanged(const TextEditor::TabSettings &);
|
||||
void applyEmitted();
|
||||
};
|
||||
|
||||
|
||||
|
@@ -59,8 +59,9 @@ TextEditor::ICodeStylePreferences *NimCodeStylePreferencesFactory::createCodeSty
|
||||
return new TextEditor::SimpleCodeStylePreferences();
|
||||
}
|
||||
|
||||
QWidget *NimCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
|
||||
QWidget *parent) const
|
||||
TextEditor::CodeStyleEditorWidget *NimCodeStylePreferencesFactory::createEditor(
|
||||
TextEditor::ICodeStylePreferences *preferences,
|
||||
QWidget *parent) const
|
||||
{
|
||||
auto result = new NimCodeStylePreferencesWidget(preferences, parent);
|
||||
result->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
|
@@ -39,8 +39,8 @@ public:
|
||||
Utils::Id languageId() override;
|
||||
QString displayName() override;
|
||||
TextEditor::ICodeStylePreferences *createCodeStyle() const override;
|
||||
QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
|
||||
QWidget *parent) const override;
|
||||
TextEditor::CodeStyleEditorWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
|
||||
QWidget *parent) const override;
|
||||
TextEditor::Indenter *createIndenter(QTextDocument *doc) const override;
|
||||
QString snippetProviderGroupId() const override;
|
||||
QString previewText() const override;
|
||||
|
@@ -44,7 +44,7 @@ using namespace TextEditor;
|
||||
namespace Nim {
|
||||
|
||||
NimCodeStylePreferencesWidget::NimCodeStylePreferencesWidget(ICodeStylePreferences *preferences, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: TextEditor::CodeStyleEditorWidget(parent)
|
||||
, m_preferences(preferences)
|
||||
, m_ui(new Ui::NimCodeStylePreferencesWidget())
|
||||
{
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <texteditor/icodestylepreferencesfactory.h>
|
||||
|
||||
namespace TextEditor {
|
||||
class ICodeStylePreferences;
|
||||
@@ -36,7 +37,7 @@ namespace Nim {
|
||||
|
||||
namespace Ui { class NimCodeStylePreferencesWidget; }
|
||||
|
||||
class NimCodeStylePreferencesWidget : public QWidget
|
||||
class NimCodeStylePreferencesWidget : public TextEditor::CodeStyleEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@@ -71,8 +71,9 @@ TextEditor::ICodeStylePreferences *QmlJSCodeStylePreferencesFactory::createCodeS
|
||||
return new TextEditor::SimpleCodeStylePreferences();
|
||||
}
|
||||
|
||||
QWidget *QmlJSCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
|
||||
QWidget *parent) const
|
||||
TextEditor::CodeStyleEditorWidget *QmlJSCodeStylePreferencesFactory::createEditor(
|
||||
TextEditor::ICodeStylePreferences *preferences,
|
||||
QWidget *parent) const
|
||||
{
|
||||
auto widget = new Internal::QmlJSCodeStylePreferencesWidget(parent);
|
||||
widget->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
|
@@ -37,8 +37,8 @@ public:
|
||||
Utils::Id languageId() override;
|
||||
QString displayName() override;
|
||||
TextEditor::ICodeStylePreferences *createCodeStyle() const override;
|
||||
QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
|
||||
QWidget *parent) const override;
|
||||
TextEditor::CodeStyleEditorWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
|
||||
QWidget *parent) const override;
|
||||
TextEditor::Indenter *createIndenter(QTextDocument *doc) const override;
|
||||
QString snippetProviderGroupId() const override;
|
||||
QString previewText() const override;
|
||||
|
@@ -51,7 +51,7 @@ namespace Internal {
|
||||
// ------------------ CppCodeStyleSettingsWidget
|
||||
|
||||
QmlJSCodeStylePreferencesWidget::QmlJSCodeStylePreferencesWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
TextEditor::CodeStyleEditorWidget(parent),
|
||||
m_ui(new Ui::QmlJSCodeStyleSettingsPage)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
@@ -26,6 +26,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <texteditor/icodestylepreferencesfactory.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
|
||||
@@ -45,7 +47,7 @@ namespace Internal {
|
||||
|
||||
namespace Ui { class QmlJSCodeStyleSettingsPage; }
|
||||
|
||||
class QmlJSCodeStylePreferencesWidget : public QWidget
|
||||
class QmlJSCodeStylePreferencesWidget : public TextEditor::CodeStyleEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@@ -104,7 +104,7 @@ CodeStyleDialog::CodeStyleDialog(ICodeStylePreferencesFactory *factory,
|
||||
m_codeStyle->setValue(codeStyle->value());
|
||||
m_codeStyle->setId(codeStyle->id());
|
||||
m_codeStyle->setDisplayName(m_originalDisplayName);
|
||||
QWidget *editor = factory->createEditor(m_codeStyle, this);
|
||||
TextEditor::CodeStyleEditorWidget *editor = factory->createEditor(m_codeStyle, this);
|
||||
|
||||
m_buttons = new QDialogButtonBox(
|
||||
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||
@@ -120,6 +120,7 @@ CodeStyleDialog::CodeStyleDialog(ICodeStylePreferencesFactory *factory,
|
||||
|
||||
connect(m_lineEdit, &QLineEdit::textChanged, this, &CodeStyleDialog::slotDisplayNameChanged);
|
||||
connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(m_buttons, &QDialogButtonBox::accepted, editor, &TextEditor::CodeStyleEditorWidget::apply);
|
||||
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
}
|
||||
|
||||
|
@@ -61,7 +61,7 @@ public:
|
||||
virtual Utils::Id languageId() = 0;
|
||||
virtual QString displayName() = 0;
|
||||
virtual ICodeStylePreferences *createCodeStyle() const = 0;
|
||||
virtual QWidget *createEditor(ICodeStylePreferences *preferences, QWidget *parent) const = 0;
|
||||
virtual CodeStyleEditorWidget *createEditor(ICodeStylePreferences *preferences, QWidget *parent) const = 0;
|
||||
virtual TextEditor::Indenter *createIndenter(QTextDocument *doc) const = 0;
|
||||
virtual QString snippetProviderGroupId() const = 0;
|
||||
virtual QString previewText() const = 0;
|
||||
|
Reference in New Issue
Block a user