diff --git a/src/plugins/beautifier/CMakeLists.txt b/src/plugins/beautifier/CMakeLists.txt index 79d2d9a855f..23e8a10c00c 100644 --- a/src/plugins/beautifier/CMakeLists.txt +++ b/src/plugins/beautifier/CMakeLists.txt @@ -13,7 +13,7 @@ add_qtc_plugin(Beautifier beautifierplugin.cpp beautifierplugin.h clangformat/clangformat.cpp clangformat/clangformat.h clangformat/clangformatconstants.h - clangformat/clangformatoptionspage.cpp clangformat/clangformatoptionspage.h clangformat/clangformatoptionspage.ui + clangformat/clangformatoptionspage.cpp clangformat/clangformatoptionspage.h clangformat/clangformatsettings.cpp clangformat/clangformatsettings.h configurationdialog.cpp configurationdialog.h configurationdialog.ui configurationeditor.cpp configurationeditor.h diff --git a/src/plugins/beautifier/beautifier.qbs b/src/plugins/beautifier/beautifier.qbs index c3676f93758..fc91980126b 100644 --- a/src/plugins/beautifier/beautifier.qbs +++ b/src/plugins/beautifier/beautifier.qbs @@ -55,7 +55,6 @@ QtcPlugin { "clangformatconstants.h", "clangformatoptionspage.cpp", "clangformatoptionspage.h", - "clangformatoptionspage.ui", "clangformatsettings.cpp", "clangformatsettings.h" ] diff --git a/src/plugins/beautifier/clangformat/clangformatoptionspage.cpp b/src/plugins/beautifier/clangformat/clangformatoptionspage.cpp index 6a8e2503534..77679fd925d 100644 --- a/src/plugins/beautifier/clangformat/clangformatoptionspage.cpp +++ b/src/plugins/beautifier/clangformat/clangformatoptionspage.cpp @@ -24,16 +24,25 @@ ****************************************************************************/ #include "clangformatoptionspage.h" -#include "ui_clangformatoptionspage.h" #include "clangformatconstants.h" #include "clangformatsettings.h" #include "../beautifierconstants.h" #include "../beautifierplugin.h" +#include "../configurationpanel.h" -namespace Beautifier { -namespace Internal { +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace Beautifier::Internal { class ClangFormatOptionsPageWidget : public Core::IOptionsPageWidget { @@ -45,60 +54,104 @@ public: void apply() final; private: - Ui::ClangFormatOptionsPage ui; ClangFormatSettings *m_settings; + ConfigurationPanel *m_configurations; + QRadioButton *m_usePredefinedStyle; + QComboBox *m_predefinedStyle; + QComboBox *m_fallbackStyle; + Utils::PathChooser *m_command; + QLineEdit *m_mime; }; ClangFormatOptionsPageWidget::ClangFormatOptionsPageWidget(ClangFormatSettings *settings) : m_settings(settings) { - ui.setupUi(this); - ui.options->setEnabled(false); - ui.predefinedStyle->addItems(m_settings->predefinedStyles()); - ui.fallbackStyle->addItems(m_settings->fallbackStyles()); - ui.command->setExpectedKind(Utils::PathChooser::ExistingCommand); - ui.command->setCommandVersionArguments({"--version"}); - ui.command->setPromptDialogTitle( - BeautifierPlugin::msgCommandPromptDialogTitle("Clang Format")); - connect(ui.command, &Utils::PathChooser::validChanged, ui.options, &QWidget::setEnabled); - connect(ui.predefinedStyle, &QComboBox::currentTextChanged, [this](const QString &item) { - ui.fallbackStyle->setEnabled(item == "File"); - }); - connect(ui.usePredefinedStyle, &QRadioButton::toggled, [this](bool checked) { - ui.fallbackStyle->setEnabled(checked && ui.predefinedStyle->currentText() == "File"); - ui.predefinedStyle->setEnabled(checked); - }); - ui.configurations->setSettings(m_settings); + auto options = new QGroupBox(tr("Options")); + options->setEnabled(false); - ui.command->setFilePath(m_settings->command()); - ui.mime->setText(m_settings->supportedMimeTypesAsString()); - const int predefinedStyleIndex = ui.predefinedStyle->findText(m_settings->predefinedStyle()); + auto useCustomizedStyle = new QRadioButton(tr("Use customized style:")); + useCustomizedStyle->setAutoExclusive(true); + + m_configurations = new ConfigurationPanel; + m_configurations->setSettings(m_settings); + m_configurations->setCurrentConfiguration(m_settings->customStyle()); + + m_usePredefinedStyle = new QRadioButton(tr("Use predefined style:")); + + m_usePredefinedStyle->setChecked(true); + m_usePredefinedStyle->setAutoExclusive(true); + + m_predefinedStyle = new QComboBox; + m_predefinedStyle->addItems(m_settings->predefinedStyles()); + const int predefinedStyleIndex = m_predefinedStyle->findText(m_settings->predefinedStyle()); if (predefinedStyleIndex != -1) - ui.predefinedStyle->setCurrentIndex(predefinedStyleIndex); - const int fallbackStyleIndex = ui.fallbackStyle->findText(m_settings->fallbackStyle()); + m_predefinedStyle->setCurrentIndex(predefinedStyleIndex); + + m_fallbackStyle = new QComboBox; + m_fallbackStyle->addItems(m_settings->fallbackStyles()); + m_fallbackStyle->setEnabled(false); + const int fallbackStyleIndex = m_fallbackStyle->findText(m_settings->fallbackStyle()); if (fallbackStyleIndex != -1) - ui.fallbackStyle->setCurrentIndex(fallbackStyleIndex); - ui.configurations->setSettings(m_settings); - ui.configurations->setCurrentConfiguration(m_settings->customStyle()); + m_fallbackStyle->setCurrentIndex(fallbackStyleIndex); + + m_mime = new QLineEdit(m_settings->supportedMimeTypesAsString()); + + m_command = new Utils::PathChooser; + m_command->setExpectedKind(Utils::PathChooser::ExistingCommand); + m_command->setCommandVersionArguments({"--version"}); + m_command->setPromptDialogTitle( + BeautifierPlugin::msgCommandPromptDialogTitle("Clang Format")); + m_command->setFilePath(m_settings->command()); if (m_settings->usePredefinedStyle()) - ui.usePredefinedStyle->setChecked(true); + m_usePredefinedStyle->setChecked(true); else - ui.useCustomizedStyle->setChecked(true); + useCustomizedStyle->setChecked(true); + + using namespace Utils::Layouting; + const Break br; + const Space empty; + + Form { + m_usePredefinedStyle, m_predefinedStyle, br, + empty, Row { tr("Fallback style:"), m_fallbackStyle }, br, + useCustomizedStyle, m_configurations, br, + }.attachTo(options); + + Column { + Group { + Title(tr("Configuration")), + Form { + tr("Clang Format command:"), m_command, br, + tr("Restrict to MIME types:"), m_mime + } + }, + options, + Stretch() + }.attachTo(this); + + connect(m_command, &Utils::PathChooser::validChanged, options, &QWidget::setEnabled); + connect(m_predefinedStyle, &QComboBox::currentTextChanged, [this](const QString &item) { + m_fallbackStyle->setEnabled(item == "File"); + }); + connect(m_usePredefinedStyle, &QRadioButton::toggled, [this](bool checked) { + m_fallbackStyle->setEnabled(checked && m_predefinedStyle->currentText() == "File"); + m_predefinedStyle->setEnabled(checked); + }); } void ClangFormatOptionsPageWidget::apply() { - m_settings->setCommand(ui.command->filePath().toString()); - m_settings->setSupportedMimeTypes(ui.mime->text()); - m_settings->setUsePredefinedStyle(ui.usePredefinedStyle->isChecked()); - m_settings->setPredefinedStyle(ui.predefinedStyle->currentText()); - m_settings->setFallbackStyle(ui.fallbackStyle->currentText()); - m_settings->setCustomStyle(ui.configurations->currentConfiguration()); + m_settings->setCommand(m_command->filePath().toString()); + m_settings->setSupportedMimeTypes(m_mime->text()); + m_settings->setUsePredefinedStyle(m_usePredefinedStyle->isChecked()); + m_settings->setPredefinedStyle(m_predefinedStyle->currentText()); + m_settings->setFallbackStyle(m_fallbackStyle->currentText()); + m_settings->setCustomStyle(m_configurations->currentConfiguration()); m_settings->save(); // update since not all MIME types are accepted (invalids or duplicates) - ui.mime->setText(m_settings->supportedMimeTypesAsString()); + m_mime->setText(m_settings->supportedMimeTypesAsString()); } ClangFormatOptionsPage::ClangFormatOptionsPage(ClangFormatSettings *settings) @@ -109,5 +162,4 @@ ClangFormatOptionsPage::ClangFormatOptionsPage(ClangFormatSettings *settings) setWidgetCreator([settings] { return new ClangFormatOptionsPageWidget(settings); }); } -} // namespace Internal -} // namespace Beautifier +} // Beautifier::Internal diff --git a/src/plugins/beautifier/clangformat/clangformatoptionspage.h b/src/plugins/beautifier/clangformat/clangformatoptionspage.h index ac2621cbf29..ccc08801ae5 100644 --- a/src/plugins/beautifier/clangformat/clangformatoptionspage.h +++ b/src/plugins/beautifier/clangformat/clangformatoptionspage.h @@ -27,8 +27,7 @@ #include -namespace Beautifier { -namespace Internal { +namespace Beautifier::Internal { class ClangFormatSettings; @@ -38,5 +37,4 @@ public: explicit ClangFormatOptionsPage(ClangFormatSettings *settings); }; -} // namespace Internal -} // namespace Beautifier +} // Beautifier::Internal diff --git a/src/plugins/beautifier/clangformat/clangformatoptionspage.ui b/src/plugins/beautifier/clangformat/clangformatoptionspage.ui deleted file mode 100644 index 1cf89000a49..00000000000 --- a/src/plugins/beautifier/clangformat/clangformatoptionspage.ui +++ /dev/null @@ -1,141 +0,0 @@ - - - Beautifier::Internal::ClangFormatOptionsPage - - - - 0 - 0 - 727 - 631 - - - - - - - - - - Options - - - - - - Use customized style: - - - true - - - - - - - - - - - 0 - 0 - - - - Use predefined style: - - - true - - - true - - - - - - - - - - - 0 - 0 - - - - Fallback style: - - - - - - - false - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Configuration - - - - - - Clang Format command: - - - - - - - - - - Restrict to MIME types: - - - - - - - - - - - - - - Utils::PathChooser - QWidget -
utils/pathchooser.h
- 1 -
- - Beautifier::Internal::ConfigurationPanel - QWidget -
beautifier/configurationpanel.h
- 1 -
-
- - -