dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
lineardialgadgetoptionspage.cpp
Go to the documentation of this file.
1 
13 /*
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.
18  *
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
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
30 #include "ui_lineardialgadgetoptionspage.h"
34 
35 #include <QFileDialog>
36 #include <QtAlgorithms>
37 #include <QStringList>
38 #include <QFontDialog>
39 
41  QObject *parent)
42  : IOptionsPage(parent)
43  , m_config(config)
44 {
45  font = QFont("Arial", 12); // Default in case nothing exists yet.
46 }
47 
48 // creates options page widget (uses the UI file)
49 QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
50 {
51 
52  Q_UNUSED(parent);
53  options_page = new Ui::LineardialGadgetOptionsPage();
54  // main widget
55  QWidget *optionsPageWidget = new QWidget;
56  // main layout
57  options_page->setupUi(optionsPageWidget);
58 
59  // Restore the contents from the settings:
60  options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
61  options_page->svgSourceFile->setPromptDialogFilter(tr("SVG image (*.svg)"));
62  options_page->svgSourceFile->setPromptDialogTitle(tr("Choose SVG image"));
63  options_page->svgSourceFile->setPath(m_config->getDialFile());
64  options_page->minValue->setValue(m_config->getMin());
65  options_page->maxValue->setValue(m_config->getMax());
66  // Do this by hand (in case value is zero, no signal would
67  // be sent!
68  on_rangeMin_valueChanged(m_config->getMin());
69  on_rangeMax_valueChanged(m_config->getMax());
70  options_page->greenMin->setValue(m_config->getGreenMin());
71  options_page->greenMax->setValue(m_config->getGreenMax());
72  options_page->yellowMin->setValue(m_config->getYellowMin());
73  options_page->yellowMax->setValue(m_config->getYellowMax());
74  options_page->redMin->setValue(m_config->getRedMin());
75  options_page->redMax->setValue(m_config->getRedMax());
76  options_page->factor->setValue(m_config->getFactor());
77  options_page->decPlaces->setValue(m_config->getDecimalPlaces());
78  font.fromString(m_config->getFont());
79 
80  // Fills the combo boxes for the UAVObjects
81  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
82  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
83  QVector<QVector<UAVDataObject *>> objList = objManager->getDataObjectsVector();
84  foreach (QVector<UAVDataObject *> list, objList) {
85  foreach (UAVDataObject *obj, list) {
86  options_page->objectName->addItem(obj->getName());
87  }
88  }
89  // select saved UAV Object field values
90  if (options_page->objectName->findText(m_config->getSourceDataObject()) != -1) {
91  options_page->objectName->setCurrentIndex(
92  options_page->objectName->findText(m_config->getSourceDataObject()));
93  // Now load the object field values:
94  UAVDataObject *obj =
95  dynamic_cast<UAVDataObject *>(objManager->getObject(m_config->getSourceDataObject()));
96  if (obj != NULL) {
97  on_objectName_currentIndexChanged(m_config->getSourceDataObject());
98  // And set the highlighed value from the settings:
99  options_page->objectField->setCurrentIndex(
100  options_page->objectField->findText(m_config->getSourceObjectField()));
101  }
102  }
103 
104  connect(options_page->objectName, SIGNAL(currentIndexChanged(QString)), this,
105  SLOT(on_objectName_currentIndexChanged(QString)));
106  connect(options_page->fontPicker, SIGNAL(clicked()), this, SLOT(on_fontPicker_clicked()));
107  connect(options_page->minValue, SIGNAL(valueChanged(double)), this,
108  SLOT(on_rangeMin_valueChanged(double)));
109  connect(options_page->maxValue, SIGNAL(valueChanged(double)), this,
110  SLOT(on_rangeMax_valueChanged(double)));
111 
112  return optionsPageWidget;
113 }
114 
119 void LineardialGadgetOptionsPage::on_rangeMin_valueChanged(double val)
120 {
121  options_page->maxValue->setMinimum(val);
122 
123  options_page->greenMin->setMinimum(val);
124  options_page->yellowMin->setMinimum(val);
125  options_page->redMin->setMinimum(val);
126 
127  options_page->greenMax->setMinimum(val);
128  options_page->yellowMax->setMinimum(val);
129  options_page->redMax->setMinimum(val);
130 }
131 
136 void LineardialGadgetOptionsPage::on_rangeMax_valueChanged(double val)
137 {
138  options_page->minValue->setMaximum(val);
139 
140  options_page->greenMax->setMaximum(val);
141  options_page->yellowMax->setMaximum(val);
142  options_page->redMax->setMaximum(val);
143 
144  options_page->greenMin->setMaximum(val);
145  options_page->yellowMin->setMaximum(val);
146  options_page->redMin->setMaximum(val);
147 }
148 
156 {
157  m_config->setDialFile(options_page->svgSourceFile->path());
158  double rangeMin = options_page->minValue->value();
159  double rangeMax = options_page->maxValue->value();
160  m_config->setRange(rangeMin, rangeMax);
161  m_config->setGreenRange(options_page->greenMin->value(), options_page->greenMax->value());
162  m_config->setYellowRange(options_page->yellowMin->value(), options_page->yellowMax->value());
163  m_config->setRedRange(options_page->redMin->value(), options_page->redMax->value());
164  m_config->setSourceDataObject(options_page->objectName->currentText());
165  m_config->setSourceObjField(options_page->objectField->currentText());
166  m_config->setFont(font.toString());
167  m_config->setDecimalPlaces(options_page->decPlaces->value());
168  m_config->setFactor(options_page->factor->value());
169 }
170 
175 void LineardialGadgetOptionsPage::on_fontPicker_clicked()
176 {
177  bool ok;
178  font = QFontDialog::getFont(&ok, font, qobject_cast<QWidget *>(this));
179 }
180 
181 /*
182  Fills in the field1 combo box when value is changed in the
183  object1 field
184 */
185 void LineardialGadgetOptionsPage::on_objectName_currentIndexChanged(QString val)
186 {
187  options_page->objectField->clear();
188  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
189  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
190  UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(val));
191  QList<UAVObjectField *> fieldList = obj->getFields();
192  foreach (UAVObjectField *field, fieldList) {
193  if (field->getElementNames().count() > 1) {
194  foreach (QString elemName, field->getElementNames()) {
195  options_page->objectField->addItem(field->getName() + "-" + elemName);
196  }
197  } else
198  options_page->objectField->addItem(field->getName());
199  }
200 }
201 
203 {
204 }
void setRedRange(double min, double max)
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
QWidget * createPage(QWidget *parent)
void setYellowRange(double min, double max)
QString getName() const
void setGreenRange(double min, double max)
QStringList getElementNames() const
QString getName()
Definition: uavobject.cpp:131
LineardialGadgetOptionsPage(LineardialGadgetConfiguration *config, QObject *parent=nullptr)
void setRange(double min, double max)
UAVObject * getObject(const QString &name, quint32 instId=0)
QVector< QVector< UAVDataObject * > > getDataObjectsVector()