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>
|
2021-04-17 14:52:47 +08:00
|
|
|
#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>
|
|
|
|
|
|
|
|
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-04-17 14:52:47 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-17 14:52:47 +08:00
|
|
|
bool SettingsWidget::isSettingsChanged()
|
2021-04-16 22:04:48 +08:00
|
|
|
{
|
|
|
|
return mSettingsChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::setSettingsChanged()
|
|
|
|
{
|
|
|
|
mSettingsChanged = true;
|
2021-04-17 14:52:47 +08:00
|
|
|
emit settingsChanged(true);
|
2021-04-16 22:04:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::clearSettingsChanged()
|
|
|
|
{
|
|
|
|
mSettingsChanged = false;
|
2021-04-17 14:52:47 +08:00
|
|
|
emit settingsChanged(false);
|
2021-04-16 22:04:48 +08:00
|
|
|
}
|