Beautifier: inline generaloptionspage.ui

Change-Id: If989d3a636f7ad046c6a1efdb78a3c3c63e15756
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2022-07-22 15:22:58 +02:00
parent d4643a627b
commit 9d4a55b3ab
5 changed files with 67 additions and 201 deletions

View File

@@ -18,7 +18,7 @@ add_qtc_plugin(Beautifier
configurationdialog.cpp configurationdialog.h configurationdialog.ui
configurationeditor.cpp configurationeditor.h
configurationpanel.cpp configurationpanel.h
generaloptionspage.cpp generaloptionspage.h generaloptionspage.ui
generaloptionspage.cpp generaloptionspage.h
generalsettings.cpp generalsettings.h
uncrustify/uncrustify.cpp uncrustify/uncrustify.h
uncrustify/uncrustifyconstants.h

View File

@@ -27,7 +27,6 @@ QtcPlugin {
"configurationpanel.h",
"generaloptionspage.cpp",
"generaloptionspage.h",
"generaloptionspage.ui",
"generalsettings.cpp",
"generalsettings.h",
]

View File

@@ -24,13 +24,19 @@
****************************************************************************/
#include "generaloptionspage.h"
#include "ui_generaloptionspage.h"
#include "beautifierconstants.h"
#include "generalsettings.h"
namespace Beautifier {
namespace Internal {
#include <utils/layoutbuilder.h>
#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
namespace Beautifier::Internal {
class GeneralOptionsPageWidget : public Core::IOptionsPageWidget
{
@@ -42,29 +48,71 @@ public:
private:
void apply() final;
Ui::GeneralOptionsPage ui;
QCheckBox *m_autoFormat;
QComboBox *m_autoFormatTool;
QLineEdit *m_autoFormatMime;
QCheckBox *m_autoFormatOnlyCurrentProject;
};
GeneralOptionsPageWidget::GeneralOptionsPageWidget(const QStringList &toolIds)
{
ui.setupUi(this);
ui.autoFormatTool->addItems(toolIds);
resize(817, 631);
auto settings = GeneralSettings::instance();
ui.autoFormat->setChecked(settings->autoFormatOnSave());
const int index = ui.autoFormatTool->findText(settings->autoFormatTool());
ui.autoFormatTool->setCurrentIndex(qMax(index, 0));
ui.autoFormatMime->setText(settings->autoFormatMimeAsString());
ui.autoFormatOnlyCurrentProject->setChecked(settings->autoFormatOnlyCurrentProject());
m_autoFormat = new QCheckBox(tr("Enable auto format on file save"));
m_autoFormat->setChecked(settings->autoFormatOnSave());
auto toolLabel = new QLabel(tr("Tool:"));
toolLabel->setEnabled(false);
auto mimeLabel = new QLabel(tr("Restrict to MIME types:"));
mimeLabel->setEnabled(false);
m_autoFormatMime = new QLineEdit(settings->autoFormatMimeAsString());
m_autoFormatMime->setEnabled(false);
m_autoFormatOnlyCurrentProject =
new QCheckBox(tr("Restrict to files contained in the current project"));
m_autoFormatOnlyCurrentProject->setEnabled(false);
m_autoFormatOnlyCurrentProject->setChecked(settings->autoFormatOnlyCurrentProject());
m_autoFormatTool = new QComboBox;
m_autoFormatTool->setEnabled(false);
m_autoFormatTool->addItems(toolIds);
const int index = m_autoFormatTool->findText(settings->autoFormatTool());
m_autoFormatTool->setCurrentIndex(qMax(index, 0));
using namespace Utils::Layouting;
const Break br;
Column {
Group {
Title(tr("Automatic Formatting on File Save")),
Form {
Span(2, m_autoFormat), br,
toolLabel, m_autoFormatTool, br,
mimeLabel, m_autoFormatMime, br,
Span(2, m_autoFormatOnlyCurrentProject)
}
},
Stretch()
}.attachTo(this);
connect(m_autoFormat, &QCheckBox::toggled, m_autoFormatTool, &QComboBox::setEnabled);
connect(m_autoFormat, &QCheckBox::toggled, m_autoFormatMime, &QLineEdit::setEnabled);
connect(m_autoFormat, &QCheckBox::toggled, toolLabel, &QLabel::setEnabled);
connect(m_autoFormat, &QCheckBox::toggled, mimeLabel, &QLabel::setEnabled);
connect(m_autoFormat, &QCheckBox::toggled, m_autoFormatOnlyCurrentProject, &QCheckBox::setEnabled);
}
void GeneralOptionsPageWidget::apply()
{
auto settings = GeneralSettings::instance();
settings->setAutoFormatOnSave(ui.autoFormat->isChecked());
settings->setAutoFormatTool(ui.autoFormatTool->currentText());
settings->setAutoFormatMime(ui.autoFormatMime->text());
settings->setAutoFormatOnlyCurrentProject(ui.autoFormatOnlyCurrentProject->isChecked());
settings->setAutoFormatOnSave(m_autoFormat->isChecked());
settings->setAutoFormatTool(m_autoFormatTool->currentText());
settings->setAutoFormatMime(m_autoFormatMime->text());
settings->setAutoFormatOnlyCurrentProject(m_autoFormatOnlyCurrentProject->isChecked());
settings->save();
}
@@ -78,5 +126,4 @@ GeneralOptionsPage::GeneralOptionsPage(const QStringList &toolIds)
setCategoryIconPath(":/beautifier/images/settingscategory_beautifier.png");
}
} // namespace Internal
} // namespace Beautifier
} // Beautifier::Internal

View File

@@ -27,8 +27,7 @@
#include <coreplugin/dialogs/ioptionspage.h>
namespace Beautifier {
namespace Internal {
namespace Beautifier::Internal {
class GeneralOptionsPage final : public Core::IOptionsPage
{
@@ -36,5 +35,4 @@ public:
explicit GeneralOptionsPage(const QStringList &toolIds);
};
} // namespace Internal
} // namespace Beautifier
} // Beautifier::Internal

View File

@@ -1,178 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Beautifier::Internal::GeneralOptionsPage</class>
<widget class="QWidget" name="Beautifier::Internal::GeneralOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>817</width>
<height>631</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="formatOnSave">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Automatic Formatting on File Save</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="autoFormat">
<property name="text">
<string>Enable auto format on file save</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Tool:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="autoFormatTool">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Restrict to MIME types:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="autoFormatMime">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="autoFormatOnlyCurrentProject">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Restrict to files contained in the current project</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>autoFormat</sender>
<signal>toggled(bool)</signal>
<receiver>autoFormatTool</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>140</x>
<y>56</y>
</hint>
<hint type="destinationlabel">
<x>262</x>
<y>99</y>
</hint>
</hints>
</connection>
<connection>
<sender>autoFormat</sender>
<signal>toggled(bool)</signal>
<receiver>autoFormatMime</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>292</x>
<y>51</y>
</hint>
<hint type="destinationlabel">
<x>288</x>
<y>106</y>
</hint>
</hints>
</connection>
<connection>
<sender>autoFormat</sender>
<signal>toggled(bool)</signal>
<receiver>label</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>41</x>
<y>55</y>
</hint>
<hint type="destinationlabel">
<x>65</x>
<y>92</y>
</hint>
</hints>
</connection>
<connection>
<sender>autoFormat</sender>
<signal>toggled(bool)</signal>
<receiver>label_2</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>92</x>
<y>47</y>
</hint>
<hint type="destinationlabel">
<x>74</x>
<y>122</y>
</hint>
</hints>
</connection>
<connection>
<sender>autoFormat</sender>
<signal>toggled(bool)</signal>
<receiver>autoFormatOnlyCurrentProject</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>38</x>
<y>50</y>
</hint>
<hint type="destinationlabel">
<x>32</x>
<y>160</y>
</hint>
</hints>
</connection>
</connections>
</ui>