2 ******************************************************************************
4 * @file dialgadgetoptionspage.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @see The GNU Public License (GPL) Version 3
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup DialPlugin Dial Plugin
11 * @brief Plots flight information rotary style dials
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "dialgadgetoptionspage.h"
30 #include "dialgadgetconfiguration.h"
31 #include "ui_dialgadgetoptionspage.h"
32 #include "extensionsystem/pluginmanager.h"
33 #include "uavobjectmanager.h"
34 #include "uavdataobject.h"
37 #include <QFileDialog>
38 #include <QtAlgorithms>
39 #include <QStringList>
41 DialGadgetOptionsPage::DialGadgetOptionsPage(DialGadgetConfiguration
*config
, QObject
*parent
) :
46 // creates options page widget (uses the UI file)
47 QWidget
*DialGadgetOptionsPage::createPage(QWidget
*parent
)
50 options_page
= new Ui::DialGadgetOptionsPage();
52 QWidget
*optionsPageWidget
= new QWidget
;
54 options_page
->setupUi(optionsPageWidget
);
56 // Fills the combo boxes for the UAVObjects
57 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
58 UAVObjectManager
*objManager
= pm
->getObject
<UAVObjectManager
>();
59 QList
< QList
<UAVDataObject
*> > objList
= objManager
->getDataObjects();
60 foreach(QList
<UAVDataObject
*> list
, objList
) {
61 foreach(UAVDataObject
* obj
, list
) {
62 options_page
->uavObject1
->addItem(obj
->getName());
63 options_page
->uavObject2
->addItem(obj
->getName());
64 options_page
->uavObject3
->addItem(obj
->getName());
68 // Fills the combo boxes for Needle movement options
69 options_page
->moveNeedle1
->addItem("Rotate");
70 options_page
->moveNeedle1
->addItem("Horizontal");
71 options_page
->moveNeedle1
->addItem("Vertical");
73 options_page
->moveNeedle2
->addItem("Rotate");
74 options_page
->moveNeedle2
->addItem("Horizontal");
75 options_page
->moveNeedle2
->addItem("Vertical");
77 options_page
->moveNeedle3
->addItem("Rotate");
78 options_page
->moveNeedle3
->addItem("Horizontal");
79 options_page
->moveNeedle3
->addItem("Vertical");
81 // Restore the contents from the settings:
83 options_page
->svgSourceFile
->setExpectedKind(Utils::PathChooser::File
);
84 options_page
->svgSourceFile
->setPromptDialogFilter(tr("SVG image (*.svg)"));
85 options_page
->svgSourceFile
->setPromptDialogTitle(tr("Choose SVG image"));
86 options_page
->svgSourceFile
->setPath(m_config
->dialFile());
87 options_page
->backgroundID
->setText(m_config
->dialBackground());
88 options_page
->foregroundID
->setText(m_config
->dialForeground());
89 options_page
->needle1ID
->setText(m_config
->dialNeedle1());
90 options_page
->needle2ID
->setText(m_config
->dialNeedle2());
91 options_page
->needle3ID
->setText(m_config
->dialNeedle3());
92 options_page
->needle1Min
->setValue(m_config
->getN1Min());
93 options_page
->needle1Max
->setValue(m_config
->getN1Max());
94 options_page
->needle2Min
->setValue(m_config
->getN2Min());
95 options_page
->needle2Max
->setValue(m_config
->getN2Max());
96 options_page
->needle3Min
->setValue(m_config
->getN3Min());
97 options_page
->needle3Max
->setValue(m_config
->getN3Max());
98 options_page
->factor1
->setValue(m_config
->getN1Factor());
99 options_page
->factor2
->setValue(m_config
->getN2Factor());
100 options_page
->factor3
->setValue(m_config
->getN3Factor());
101 options_page
->moveNeedle1
->setCurrentIndex(options_page
->moveNeedle1
->findText(m_config
->getN1Move()));
102 options_page
->moveNeedle2
->setCurrentIndex(options_page
->moveNeedle2
->findText(m_config
->getN2Move()));
103 options_page
->moveNeedle3
->setCurrentIndex(options_page
->moveNeedle3
->findText(m_config
->getN3Move()));
105 options_page
->useOpenGL
->setChecked(m_config
->useOpenGL());
106 options_page
->smoothUpdates
->setChecked(m_config
->getBeSmooth());
109 // select saved UAV Object field values
110 if (options_page
->uavObject1
->findText(m_config
->getN1DataObject()) != -1) {
111 options_page
->uavObject1
->setCurrentIndex(options_page
->uavObject1
->findText(m_config
->getN1DataObject()));
112 // Now load the object field values - 1st check that the object saved in the config still exists
113 UAVDataObject
*obj
= dynamic_cast<UAVDataObject
*>(objManager
->getObject(m_config
->getN1DataObject()));
115 on_uavObject1_currentIndexChanged(m_config
->getN1DataObject());
116 // And set the highlighed value from the settings:
117 options_page
->objectField1
->setCurrentIndex(options_page
->objectField1
->findText(m_config
->getN1ObjField()));
120 connect(options_page
->uavObject1
, SIGNAL(currentIndexChanged(QString
)), this, SLOT(on_uavObject1_currentIndexChanged(QString
)));
122 if (options_page
->uavObject2
->findText(m_config
->getN2DataObject()) != -1) {
123 options_page
->uavObject2
->setCurrentIndex(options_page
->uavObject2
->findText(m_config
->getN2DataObject()));
124 // Now load the object field values:
125 UAVDataObject
*obj
= dynamic_cast<UAVDataObject
*>(objManager
->getObject(m_config
->getN2DataObject()));
127 on_uavObject2_currentIndexChanged(m_config
->getN2DataObject());
128 options_page
->objectField2
->setCurrentIndex(options_page
->objectField2
->findText(m_config
->getN2ObjField()));
131 connect(options_page
->uavObject2
, SIGNAL(currentIndexChanged(QString
)), this, SLOT(on_uavObject2_currentIndexChanged(QString
)));
133 if (options_page
->uavObject3
->findText(m_config
->getN3DataObject()) != -1) {
134 options_page
->uavObject3
->setCurrentIndex(options_page
->uavObject3
->findText(m_config
->getN3DataObject()));
135 // Now load the object field values:
136 UAVDataObject
*obj
= dynamic_cast<UAVDataObject
*>(objManager
->getObject(m_config
->getN3DataObject()));
138 on_uavObject3_currentIndexChanged(m_config
->getN3DataObject());
139 options_page
->objectField3
->setCurrentIndex(options_page
->objectField3
->findText(m_config
->getN3ObjField()));
142 connect(options_page
->uavObject3
, SIGNAL(currentIndexChanged(QString
)), this, SLOT(on_uavObject3_currentIndexChanged(QString
)));
144 connect(options_page
->fontPicker
, SIGNAL(clicked()), this, SLOT(on_fontPicker_clicked()));
146 return optionsPageWidget
;
150 * Called when the user presses apply or OK.
152 * Saves the current values
155 void DialGadgetOptionsPage::apply()
157 m_config
->setDialFile(options_page
->svgSourceFile
->path());
158 m_config
->setDialBackgroundID(options_page
->backgroundID
->text());
159 m_config
->setDialForegroundID(options_page
->foregroundID
->text());
160 m_config
->setDialNeedleID1(options_page
->needle1ID
->text());
161 m_config
->setDialNeedleID2(options_page
->needle2ID
->text());
162 m_config
->setDialNeedleID3(options_page
->needle3ID
->text());
163 m_config
->setN1Min(options_page
->needle1Min
->value());
164 m_config
->setN1Max(options_page
->needle1Max
->value());
165 m_config
->setN1Factor(options_page
->factor1
->value());
166 m_config
->setN2Min(options_page
->needle2Min
->value());
167 m_config
->setN2Max(options_page
->needle2Max
->value());
168 m_config
->setN2Factor(options_page
->factor2
->value());
169 m_config
->setN3Min(options_page
->needle3Min
->value());
170 m_config
->setN3Max(options_page
->needle3Max
->value());
171 m_config
->setN3Factor(options_page
->factor3
->value());
172 m_config
->setN1DataObject(options_page
->uavObject1
->currentText());
173 m_config
->setN2DataObject(options_page
->uavObject2
->currentText());
174 m_config
->setN3DataObject(options_page
->uavObject3
->currentText());
175 m_config
->setN1ObjField(options_page
->objectField1
->currentText());
176 m_config
->setN2ObjField(options_page
->objectField2
->currentText());
177 m_config
->setN3ObjField(options_page
->objectField3
->currentText());
178 m_config
->setN1Move(options_page
->moveNeedle1
->currentText());
179 m_config
->setN2Move(options_page
->moveNeedle2
->currentText());
180 m_config
->setN3Move(options_page
->moveNeedle3
->currentText());
181 m_config
->setFont(font
.toString());
182 m_config
->setUseOpenGL(options_page
->useOpenGL
->checkState());
183 m_config
->setBeSmooth(options_page
->smoothUpdates
->checkState());
187 * Opens a font picker.
190 void DialGadgetOptionsPage::on_fontPicker_clicked()
194 font
= QFontDialog::getFont(&ok
, QFont("Arial", 12), qobject_cast
<QWidget
*>(this));
199 Fills in the field1 combo box when value is changed in the
202 void DialGadgetOptionsPage::on_uavObject1_currentIndexChanged(QString val
)
204 options_page
->objectField1
->clear();
205 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
206 UAVObjectManager
*objManager
= pm
->getObject
<UAVObjectManager
>();
207 UAVDataObject
*obj
= dynamic_cast<UAVDataObject
*>(objManager
->getObject(val
));
208 QList
<UAVObjectField
*> fieldList
= obj
->getFields();
209 foreach(UAVObjectField
* field
, fieldList
) {
210 if (field
->getType() == UAVObjectField::STRING
|| field
->getType() == UAVObjectField::ENUM
) {
213 if (field
->getElementNames().count() > 1) {
214 foreach(QString elemName
, field
->getElementNames()) {
215 options_page
->objectField1
->addItem(field
->getName() + "-" + elemName
);
218 options_page
->objectField1
->addItem(field
->getName());
224 Fills in the field2 combo box when value is changed in the
227 void DialGadgetOptionsPage::on_uavObject2_currentIndexChanged(QString val
)
229 options_page
->objectField2
->clear();
230 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
231 UAVObjectManager
*objManager
= pm
->getObject
<UAVObjectManager
>();
232 UAVDataObject
*obj
= dynamic_cast<UAVDataObject
*>(objManager
->getObject(val
));
233 QList
<UAVObjectField
*> fieldList
= obj
->getFields();
234 foreach(UAVObjectField
* field
, fieldList
) {
235 if (field
->getType() == UAVObjectField::STRING
|| field
->getType() == UAVObjectField::ENUM
) {
238 if (field
->getElementNames().count() > 1) {
239 foreach(QString elemName
, field
->getElementNames()) {
240 options_page
->objectField2
->addItem(field
->getName() + "-" + elemName
);
243 options_page
->objectField2
->addItem(field
->getName());
249 Fills in the field3 combo box when value is changed in the
252 void DialGadgetOptionsPage::on_uavObject3_currentIndexChanged(QString val
)
254 options_page
->objectField3
->clear();
255 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
256 UAVObjectManager
*objManager
= pm
->getObject
<UAVObjectManager
>();
257 UAVDataObject
*obj
= dynamic_cast<UAVDataObject
*>(objManager
->getObject(val
));
258 QList
<UAVObjectField
*> fieldList
= obj
->getFields();
259 foreach(UAVObjectField
* field
, fieldList
) {
260 if (field
->getType() == UAVObjectField::STRING
|| field
->getType() == UAVObjectField::ENUM
) {
263 if (field
->getElementNames().count() > 1) {
264 foreach(QString elemName
, field
->getElementNames()) {
265 options_page
->objectField3
->addItem(field
->getName() + "-" + elemName
);
268 options_page
->objectField3
->addItem(field
->getName());
274 void DialGadgetOptionsPage::finish()