#include "settingswidget.h" #include #include #include #include #include #include #include #include #include "../widgets/coloredit.h" SettingsWidget::SettingsWidget(const QString &name, const QString &group, QWidget *parent): QWidget(parent), mName(name), mGroup(group) { } void SettingsWidget::init() { load(); connectInputs(); } void SettingsWidget::load() { doLoad(); clearSettingsChanged(); } void SettingsWidget::save() { doSave(); 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); } void SettingsWidget::connectInputs() { for (QLineEdit* p:findChildren()) { connect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged); } for (QCheckBox* p:findChildren()) { connect(p, &QCheckBox::toggled, this, &SettingsWidget::setSettingsChanged); } for (QRadioButton* p:findChildren()) { connect(p, &QRadioButton::toggled, this, &SettingsWidget::setSettingsChanged); } for (QPlainTextEdit* p:findChildren()) { connect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged); } for (QSpinBox* p:findChildren()) { connect(p, QOverload::of(&QSpinBox::valueChanged), this, &SettingsWidget::setSettingsChanged); } for (ColorEdit* p:findChildren()) { connect(p, &ColorEdit::colorChanged, this, &SettingsWidget::setSettingsChanged); } for (QComboBox* p: findChildren()) { connect(p, QOverload::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged); } for (QAbstractItemView* p: findChildren()) { connectAbstractItemView(p); } } void SettingsWidget::disconnectInputs() { for (QLineEdit* p:findChildren()) { disconnect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged); } for (QCheckBox* p:findChildren()) { disconnect(p, &QCheckBox::stateChanged, this, &SettingsWidget::setSettingsChanged); } for (QPlainTextEdit* p:findChildren()) { disconnect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged); } for (QComboBox* p: findChildren()) { disconnect(p, QOverload::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged); } for (QAbstractItemView* p: findChildren()) { disconnectAbstractItemView(p); } } const QString &SettingsWidget::group() { return mGroup; } const QString &SettingsWidget::name() { return mName; } bool SettingsWidget::isSettingsChanged() { return mSettingsChanged; } void SettingsWidget::setSettingsChanged() { mSettingsChanged = true; emit settingsChanged(true); } void SettingsWidget::clearSettingsChanged() { mSettingsChanged = false; emit settingsChanged(false); }