forked from qt-creator/qt-creator
ClangFormat: Fix settings checkboxes disappearance
- Fixed settings checkboxes disappearance after open a project - Fixed impossibility to save settings Task-number: QTCREATORBUG-26948 Change-Id: Ia73a61bf56b99adea9ed45c9d656860b185a3d7e Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -131,14 +131,13 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(ProjectExplorer::Project *proje
|
||||
|
||||
initChecksAndPreview();
|
||||
|
||||
if (m_project) {
|
||||
m_ui->applyButton->show();
|
||||
if (m_project) {
|
||||
hideGlobalCheckboxes();
|
||||
m_ui->fallbackConfig->hide();
|
||||
m_ui->overrideDefault->setChecked(
|
||||
m_project->namedSettings(Constants::OVERRIDE_FILE_ID).toBool());
|
||||
} else {
|
||||
m_ui->applyButton->hide();
|
||||
showGlobalCheckboxes();
|
||||
m_ui->overrideDefault->setChecked(ClangFormatSettings::instance().overrideDefaultFile());
|
||||
m_ui->overrideDefault->setToolTip(
|
||||
@@ -179,12 +178,13 @@ void ClangFormatConfigWidget::initChecksAndPreview()
|
||||
m_preview->textDocument()->setSyntaxHighlighter(new CppEditor::CppHighlighter);
|
||||
|
||||
Utils::FilePath fileName;
|
||||
if (m_project) {
|
||||
connect(m_ui->applyButton, &QPushButton::clicked, this, &ClangFormatConfigWidget::apply);
|
||||
if (m_project) {
|
||||
fileName = m_project->projectFilePath().pathAppended("snippet.cpp");
|
||||
} else {
|
||||
fileName = Core::ICore::userResourcePath("snippet.cpp");
|
||||
}
|
||||
|
||||
m_preview->textDocument()->indenter()->setFileName(fileName);
|
||||
}
|
||||
|
||||
|
@@ -84,11 +84,10 @@ public:
|
||||
return new ClangFormatIndenter(doc);
|
||||
}
|
||||
|
||||
std::pair<CppEditor::CppCodeStyleWidget *, QString> additionalTab(QWidget *parent) const override
|
||||
std::pair<CppEditor::CppCodeStyleWidget *, QString> additionalTab(
|
||||
ProjectExplorer::Project *project, QWidget *parent) const override
|
||||
{
|
||||
if (!parent)
|
||||
return {new ClangFormatConfigWidget(), tr("ClangFormat")};
|
||||
return {new ClangFormatConfigWidget(SessionManager::startupProject()), tr("ClangFormat")};
|
||||
return {new ClangFormatConfigWidget(project, parent), tr("ClangFormat")};
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -98,6 +98,7 @@ TextEditor::ICodeStylePreferences *CppCodeStylePreferencesFactory::createCodeSty
|
||||
}
|
||||
|
||||
QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent) const
|
||||
{
|
||||
auto cppPreferences = qobject_cast<CppCodeStylePreferences *>(preferences);
|
||||
@@ -108,7 +109,7 @@ QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePref
|
||||
widget->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
widget->setCodeStyle(cppPreferences);
|
||||
|
||||
const auto tab = additionalTab(parent);
|
||||
const auto tab = additionalTab(project, parent);
|
||||
widget->addTab(tab.first, tab.second);
|
||||
|
||||
return widget;
|
||||
@@ -129,9 +130,10 @@ QString CppCodeStylePreferencesFactory::previewText() const
|
||||
return QLatin1String(defaultPreviewText);
|
||||
}
|
||||
|
||||
std::pair<CppCodeStyleWidget *, QString> CppCodeStylePreferencesFactory::additionalTab(QWidget *parent) const
|
||||
std::pair<CppCodeStyleWidget *, QString> CppCodeStylePreferencesFactory::additionalTab(ProjectExplorer::Project *project, QWidget *parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
Q_UNUSED(project)
|
||||
return {nullptr, ""};
|
||||
}
|
||||
|
||||
|
@@ -41,11 +41,13 @@ public:
|
||||
QString displayName() override;
|
||||
TextEditor::ICodeStylePreferences *createCodeStyle() const override;
|
||||
QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent) const override;
|
||||
TextEditor::Indenter *createIndenter(QTextDocument *doc) const override;
|
||||
QString snippetProviderGroupId() const override;
|
||||
QString previewText() const override;
|
||||
virtual std::pair<CppCodeStyleWidget *, QString> additionalTab(QWidget *parent) const;
|
||||
virtual std::pair<CppCodeStyleWidget *, QString> additionalTab(ProjectExplorer::Project *project,
|
||||
QWidget *parent) const;
|
||||
};
|
||||
|
||||
} // namespace CppEditor
|
||||
|
@@ -60,8 +60,10 @@ TextEditor::ICodeStylePreferences *NimCodeStylePreferencesFactory::createCodeSty
|
||||
}
|
||||
|
||||
QWidget *NimCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent) const
|
||||
{
|
||||
Q_UNUSED(project)
|
||||
auto result = new NimCodeStylePreferencesWidget(preferences, parent);
|
||||
result->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
return result;
|
||||
|
@@ -40,6 +40,7 @@ public:
|
||||
QString displayName() override;
|
||||
TextEditor::ICodeStylePreferences *createCodeStyle() const override;
|
||||
QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent) const override;
|
||||
TextEditor::Indenter *createIndenter(QTextDocument *doc) const override;
|
||||
QString snippetProviderGroupId() const override;
|
||||
|
@@ -44,7 +44,7 @@ CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project) : QWidget(),
|
||||
Utils::Id languageId = factory->languageId();
|
||||
ICodeStylePreferences *codeStylePreferences = config->codeStyle(languageId);
|
||||
|
||||
auto preview = factory->createCodeStyleEditor(codeStylePreferences, m_ui.stackedWidget);
|
||||
auto preview = factory->createCodeStyleEditor(codeStylePreferences, project, m_ui.stackedWidget);
|
||||
if (preview && preview->layout())
|
||||
preview->layout()->setContentsMargins(QMargins());
|
||||
m_ui.stackedWidget->addWidget(preview);
|
||||
|
@@ -71,9 +71,12 @@ TextEditor::ICodeStylePreferences *QmlJSCodeStylePreferencesFactory::createCodeS
|
||||
return new TextEditor::SimpleCodeStylePreferences();
|
||||
}
|
||||
|
||||
QWidget *QmlJSCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
|
||||
QWidget *QmlJSCodeStylePreferencesFactory::createEditor(
|
||||
TextEditor::ICodeStylePreferences *preferences,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent) const
|
||||
{
|
||||
Q_UNUSED(project)
|
||||
auto widget = new Internal::QmlJSCodeStylePreferencesWidget(parent);
|
||||
widget->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
widget->setPreferences(preferences);
|
||||
|
@@ -38,6 +38,7 @@ public:
|
||||
QString displayName() override;
|
||||
TextEditor::ICodeStylePreferences *createCodeStyle() const override;
|
||||
QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent) const override;
|
||||
TextEditor::Indenter *createIndenter(QTextDocument *doc) const override;
|
||||
QString snippetProviderGroupId() const override;
|
||||
|
@@ -42,13 +42,15 @@
|
||||
using namespace TextEditor;
|
||||
|
||||
CodeStyleEditor::CodeStyleEditor(ICodeStylePreferencesFactory *factory,
|
||||
ICodeStylePreferences *codeStyle, QWidget *parent)
|
||||
: CodeStyleEditorWidget(parent),
|
||||
m_factory(factory),
|
||||
m_codeStyle(codeStyle)
|
||||
ICodeStylePreferences *codeStyle,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent)
|
||||
: CodeStyleEditorWidget(parent)
|
||||
, m_factory(factory)
|
||||
, m_codeStyle(codeStyle)
|
||||
{
|
||||
m_layout = new QVBoxLayout(this);
|
||||
auto selector = new CodeStyleSelectorWidget(factory, this);
|
||||
auto selector = new CodeStyleSelectorWidget(factory, project, this);
|
||||
selector->setCodeStyle(codeStyle);
|
||||
m_preview = new SnippetEditorWidget(this);
|
||||
DisplaySettings displaySettings = m_preview->displaySettings();
|
||||
|
@@ -33,6 +33,7 @@ QT_BEGIN_NAMESPACE
|
||||
class QVBoxLayout;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace ProjectExplorer { class Project; }
|
||||
namespace TextEditor {
|
||||
|
||||
class ICodeStylePreferencesFactory;
|
||||
@@ -44,7 +45,9 @@ class TEXTEDITOR_EXPORT CodeStyleEditor : public CodeStyleEditorWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
CodeStyleEditor(ICodeStylePreferencesFactory *factory,
|
||||
ICodeStylePreferences *codeStyle, QWidget *parent = nullptr);
|
||||
ICodeStylePreferences *codeStyle,
|
||||
ProjectExplorer::Project *project = nullptr,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
void updatePreview();
|
||||
|
@@ -52,8 +52,10 @@ class CodeStyleDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CodeStyleDialog(ICodeStylePreferencesFactory *factory,
|
||||
ICodeStylePreferences *codeStyle, QWidget *parent = nullptr);
|
||||
explicit CodeStyleDialog(ICodeStylePreferencesFactory *factory,
|
||||
ICodeStylePreferences *codeStyle,
|
||||
ProjectExplorer::Project *project = nullptr,
|
||||
QWidget *parent = nullptr);
|
||||
~CodeStyleDialog() override;
|
||||
ICodeStylePreferences *codeStyle() const;
|
||||
private:
|
||||
@@ -69,7 +71,9 @@ private:
|
||||
};
|
||||
|
||||
CodeStyleDialog::CodeStyleDialog(ICodeStylePreferencesFactory *factory,
|
||||
ICodeStylePreferences *codeStyle, QWidget *parent)
|
||||
ICodeStylePreferences *codeStyle,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowTitle(tr("Edit Code Style"));
|
||||
@@ -104,7 +108,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);
|
||||
QWidget *editor = factory->createEditor(m_codeStyle, project, this);
|
||||
|
||||
m_buttons = new QDialogButtonBox(
|
||||
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||
@@ -153,10 +157,13 @@ CodeStyleDialog::~CodeStyleDialog()
|
||||
|
||||
} // Internal
|
||||
|
||||
CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *factory, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_factory(factory),
|
||||
m_ui(new Internal::Ui::CodeStyleSelectorWidget)
|
||||
CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *factory,
|
||||
ProjectExplorer::Project *project,
|
||||
QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_factory(factory)
|
||||
, m_project(project)
|
||||
, m_ui(new Internal::Ui::CodeStyleSelectorWidget)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->importButton->setEnabled(false);
|
||||
@@ -283,7 +290,7 @@ void CodeStyleSelectorWidget::slotEditClicked()
|
||||
ICodeStylePreferences *codeStyle = m_codeStyle->currentPreferences();
|
||||
// check if it's read-only
|
||||
|
||||
Internal::CodeStyleDialog dialog(m_factory, codeStyle, this);
|
||||
Internal::CodeStyleDialog dialog(m_factory, codeStyle, m_project, this);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
ICodeStylePreferences *dialogCodeStyle = dialog.codeStyle();
|
||||
if (codeStyle->isReadOnly()) {
|
||||
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace ProjectExplorer { class Project; }
|
||||
namespace TextEditor {
|
||||
|
||||
namespace Internal { namespace Ui { class CodeStyleSelectorWidget; } }
|
||||
@@ -40,7 +41,9 @@ class TEXTEDITOR_EXPORT CodeStyleSelectorWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CodeStyleSelectorWidget(ICodeStylePreferencesFactory *factory, QWidget *parent = nullptr);
|
||||
explicit CodeStyleSelectorWidget(ICodeStylePreferencesFactory *factory,
|
||||
ProjectExplorer::Project *project = nullptr,
|
||||
QWidget *parent = nullptr);
|
||||
~CodeStyleSelectorWidget() override;
|
||||
|
||||
void setCodeStyle(TextEditor::ICodeStylePreferences *codeStyle);
|
||||
@@ -60,6 +63,7 @@ private:
|
||||
void updateName(ICodeStylePreferences *codeStyle);
|
||||
ICodeStylePreferencesFactory *m_factory;
|
||||
ICodeStylePreferences *m_codeStyle = nullptr;
|
||||
ProjectExplorer::Project *m_project = nullptr;
|
||||
|
||||
QString displayName(ICodeStylePreferences *codeStyle) const;
|
||||
|
||||
|
@@ -34,7 +34,7 @@ ICodeStylePreferencesFactory::ICodeStylePreferencesFactory()
|
||||
}
|
||||
|
||||
CodeStyleEditorWidget *ICodeStylePreferencesFactory::createCodeStyleEditor(
|
||||
ICodeStylePreferences *codeStyle, QWidget *parent)
|
||||
ICodeStylePreferences *codeStyle, ProjectExplorer::Project *project, QWidget *parent)
|
||||
{
|
||||
return new CodeStyleEditor(this, codeStyle, parent);
|
||||
return new CodeStyleEditor(this, codeStyle, project, parent);
|
||||
}
|
||||
|
@@ -33,6 +33,8 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace ProjectExplorer { class Project; }
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
class ICodeStylePreferences;
|
||||
@@ -57,11 +59,14 @@ public:
|
||||
virtual ~ICodeStylePreferencesFactory() = default;
|
||||
|
||||
virtual CodeStyleEditorWidget *createCodeStyleEditor(ICodeStylePreferences *codeStyle,
|
||||
ProjectExplorer::Project *project = nullptr,
|
||||
QWidget *parent = nullptr);
|
||||
virtual Utils::Id languageId() = 0;
|
||||
virtual QString displayName() = 0;
|
||||
virtual ICodeStylePreferences *createCodeStyle() const = 0;
|
||||
virtual QWidget *createEditor(ICodeStylePreferences *preferences, QWidget *parent) const = 0;
|
||||
virtual QWidget *createEditor(ICodeStylePreferences *preferences,
|
||||
ProjectExplorer::Project *project = nullptr,
|
||||
QWidget *parent = nullptr) 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