dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
dialgadgetoptionspage.cpp
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 
29 #include "dialgadgetoptionspage.h"
31 #include "ui_dialgadgetoptionspage.h"
35 
36 #include <QtAlgorithms>
37 #include <QStringList>
38 
40  : IOptionsPage(parent)
41  , m_config(config)
42 {
43 }
44 
45 // creates options page widget (uses the UI file)
46 QWidget *DialGadgetOptionsPage::createPage(QWidget *parent)
47 {
48 
49  Q_UNUSED(parent);
50  options_page = new Ui::DialGadgetOptionsPage();
51  // main widget
52  QWidget *optionsPageWidget = new QWidget;
53  // main layout
54  options_page->setupUi(optionsPageWidget);
55 
56  // Fills the combo boxes for the UAVObjects
57  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
58  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
59  QVector<QVector<UAVDataObject *>> objList = objManager->getDataObjectsVector();
60  foreach (QVector<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());
65  }
66  }
67 
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");
72 
73  options_page->moveNeedle2->addItem("Rotate");
74  options_page->moveNeedle2->addItem("Horizontal");
75  options_page->moveNeedle2->addItem("Vertical");
76 
77  options_page->moveNeedle3->addItem("Rotate");
78  options_page->moveNeedle3->addItem("Horizontal");
79  options_page->moveNeedle3->addItem("Vertical");
80 
81  // Restore the contents from the settings:
82 
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(
102  options_page->moveNeedle1->findText(m_config->getN1Move()));
103  options_page->moveNeedle2->setCurrentIndex(
104  options_page->moveNeedle2->findText(m_config->getN2Move()));
105  options_page->moveNeedle3->setCurrentIndex(
106  options_page->moveNeedle3->findText(m_config->getN3Move()));
107 
108  options_page->smoothUpdates->setChecked(m_config->getBeSmooth());
109 
110  // select saved UAV Object field values
111  if (options_page->uavObject1->findText(m_config->getN1DataObject()) != -1) {
112  options_page->uavObject1->setCurrentIndex(
113  options_page->uavObject1->findText(m_config->getN1DataObject()));
114  // Now load the object field values - 1st check that the object saved in the config still
115  // exists
116  UAVDataObject *obj =
117  dynamic_cast<UAVDataObject *>(objManager->getObject(m_config->getN1DataObject()));
118  if (obj != NULL) {
119  uavoChanged(options_page->objectField1, m_config->getN1DataObject());
120  // And set the highlighed value from the settings:
121  options_page->objectField1->setCurrentIndex(
122  options_page->objectField1->findText(m_config->getN1ObjField()));
123  }
124  }
125  connect(options_page->uavObject1,
126  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
127  [this](const QString &val) { uavoChanged(options_page->objectField1, val); });
128 
129  if (options_page->uavObject2->findText(m_config->getN2DataObject()) != -1) {
130  options_page->uavObject2->setCurrentIndex(
131  options_page->uavObject2->findText(m_config->getN2DataObject()));
132  // Now load the object field values:
133  UAVDataObject *obj =
134  dynamic_cast<UAVDataObject *>(objManager->getObject(m_config->getN2DataObject()));
135  if (obj != NULL) {
136  uavoChanged(options_page->objectField2, m_config->getN2DataObject());
137  options_page->objectField2->setCurrentIndex(
138  options_page->objectField2->findText(m_config->getN2ObjField()));
139  }
140  }
141  connect(options_page->uavObject2,
142  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
143  [this](const QString &val) { uavoChanged(options_page->objectField2, val); });
144 
145  if (options_page->uavObject3->findText(m_config->getN3DataObject()) != -1) {
146  options_page->uavObject3->setCurrentIndex(
147  options_page->uavObject3->findText(m_config->getN3DataObject()));
148  // Now load the object field values:
149  UAVDataObject *obj =
150  dynamic_cast<UAVDataObject *>(objManager->getObject(m_config->getN3DataObject()));
151  if (obj != NULL) {
152  uavoChanged(options_page->objectField3, m_config->getN3DataObject());
153  options_page->objectField3->setCurrentIndex(
154  options_page->objectField3->findText(m_config->getN3ObjField()));
155  }
156  }
157  connect(options_page->uavObject3,
158  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
159  [this](const QString &val) { uavoChanged(options_page->objectField3, val); });
160 
161  connect(options_page->fontPicker, &QAbstractButton::clicked, this,
162  &DialGadgetOptionsPage::on_fontPicker_clicked);
163 
164  return optionsPageWidget;
165 }
166 
174 {
175  m_config->setDialFile(options_page->svgSourceFile->path());
176  m_config->setDialBackgroundID(options_page->backgroundID->text());
177  m_config->setDialForegroundID(options_page->foregroundID->text());
178  m_config->setDialNeedleID1(options_page->needle1ID->text());
179  m_config->setDialNeedleID2(options_page->needle2ID->text());
180  m_config->setDialNeedleID3(options_page->needle3ID->text());
181  m_config->setN1Min(options_page->needle1Min->value());
182  m_config->setN1Max(options_page->needle1Max->value());
183  m_config->setN1Factor(options_page->factor1->value());
184  m_config->setN2Min(options_page->needle2Min->value());
185  m_config->setN2Max(options_page->needle2Max->value());
186  m_config->setN2Factor(options_page->factor2->value());
187  m_config->setN3Min(options_page->needle3Min->value());
188  m_config->setN3Max(options_page->needle3Max->value());
189  m_config->setN3Factor(options_page->factor3->value());
190  m_config->setN1DataObject(options_page->uavObject1->currentText());
191  m_config->setN2DataObject(options_page->uavObject2->currentText());
192  m_config->setN3DataObject(options_page->uavObject3->currentText());
193  m_config->setN1ObjField(options_page->objectField1->currentText());
194  m_config->setN2ObjField(options_page->objectField2->currentText());
195  m_config->setN3ObjField(options_page->objectField3->currentText());
196  m_config->setN1Move(options_page->moveNeedle1->currentText());
197  m_config->setN2Move(options_page->moveNeedle2->currentText());
198  m_config->setN3Move(options_page->moveNeedle3->currentText());
199  m_config->setFont(font.toString());
200  m_config->setBeSmooth(options_page->smoothUpdates->checkState());
201 }
202 
207 void DialGadgetOptionsPage::on_fontPicker_clicked()
208 {
209  bool ok;
210  font = QFontDialog::getFont(&ok, QFont("Arial", 12), qobject_cast<QWidget *>(this));
211 }
212 
218 void DialGadgetOptionsPage::uavoChanged(QComboBox *widget, const QString &uavo)
219 {
220  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
221  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
222 
223  UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(uavo));
224  if (!obj) {
225  qWarning() << "Invalid object" << uavo;
226  return;
227  }
228 
229  widget->clear();
230  for (auto field : obj->getFields()) {
231  if (field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM)
232  continue;
233  if (field->getElementNames().count() > 1) {
234  for (const QString &elemName : field->getElementNames())
235  widget->addItem(field->getName() + "-" + elemName);
236  } else
237  widget->addItem(field->getName());
238  }
239 }
240 
242 {
243 }
void setDialBackgroundID(QString elementID)
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
void setDialForegroundID(QString elementID)
void setDialNeedleID3(QString elementID)
DialGadgetOptionsPage(DialGadgetConfiguration *config, QObject *parent=nullptr)
void setN2DataObject(QString text)
void setN3DataObject(QString text)
void setDialNeedleID2(QString elementID)
void setN2ObjField(QString text)
void setDialNeedleID1(QString elementID)
void setN3ObjField(QString text)
QString getName()
Definition: uavobject.cpp:131
QWidget * createPage(QWidget *parent)
void setN1ObjField(QString text)
UAVObject * getObject(const QString &name, quint32 instId=0)
void setDialFile(QString dialFile)
QVector< QVector< UAVDataObject * > > getDataObjectsVector()
void setN1DataObject(QString text)