2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 #include "guisettingsviewer.h"
26 #include "guisettingstab.h"
28 // #include <iostream>
29 // using namespace std;
31 #include <QTextStream>
34 /* Here is how we we get QTextStreams that look like iostreams */
35 QTextStream
cin(stdin
, QIODevice::ReadOnly
);
36 QTextStream
cout(stdout
, QIODevice::WriteOnly
);
37 QTextStream
cerr(stderr
, QIODevice::WriteOnly
);
39 GuiSettingsViewer::GuiSettingsViewer(QSettings
* Set
,QWidget
*parent
) : QDialog(parent
)
42 organization
=Set
->organizationName();
43 application
= Set
->applicationName();
47 GuiSettingsViewer::GuiSettingsViewer(QString org
, QString app
,QWidget
*parent
) : QDialog(parent
)
51 settings
=new QSettings(org
,app
);
55 void GuiSettingsViewer::CreateViewer()
57 closeButton
= new QPushButton(tr("Close"));
58 saveButton
= new QPushButton(tr("Save"));
60 connect(closeButton
, SIGNAL(clicked()), this, SLOT(close()));
61 connect(saveButton
, SIGNAL(clicked()), this, SLOT(save()));
63 QHBoxLayout
*bottomLayout
= new QHBoxLayout
;
64 bottomLayout
->addStretch();
65 bottomLayout
->addWidget(saveButton
);
66 bottomLayout
->addWidget(closeButton
);
68 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
69 mainLayout
->addWidget(&tabWidget
);
70 mainLayout
->addLayout(bottomLayout
);
71 setLayout(mainLayout
);
73 setWindowTitle(tr("Settings Viewer"));
77 void GuiSettingsViewer::save()
79 for (int i
=0;i
<tabWidget
.count();i
++)
81 QString group
=tabWidget
.tabText(i
);
82 GuiSettingsTab
* ST
=(GuiSettingsTab
*)(tabWidget
.widget(i
));
87 if(group
!="General") settings
->beginGroup(group
);
89 N
=(ST
->spinbox_name
).size();
92 settings
->beginGroup("int");
93 key
=ST
->spinbox_name
[i
];
94 int value
=ST
->spinbox
[i
]->value();
95 settings
->setValue(key
,value
);
99 N
=(ST
->checkbox_name
).size();
102 settings
->beginGroup("bool");
103 key
=ST
->checkbox_name
[i
];
104 Qt::CheckState value
=ST
->checkbox
[i
]->checkState();
105 settings
->setValue(key
,value
);
106 settings
->endGroup();
109 N
=(ST
->lineedit_name
).size();
112 settings
->beginGroup("double");
113 key
=ST
->lineedit_name
[i
];
114 double value
=(ST
->lineedit
[i
]->text()).toDouble();
115 settings
->setValue(key
,value
);
116 settings
->endGroup();
119 if(group
!="General") settings
->endGroup();
126 void GuiSettingsViewer::open()
128 QDialog
dialog(this);
130 QLabel
*orgLabel
= new QLabel(tr("&Organization:"));
131 QLineEdit
*orgLineEdit
= new QLineEdit(organization
);
132 orgLabel
->setBuddy(orgLineEdit
);
134 QLabel
*appLabel
= new QLabel(tr("&Application:"));
135 QLineEdit
*appLineEdit
= new QLineEdit(application
);
136 appLabel
->setBuddy(appLineEdit
);
138 QPushButton
*okButton
= new QPushButton(tr("OK"));
139 okButton
->setDefault(true);
140 QPushButton
*cancelButton
= new QPushButton(tr("Cancel"));
142 connect(okButton
, SIGNAL(clicked()), &dialog
, SLOT(accept()));
143 connect(cancelButton
, SIGNAL(clicked()), &dialog
, SLOT(reject()));
145 QHBoxLayout
*buttonLayout
= new QHBoxLayout
;
146 buttonLayout
->addStretch();
147 buttonLayout
->addWidget(okButton
);
148 buttonLayout
->addWidget(cancelButton
);
150 QGridLayout
*gridLayout
= new QGridLayout
;
151 gridLayout
->addWidget(orgLabel
, 0, 0);
152 gridLayout
->addWidget(orgLineEdit
, 0, 1);
153 gridLayout
->addWidget(appLabel
, 1, 0);
154 gridLayout
->addWidget(appLineEdit
, 1, 1);
156 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
157 mainLayout
->addLayout(gridLayout
);
158 mainLayout
->addLayout(buttonLayout
);
159 dialog
.setLayout(mainLayout
);
161 dialog
.setWindowTitle(tr("Choose Settings"));
164 organization
= orgLineEdit
->text();
165 application
= appLineEdit
->text();
170 void GuiSettingsViewer::readSettings()
173 setWindowTitle(tr("Settings Viewer - %1 by %2").arg(application
).arg(organization
));
176 void GuiSettingsViewer::addChildSettings()
178 tabWidget
.clear(); //This only removes the tabs, but does not delete them!!! TODO: delete for real
180 tabWidget
.addTab(new GuiSettingsTab(organization
, application
, "General"), "General");
181 foreach (QString group
, settings
->childGroups()) {
182 if ((group
!= "int") && (group
!= "bool") && (group
!= "double")) {
183 tabWidget
.addTab(new GuiSettingsTab(organization
, application
, group
), group
);