File: AutoQSettings.cpp

package info (click to toggle)
fmit 1.2.6-0.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 2,828 kB
  • sloc: cpp: 9,490; sh: 62; makefile: 15
file content (142 lines) | stat: -rw-r--r-- 5,104 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2007 "Gilles Degottex"

// This file is part of "Music"

// "Music" is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// "Music" is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#include <iostream>
using namespace std;
#include <qsettings.h>
#include "AutoQSettings.h"

AutoQSettings::AutoQSettings(const QString& domain, const QString& product, const QString& setting_version)
	: QSettings(QSettings::UserScope, domain, product)
{
	beginGroup(QString("/")+product+setting_version+"/");
//    cout << "INFO: AutoQSettings: " << fileName().toStdString() << endl;
}

void AutoQSettings::add(QCheckBox* el)
{
	assert(el->objectName()!="");
	m_elements_checkbox.push_back(el);
}
void AutoQSettings::add(QSpinBox* el)
{
	assert(el->objectName()!="");
	m_elements_spinbox.push_back(el);
}
void AutoQSettings::add(QLineEdit* el)
{
	assert(el->objectName()!="");
	m_elements_lineedit.push_back(el);
}
void AutoQSettings::add(QComboBox* el)
{
	assert(el->objectName()!="");
	m_elements_combobox.push_back(el);
}
void AutoQSettings::add(QGroupBox* el)
{
	assert(el->objectName()!="");
	m_elements_qgroupbox.push_back(el);
}
void AutoQSettings::add(QRadioButton* el)
{
	assert(el->objectName()!="");
	m_elements_qradiobutton.push_back(el);
}

void AutoQSettings::save(QCheckBox* el)
{
	setValue(el->objectName(), el->isChecked());
}
void AutoQSettings::load(QCheckBox* el)
{
	el->setChecked(value(el->objectName(), el->isChecked()).toBool());
}

void AutoQSettings::save()
{
	beginGroup("Auto/");

	for(list<QCheckBox*>::iterator it=m_elements_checkbox.begin(); it!=m_elements_checkbox.end(); it++)
		setValue((*it)->objectName(), (*it)->isChecked());

	for(list<QSpinBox*>::iterator it=m_elements_spinbox.begin(); it!=m_elements_spinbox.end(); it++)
		setValue((*it)->objectName(), (*it)->value());

	for(list<QLineEdit*>::iterator it=m_elements_lineedit.begin(); it!=m_elements_lineedit.end(); it++)
		setValue((*it)->objectName(), (*it)->text());

	for(list<QComboBox*>::iterator it=m_elements_combobox.begin(); it!=m_elements_combobox.end(); it++)
		setValue((*it)->objectName(), (*it)->currentIndex());

	for(list<QGroupBox*>::iterator it=m_elements_qgroupbox.begin(); it!=m_elements_qgroupbox.end(); it++)
		setValue((*it)->objectName(), (*it)->isChecked());

	for(list<QRadioButton*>::iterator it=m_elements_qradiobutton.begin(); it!=m_elements_qradiobutton.end(); it++)
		setValue((*it)->objectName(), (*it)->isChecked());

	endGroup();
}
void AutoQSettings::load()
{
	beginGroup("Auto/");

	for(list<QCheckBox*>::iterator it=m_elements_checkbox.begin(); it!=m_elements_checkbox.end(); it++)
		(*it)->setChecked(value((*it)->objectName(), (*it)->isChecked()).toBool());

	for(list<QSpinBox*>::iterator it=m_elements_spinbox.begin(); it!=m_elements_spinbox.end(); it++)
		(*it)->setValue(value((*it)->objectName(), (*it)->value()).toInt());

	for(list<QLineEdit*>::iterator it=m_elements_lineedit.begin(); it!=m_elements_lineedit.end(); it++)
		(*it)->setText(value((*it)->objectName(), ((*it)->text())).toString());

	for(list<QComboBox*>::iterator it=m_elements_combobox.begin(); it!=m_elements_combobox.end(); it++)
		(*it)->setCurrentIndex(value((*it)->objectName(), (*it)->currentIndex()).toInt());

	for(list<QGroupBox*>::iterator it=m_elements_qgroupbox.begin(); it!=m_elements_qgroupbox.end(); it++)
		(*it)->setChecked(value((*it)->objectName(), (*it)->isChecked()).toBool());

	for(list<QRadioButton*>::iterator it=m_elements_qradiobutton.begin(); it!=m_elements_qradiobutton.end(); it++)
		(*it)->setChecked(value((*it)->objectName(), (*it)->isChecked()).toBool());

	endGroup();
}
void AutoQSettings::clear()
{
	beginGroup("Auto/");

	for(list<QCheckBox*>::iterator it=m_elements_checkbox.begin(); it!=m_elements_checkbox.end(); it++)
		remove((*it)->objectName());

	for(list<QSpinBox*>::iterator it=m_elements_spinbox.begin(); it!=m_elements_spinbox.end(); it++)
		remove((*it)->objectName());

	for(list<QLineEdit*>::iterator it=m_elements_lineedit.begin(); it!=m_elements_lineedit.end(); it++)
		remove((*it)->objectName());

	for(list<QComboBox*>::iterator it=m_elements_combobox.begin(); it!=m_elements_combobox.end(); it++)
		remove((*it)->objectName());

    for(list<QGroupBox*>::iterator it=m_elements_qgroupbox.begin(); it!=m_elements_qgroupbox.end(); it++)
        remove((*it)->objectName());

    for(list<QRadioButton*>::iterator it=m_elements_qradiobutton.begin(); it!=m_elements_qradiobutton.end(); it++)
        remove((*it)->objectName());

    endGroup();
}