| 1 |
// Copyright 2007 "Gilles Degottex" |
| 2 |
|
| 3 |
// This file is part of "Music" |
| 4 |
|
| 5 |
// "Music" is free software; you can redistribute it and/or modify |
| 6 |
// it under the terms of the GNU Lesser General Public License as published by |
| 7 |
// the Free Software Foundation; either version 2.1 of the License, or |
| 8 |
// (at your option) any later version. |
| 9 |
// |
| 10 |
// "Music" is distributed in the hope that it will be useful, |
| 11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
// GNU Lesser General Public License for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU Lesser General Public License |
| 16 |
// along with this program; if not, write to the Free Software |
| 17 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 |
|
| 19 |
#include <iostream> |
| 20 |
using namespace std; |
| 21 |
#include <qsettings.h> |
| 22 |
#include "AutoQSettings.h" |
| 23 |
|
| 24 |
AutoQSettings::AutoQSettings(const QString& domain, const QString& product, const QString& setting_version) |
| 25 |
: QSettings(QSettings::UserScope, domain, product) |
| 26 |
{ |
| 27 |
beginGroup(QString("/")+product+setting_version+"/"); |
| 28 |
// cout << "INFO: AutoQSettings: " << fileName().toStdString() << endl; |
| 29 |
} |
| 30 |
|
| 31 |
void AutoQSettings::add(QCheckBox* el) |
| 32 |
{ |
| 33 |
assert(el->objectName()!=""); |
| 34 |
m_elements_checkbox.push_back(el); |
| 35 |
} |
| 36 |
void AutoQSettings::add(QSpinBox* el) |
| 37 |
{ |
| 38 |
assert(el->objectName()!=""); |
| 39 |
m_elements_spinbox.push_back(el); |
| 40 |
} |
| 41 |
void AutoQSettings::add(QLineEdit* el) |
| 42 |
{ |
| 43 |
assert(el->objectName()!=""); |
| 44 |
m_elements_lineedit.push_back(el); |
| 45 |
} |
| 46 |
void AutoQSettings::add(QComboBox* el) |
| 47 |
{ |
| 48 |
assert(el->objectName()!=""); |
| 49 |
m_elements_combobox.push_back(el); |
| 50 |
} |
| 51 |
void AutoQSettings::add(QGroupBox* el) |
| 52 |
{ |
| 53 |
assert(el->objectName()!=""); |
| 54 |
m_elements_qgroupbox.push_back(el); |
| 55 |
} |
| 56 |
void AutoQSettings::add(QRadioButton* el) |
| 57 |
{ |
| 58 |
assert(el->objectName()!=""); |
| 59 |
m_elements_qradiobutton.push_back(el); |
| 60 |
} |
| 61 |
|
| 62 |
void AutoQSettings::save(QCheckBox* el) |
| 63 |
{ |
| 64 |
setValue(el->objectName(), el->isChecked()); |
| 65 |
} |
| 66 |
void AutoQSettings::load(QCheckBox* el) |
| 67 |
{ |
| 68 |
el->setChecked(value(el->objectName(), el->isChecked()).toBool()); |
| 69 |
} |
| 70 |
|
| 71 |
void AutoQSettings::save() |
| 72 |
{ |
| 73 |
beginGroup("Auto/"); |
| 74 |
|
| 75 |
for(list<QCheckBox*>::iterator it=m_elements_checkbox.begin(); it!=m_elements_checkbox.end(); it++) |
| 76 |
setValue((*it)->objectName(), (*it)->isChecked()); |
| 77 |
|
| 78 |
for(list<QSpinBox*>::iterator it=m_elements_spinbox.begin(); it!=m_elements_spinbox.end(); it++) |
| 79 |
setValue((*it)->objectName(), (*it)->value()); |
| 80 |
|
| 81 |
for(list<QLineEdit*>::iterator it=m_elements_lineedit.begin(); it!=m_elements_lineedit.end(); it++) |
| 82 |
setValue((*it)->objectName(), (*it)->text()); |
| 83 |
|
| 84 |
for(list<QComboBox*>::iterator it=m_elements_combobox.begin(); it!=m_elements_combobox.end(); it++) |
| 85 |
setValue((*it)->objectName(), (*it)->currentIndex()); |
| 86 |
|
| 87 |
for(list<QGroupBox*>::iterator it=m_elements_qgroupbox.begin(); it!=m_elements_qgroupbox.end(); it++) |
| 88 |
setValue((*it)->objectName(), (*it)->isChecked()); |
| 89 |
|
| 90 |
for(list<QRadioButton*>::iterator it=m_elements_qradiobutton.begin(); it!=m_elements_qradiobutton.end(); it++) |
| 91 |
setValue((*it)->objectName(), (*it)->isChecked()); |
| 92 |
|
| 93 |
endGroup(); |
| 94 |
} |
| 95 |
void AutoQSettings::load() |
| 96 |
{ |
| 97 |
beginGroup("Auto/"); |
| 98 |
|
| 99 |
for(list<QCheckBox*>::iterator it=m_elements_checkbox.begin(); it!=m_elements_checkbox.end(); it++) |
| 100 |
(*it)->setChecked(value((*it)->objectName(), (*it)->isChecked()).toBool()); |
| 101 |
|
| 102 |
for(list<QSpinBox*>::iterator it=m_elements_spinbox.begin(); it!=m_elements_spinbox.end(); it++) |
| 103 |
(*it)->setValue(value((*it)->objectName(), (*it)->value()).toInt()); |
| 104 |
|
| 105 |
for(list<QLineEdit*>::iterator it=m_elements_lineedit.begin(); it!=m_elements_lineedit.end(); it++) |
| 106 |
(*it)->setText(value((*it)->objectName(), ((*it)->text())).toString()); |
| 107 |
|
| 108 |
for(list<QComboBox*>::iterator it=m_elements_combobox.begin(); it!=m_elements_combobox.end(); it++) |
| 109 |
(*it)->setCurrentIndex(value((*it)->objectName(), (*it)->currentIndex()).toInt()); |
| 110 |
|
| 111 |
for(list<QGroupBox*>::iterator it=m_elements_qgroupbox.begin(); it!=m_elements_qgroupbox.end(); it++) |
| 112 |
(*it)->setChecked(value((*it)->objectName(), (*it)->isChecked()).toBool()); |
| 113 |
|
| 114 |
for(list<QRadioButton*>::iterator it=m_elements_qradiobutton.begin(); it!=m_elements_qradiobutton.end(); it++) |
| 115 |
(*it)->setChecked(value((*it)->objectName(), (*it)->isChecked()).toBool()); |
| 116 |
|
| 117 |
endGroup(); |
| 118 |
} |
| 119 |
void AutoQSettings::clear() |
| 120 |
{ |
| 121 |
beginGroup("Auto/"); |
| 122 |
|
| 123 |
for(list<QCheckBox*>::iterator it=m_elements_checkbox.begin(); it!=m_elements_checkbox.end(); it++) |
| 124 |
remove((*it)->objectName()); |
| 125 |
|
| 126 |
for(list<QSpinBox*>::iterator it=m_elements_spinbox.begin(); it!=m_elements_spinbox.end(); it++) |
| 127 |
remove((*it)->objectName()); |
| 128 |
|
| 129 |
for(list<QLineEdit*>::iterator it=m_elements_lineedit.begin(); it!=m_elements_lineedit.end(); it++) |
| 130 |
remove((*it)->objectName()); |
| 131 |
|
| 132 |
for(list<QComboBox*>::iterator it=m_elements_combobox.begin(); it!=m_elements_combobox.end(); it++) |
| 133 |
remove((*it)->objectName()); |
| 134 |
|
| 135 |
for(list<QGroupBox*>::iterator it=m_elements_qgroupbox.begin(); it!=m_elements_qgroupbox.end(); it++) |
| 136 |
remove((*it)->objectName()); |
| 137 |
|
| 138 |
for(list<QRadioButton*>::iterator it=m_elements_qradiobutton.begin(); it!=m_elements_qradiobutton.end(); it++) |
| 139 |
remove((*it)->objectName()); |
| 140 |
|
| 141 |
endGroup(); |
| 142 |
} |