RedPanda-CPP/RedPandaIDE/settingsdialog/settingswidget.cpp

128 lines
4.0 KiB
C++
Raw Normal View History

2021-04-16 22:04:48 +08:00
#include "settingswidget.h"
2021-04-17 22:38:46 +08:00
#include <QAbstractItemView>
2021-04-16 22:04:48 +08:00
#include <QCheckBox>
#include <QComboBox>
2021-04-16 22:04:48 +08:00
#include <QLineEdit>
2021-04-17 22:38:46 +08:00
#include <QListView>
2021-04-16 22:04:48 +08:00
#include <QPlainTextEdit>
2021-06-07 11:02:03 +08:00
#include <QSpinBox>
#include "../widgets/coloredit.h"
2021-04-16 22:04:48 +08:00
SettingsWidget::SettingsWidget(const QString &name, const QString &group, QWidget *parent):
QWidget(parent),
mName(name),
mGroup(group)
{
}
void SettingsWidget::init()
{
load();
2021-04-17 22:38:46 +08:00
connectInputs();
}
void SettingsWidget::load()
{
doLoad();
2021-04-18 11:25:40 +08:00
clearSettingsChanged();
2021-04-17 22:38:46 +08:00
}
void SettingsWidget::save()
{
doSave();
2021-04-18 11:25:40 +08:00
clearSettingsChanged();
}
void SettingsWidget::connectAbstractItemView(QAbstractItemView *pView)
{
connect(pView->model(),&QAbstractItemModel::rowsInserted,this,&SettingsWidget::setSettingsChanged);
connect(pView->model(),&QAbstractItemModel::rowsMoved,this,&SettingsWidget::setSettingsChanged);
connect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged);
connect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged);
connect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged);
}
void SettingsWidget::disconnectAbstractItemView(QAbstractItemView *pView)
{
disconnect(pView->model(),&QAbstractItemModel::rowsInserted,this,&SettingsWidget::setSettingsChanged);
disconnect(pView->model(),&QAbstractItemModel::rowsMoved,this,&SettingsWidget::setSettingsChanged);
disconnect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged);
disconnect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged);
disconnect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged);
2021-04-17 22:38:46 +08:00
}
void SettingsWidget::connectInputs()
{
2021-04-16 22:04:48 +08:00
for (QLineEdit* p:findChildren<QLineEdit*>()) {
connect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
}
for (QCheckBox* p:findChildren<QCheckBox*>()) {
connect(p, &QCheckBox::stateChanged, this, &SettingsWidget::setSettingsChanged);
}
for (QPlainTextEdit* p:findChildren<QPlainTextEdit*>()) {
connect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
}
2021-06-07 11:02:03 +08:00
for (QSpinBox* p:findChildren<QSpinBox*>()) {
connect(p, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsWidget::setSettingsChanged);
}
for (ColorEdit* p:findChildren<ColorEdit*>()) {
connect(p, &ColorEdit::colorChanged, this, &SettingsWidget::setSettingsChanged);
}
for (QComboBox* p: findChildren<QComboBox*>()) {
connect(p, QOverload<int>::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged);
}
2021-04-17 22:38:46 +08:00
for (QAbstractItemView* p: findChildren<QAbstractItemView*>()) {
2021-04-18 11:25:40 +08:00
connectAbstractItemView(p);
2021-04-17 22:38:46 +08:00
}
2021-04-16 22:04:48 +08:00
}
2021-04-18 11:25:40 +08:00
void SettingsWidget::disconnectInputs()
{
for (QLineEdit* p:findChildren<QLineEdit*>()) {
disconnect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
}
for (QCheckBox* p:findChildren<QCheckBox*>()) {
disconnect(p, &QCheckBox::stateChanged, this, &SettingsWidget::setSettingsChanged);
}
for (QPlainTextEdit* p:findChildren<QPlainTextEdit*>()) {
disconnect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
}
for (QComboBox* p: findChildren<QComboBox*>()) {
disconnect(p, QOverload<int>::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged);
}
for (QAbstractItemView* p: findChildren<QAbstractItemView*>()) {
disconnectAbstractItemView(p);
}
}
2021-04-16 22:04:48 +08:00
const QString &SettingsWidget::group()
{
return mGroup;
}
const QString &SettingsWidget::name()
{
return mName;
}
bool SettingsWidget::isSettingsChanged()
2021-04-16 22:04:48 +08:00
{
return mSettingsChanged;
}
void SettingsWidget::setSettingsChanged()
{
mSettingsChanged = true;
emit settingsChanged(true);
2021-04-16 22:04:48 +08:00
}
void SettingsWidget::clearSettingsChanged()
{
mSettingsChanged = false;
emit settingsChanged(false);
2021-04-16 22:04:48 +08:00
}