54 , allowWidgetUpdates(true)
57 , outOfLimitsStyle(
"background-color: rgb(255, 180, 0);")
60 pm = ExtensionSystem::PluginManager::instance();
64 connect(telMngr, SIGNAL(connected()),
this, SLOT(
onAutopilotConnect()), Qt::UniqueConnection);
66 Qt::UniqueConnection);
67 connect(telMngr, SIGNAL(connected()),
this, SIGNAL(
autoPilotConnected()), Qt::UniqueConnection);
69 Qt::UniqueConnection);
72 connect(importexportplugin, SIGNAL(importAboutToBegin()),
this, SLOT(
invalidateObjects()));
114 QWidget *widget, QString element,
double scale,
115 bool isLimited,
bool useUnits,
116 QList<int> *defaultReloadGroups, quint32 instID,
122 qWarning() <<
"Failed to get object" << objectName;
128 if (!fieldName.isEmpty() && !element.isEmpty()) {
129 const auto field = obj->
getField(QString(fieldName));
132 qWarning() <<
"Failed to get object field" << objectName << fieldName;
135 index = field->getElementIndex(element);
139 defaultReloadGroups, instID, oneWayBind);
143 int index,
double scale,
bool isLimited,
144 bool useUnits,
QList<int> *defaultReloadGroups,
145 quint32 instID,
bool oneWayBind)
147 if (
addShadowWidget(
object, field, widget, index, scale, isLimited, useUnits,
148 defaultReloadGroups, instID))
153 if (!
object.isEmpty()) {
154 obj = objManager->
getObject(QString(
object), instID);
156 objectUpdates.insert(obj,
true);
157 connect(obj, SIGNAL(objectUpdated(
UAVObject *)),
this, SLOT(objectUpdated(
UAVObject *)));
158 connect(obj, SIGNAL(objectUpdated(
UAVObject *)),
this,
162 connect(dobj, SIGNAL(presentOnHardwareChanged(
UAVDataObject *)),
this,
163 SLOT(doRefreshHiddenObjects(
UAVDataObject *)), Qt::UniqueConnection);
168 if (!field.isEmpty() && obj)
169 _field = obj->
getField(QString(field));
179 objOfInterest.append(ow);
185 if (smartsave && obj && !qobject_cast<QLabel *>(widget))
186 smartsave->
addObject(static_cast<UAVDataObject *>(obj));
189 if (defaultReloadGroups && obj) {
190 foreach (
int i, *defaultReloadGroups) {
191 if (this->defaultReloadGroups.contains(i)) {
192 this->defaultReloadGroups.value(i)->append(ow);
195 this->defaultReloadGroups.value(i)->append(ow);
201 if (defaultReloadGroups)
203 shadowsList.insert(widget, ow);
204 loadWidgetLimits(widget, _field, index, isLimited, useUnits, scale);
284 for (
int i = 0;
i < list.size();
i++)
286 return accum / list.size();
296 double mean_accum = 0;
297 double var_accum = 0;
300 for (
int i = 0;
i < list.size();
i++)
301 mean_accum += list[
i];
302 mean = mean_accum / list.size();
304 for (
int i = 0;
i < list.size();
i++)
305 var_accum += (list[
i] - mean) * (list[
i] - mean);
308 return var_accum / (list.size() - 1);
357 bool dirtyBack = dirty;
373 if (!allowWidgetUpdates)
376 bool dirtyBack = dirty;
394 for (
const auto ow : objOfInterest) {
395 if (ow->object && ow->field && !ow->oneWayBind)
396 setFieldFromWidget(ow->widget, ow->field, ow->index, ow->scale, ow->useUnits);
405 QString url = helpButtonList.value(dynamic_cast<QPushButton *>(sender()), QString());
407 QDesktopServices::openUrl(QUrl(url, QUrl::StrictMode));
415 void ConfigTaskWidget::addApplySaveButtons(QPushButton *update, QPushButton *
save)
420 connect(smartsave, SIGNAL(saveSuccessfull()),
this, SLOT(
clearDirty()));
424 foreach (objectToWidget *oTw, objOfInterest) {
425 if (oTw->object && !qobject_cast<QLabel *>(oTw->widget)) {
426 smartsave->
addObject(static_cast<UAVDataObject *>(oTw->object));
453 for (QPushButton *button : reloadButtonList)
454 setWidgetEnabledByObj(button, enable);
455 for (QPushButton *button : rebootButtonList)
456 setWidgetEnabledByObj(button, enable);
457 for (QPushButton *button : connectionsButtonList)
458 setWidgetEnabledByObj(button, enable);
484 objectToWidget *oTw = shadowsList.value(dynamic_cast<QWidget *>(sender()), NULL);
486 if (oTw->
widget == dynamic_cast<QWidget *>(sender())) {
494 if (sh->
widget == static_cast<QWidget *>(sender())) {
503 if (oTw->
widget != static_cast<QWidget *>(sender())) {
515 if (sh->
widget != static_cast<QWidget *>(sender())) {
569 allowWidgetUpdates =
false;
581 allowWidgetUpdates =
true;
592 void ConfigTaskWidget::objectUpdated(
UAVObject *obj)
594 objectUpdates[obj] =
true;
603 foreach (
UAVObject *obj, objectUpdates.keys()) {
604 ret = ret & objectUpdates[obj];
615 helpButtonList.insert(button, url);
623 foreach (
UAVObject *obj, objectUpdates.keys()) {
624 objectUpdates[obj] =
false;
653 double scale,
bool isLimited,
bool useUnits,
654 QList<int> *defaultReloadGroups, quint32 instID)
664 if (qobject_cast<QLabel *>(oTw->
widget) && !qobject_cast<QLabel *>(widget)) {
676 else if (!qobject_cast<QDoubleSpinBox *>(oTw->
widget)
677 && qobject_cast<QDoubleSpinBox *>(widget)) {
694 shadowsList.insert(widget, oTw);
697 if (defaultReloadGroups)
699 loadWidgetLimits(widget, oTw->
field, oTw->
index, isLimited, useUnits, scale);
702 connect(dobj, SIGNAL(presentOnHardwareChanged(
UAVDataObject *)),
this,
703 SLOT(doRefreshHiddenObjects(
UAVDataObject *)), Qt::UniqueConnection);
718 QPushButton *saveButtonWidget = NULL;
719 QPushButton *applyButtonWidget = NULL;
720 foreach (QWidget *widget, this->findChildren<QWidget *>()) {
721 QVariant info = widget->property(
"objrelation");
722 if (info.isValid()) {
725 uiRelation.
scale = 1;
727 uiRelation.
element = QString();
731 foreach (QString str, info.toStringList()) {
732 QString prop = str.split(
":").at(0);
733 QString value = str.split(
":").at(1);
734 if (prop ==
"objname") {
736 }
else if (prop ==
"fieldname") {
738 }
else if (prop ==
"element") {
740 }
else if (prop ==
"scale") {
742 uiRelation.
scale = 1;
744 uiRelation.
scale = value.toDouble();
745 }
else if (prop ==
"haslimits") {
750 }
else if (prop ==
"button") {
753 else if (value ==
"apply")
755 else if (value ==
"reload")
757 else if (value ==
"default")
759 else if (value ==
"help")
761 else if (value ==
"reboot")
763 else if (value ==
"connectiondiagram")
765 }
else if (prop ==
"buttongroup") {
766 foreach (QString
s, value.split(
","))
768 }
else if (prop ==
"url") {
769 uiRelation.
url = str.mid(str.indexOf(
":") + 1);
770 }
else if (prop ==
"checkedoption") {
771 widget->setProperty(
"checkedOption", value);
772 }
else if (prop ==
"uncheckedoption") {
773 widget->setProperty(
"unCheckedOption", value);
774 }
else if (prop ==
"useunits") {
775 uiRelation.
useUnits = value ==
"yes";
776 }
else if (prop ==
"onewaybind") {
778 }
else if (prop ==
"instance") {
784 QPushButton *button = NULL;
787 saveButtonWidget = qobject_cast<QPushButton *>(widget);
788 if (saveButtonWidget)
789 addApplySaveButtons(NULL, saveButtonWidget);
792 applyButtonWidget = qobject_cast<QPushButton *>(widget);
793 if (applyButtonWidget)
794 addApplySaveButtons(applyButtonWidget, NULL);
797 button = qobject_cast<QPushButton *>(widget);
800 qWarning() <<
"[autoLoadWidgets] No button group specified for default "
804 addDefaultButton(button, uiRelation.
buttonGroup.at(0));
808 button = qobject_cast<QPushButton *>(widget);
812 <<
"[autoLoadWidgets] No button group specified for reload button!";
815 addReloadButton(button, uiRelation.
buttonGroup.at(0));
819 button = qobject_cast<QPushButton *>(widget);
824 button = qobject_cast<QPushButton *>(widget);
826 addRebootButton(button);
829 button = qobject_cast<QPushButton *>(widget);
837 QWidget *wid = qobject_cast<QWidget *>(widget);
862 if (oTw->
widget == widget)
871 foreach (
int i, *groups) {
872 if (defaultReloadGroups.contains(i)) {
873 defaultReloadGroups.value(i)->append(oTw);
876 defaultReloadGroups.value(i)->append(oTw);
887 void ConfigTaskWidget::addDefaultButton(QPushButton *button,
int buttonGroup)
889 button->setProperty(
"group", buttonGroup);
890 connect(button, SIGNAL(clicked()),
this, SLOT(defaultButtonClicked()));
897 void ConfigTaskWidget::addReloadButton(QPushButton *button,
int buttonGroup)
899 button->setProperty(
"group", buttonGroup);
900 reloadButtonList.append(button);
901 connect(button, SIGNAL(clicked()),
this, SLOT(reloadButtonClicked()));
908 void ConfigTaskWidget::addRebootButton(QPushButton *button)
910 rebootButtonList.append(button);
911 connect(button, SIGNAL(clicked()),
this, SLOT(rebootButtonClicked()));
916 connectionsButtonList.append(button);
917 connect(button, SIGNAL(clicked()),
this, SLOT(connectionsButtonClicked()));
923 void ConfigTaskWidget::defaultButtonClicked()
925 int group = sender()->property(
"group").toInt();
928 foreach (objectToWidget *oTw, *list) {
929 if (oTw->object && oTw->field) {
931 setWidgetFromField(oTw->widget, temp->
getField(oTw->field->getName()), oTw->index,
932 oTw->scale, oTw->isLimited, oTw->useUnits);
940 void ConfigTaskWidget::rebootButtonClicked()
942 QPointer<QPushButton> button(qobject_cast<QPushButton *>(sender()));
944 qWarning() <<
"Invalid button";
948 setWidgetEnabledByObj(button,
false);
949 button->setIcon(QIcon(
":/uploader/images/system-run.svg"));
951 FirmwareIAPObj *iapObj =
955 if (!conMngr->
isConnected() || !iapObj->getIsPresentOnHardware()) {
956 setWidgetEnabledByObj(button,
true);
957 button->setIcon(QIcon(
":/uploader/images/error.svg"));
963 timeout.setSingleShot(
true);
964 iapObj->setBoardRevision(0);
965 iapObj->setBoardType(0);
966 connect(&timeout, &QTimer::timeout, &loop, &QEventLoop::quit);
973 quint16 magicValue = 1122;
974 quint16 magicStep = 1111;
975 for (
int i = 0;
i < 3; ++
i) {
980 iapObj->setCommand(magicValue);
981 magicValue += magicStep;
983 if (magicValue == 3344)
991 if (!timeout.isActive() && button) {
992 setWidgetEnabledByObj(button,
true);
993 button->setIcon(QIcon(
":/uploader/images/error.svg"));
1000 setWidgetEnabledByObj(button,
true);
1001 button->setIcon(QIcon(
":/uploader/images/dialog-apply.svg"));
1011 void ConfigTaskWidget::reloadButtonClicked()
1015 int group = sender()->property(
"group").toInt();
1019 ObjectPersistence *objper =
1021 timeOut =
new QTimer(
this);
1022 QEventLoop *eventLoop =
new QEventLoop(
this);
1023 connect(timeOut, SIGNAL(timeout()), eventLoop, SLOT(quit()));
1024 connect(objper, SIGNAL(objectUpdated(
UAVObject *)), eventLoop, SLOT(quit()));
1027 foreach (objectToWidget *oTw, *list) {
1028 if (oTw->object != NULL) {
1034 value.objid = oTw->object->
getObjID();
1035 value.objinstid = oTw->object->getInstID();
1036 if (temp.contains(value))
1040 ObjectPersistence::DataFields
data;
1041 data.Operation = ObjectPersistence::OPERATION_LOAD;
1042 data.ObjectID = oTw->object->getObjID();
1043 data.InstanceID = oTw->object->getInstID();
1044 objper->setData(data);
1046 timeOut->start(500);
1048 if (timeOut->isActive()) {
1049 oTw->object->requestUpdate();
1051 setWidgetFromField(oTw->widget, oTw->field, oTw->index, oTw->scale,
1052 oTw->isLimited, oTw->useUnits);
1067 void ConfigTaskWidget::connectionsButtonClicked()
1073 void ConfigTaskWidget::doRefreshHiddenObjects(
UAVDataObject *obj)
1075 foreach (objectToWidget *ow, shadowsList.values()) {
1076 if (ow->object == NULL || ow->widget == NULL) {
1079 if (ow->object == obj) {
1080 foreach (QWidget *w, shadowsList.keys(ow))
1090 void ConfigTaskWidget::connectWidgetUpdatesToSlot(QWidget *widget,
const char *
function)
1094 if (QComboBox *cb = qobject_cast<QComboBox *>(widget)) {
1095 connect(cb, SIGNAL(currentIndexChanged(
int)),
this,
function);
1096 }
else if (QSlider *cb = qobject_cast<QSlider *>(widget)) {
1097 connect(cb, SIGNAL(valueChanged(
int)),
this,
function);
1098 }
else if (
MixerCurveWidget *cb = qobject_cast<MixerCurveWidget *>(widget)) {
1099 connect(cb, SIGNAL(curveUpdated()),
this,
function);
1100 }
else if (QTableWidget *cb = qobject_cast<QTableWidget *>(widget)) {
1101 connect(cb, SIGNAL(cellChanged(
int,
int)),
this,
function);
1102 }
else if (QSpinBox *cb = qobject_cast<QSpinBox *>(widget)) {
1103 connect(cb, SIGNAL(valueChanged(
int)),
this,
function);
1104 }
else if (
LongLongSpinBox *cb = qobject_cast<LongLongSpinBox *>(widget)) {
1105 connect(cb, SIGNAL(valueChanged(qint64)),
this,
function);
1106 }
else if (QDoubleSpinBox *cb = qobject_cast<QDoubleSpinBox *>(widget)) {
1107 connect(cb, SIGNAL(valueChanged(
double)),
this,
function);
1108 }
else if (QGroupBox *cb = qobject_cast<QGroupBox *>(widget)) {
1109 connect(cb, SIGNAL(toggled(
bool)),
this,
function);
1110 }
else if (QCheckBox *cb = qobject_cast<QCheckBox *>(widget)) {
1111 connect(cb, SIGNAL(stateChanged(
int)),
this,
function);
1112 }
else if (QPushButton *cb = qobject_cast<QPushButton *>(widget)) {
1113 connect(cb, SIGNAL(clicked()),
this,
function);
1114 }
else if (qobject_cast<QLabel *>(widget)) {
1115 }
else if (qobject_cast<QLineEdit *>(widget)) {
1117 qDebug() << __FUNCTION__ <<
"widget to uavobject relation not implemented for widget: "
1118 << widget->objectName() <<
"of class:" << widget->metaObject()->className();
1123 void ConfigTaskWidget::disconnectWidgetUpdatesToSlot(QWidget *widget,
const char *
function)
1127 if (QComboBox *cb = qobject_cast<QComboBox *>(widget)) {
1128 disconnect(cb, SIGNAL(currentIndexChanged(
int)),
this,
function);
1129 }
else if (QSlider *cb = qobject_cast<QSlider *>(widget)) {
1130 disconnect(cb, SIGNAL(valueChanged(
int)),
this,
function);
1131 }
else if (
MixerCurveWidget *cb = qobject_cast<MixerCurveWidget *>(widget)) {
1132 disconnect(cb, SIGNAL(curveUpdated()),
this,
function);
1133 }
else if (QTableWidget *cb = qobject_cast<QTableWidget *>(widget)) {
1134 disconnect(cb, SIGNAL(cellChanged(
int,
int)),
this,
function);
1135 }
else if (QSpinBox *cb = qobject_cast<QSpinBox *>(widget)) {
1136 disconnect(cb, SIGNAL(valueChanged(
int)),
this,
function);
1137 }
else if (
LongLongSpinBox *cb = qobject_cast<LongLongSpinBox *>(widget)) {
1138 disconnect(cb, SIGNAL(valueChanged(qint64)),
this,
function);
1139 }
else if (QDoubleSpinBox *cb = qobject_cast<QDoubleSpinBox *>(widget)) {
1140 disconnect(cb, SIGNAL(valueChanged(
double)),
this,
function);
1141 }
else if (QGroupBox *cb = qobject_cast<QGroupBox *>(widget)) {
1142 disconnect(cb, SIGNAL(toggled(
bool)),
this,
function);
1143 }
else if (QCheckBox *cb = qobject_cast<QCheckBox *>(widget)) {
1144 disconnect(cb, SIGNAL(stateChanged(
int)),
this,
function);
1145 }
else if (QPushButton *cb = qobject_cast<QPushButton *>(widget)) {
1146 disconnect(cb, SIGNAL(clicked()),
this,
function);
1147 }
else if (qobject_cast<QLabel *>(widget)) {
1148 }
else if (qobject_cast<QLineEdit *>(widget)) {
1150 qDebug() << __FUNCTION__ <<
"widget to uavobject relation not implemented for widget: "
1151 << widget->objectName() <<
"of class:" << widget->metaObject()->className();
1154 bool ConfigTaskWidget::widgetReadOnly(QWidget *widget)
const
1156 if (qobject_cast<QLabel *>(widget))
1158 if (
auto le = qobject_cast<QLineEdit *>(widget))
1159 return le->isReadOnly();
1171 bool ConfigTaskWidget::setFieldFromWidget(QWidget *widget,
UAVObjectField *field,
int index,
1172 double scale,
bool usesUnits)
1174 if (!widget || !field || widgetReadOnly(widget))
1178 if (ret.isValid()) {
1182 qDebug() << __FUNCTION__ <<
"widget to uavobject relation not implemented for widget: "
1183 << widget->objectName() <<
"of class:" << widget->metaObject()->className();
1196 if (QComboBox *comboBox = qobject_cast<QComboBox *>(widget)) {
1197 return comboBox->currentData();
1198 }
else if (QDoubleSpinBox *dblSpinBox = qobject_cast<QDoubleSpinBox *>(widget)) {
1199 return (
double)(dblSpinBox->value() * scale);
1200 }
else if (QSpinBox *spinBox = qobject_cast<QSpinBox *>(widget)) {
1201 return (
double)(spinBox->value() * scale);
1202 }
else if (
LongLongSpinBox *spinBox = qobject_cast<LongLongSpinBox *>(widget)) {
1203 return QVariant(spinBox->value() * scale);
1204 }
else if (QSlider *slider = qobject_cast<QSlider *>(widget)) {
1205 return (
double)(slider->value() * scale);
1206 }
else if (QGroupBox *groupBox = qobject_cast<QGroupBox *>(widget)) {
1208 }
else if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(widget)) {
1210 }
else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget)) {
1212 QStringList bits = lineEdit->displayText().split(
' ');
1215 return bits.join(
"");
1217 return lineEdit->displayText();
1234 units = units.trimmed();
1235 if (!units.startsWith(
"%")) {
1236 if (!units.isEmpty() && !qFuzzyCompare(1 + 1.0, 1 + scale) && scale != 0)
1237 units = applyScaleToUnits(units, scale);
1238 if (!units.isEmpty())
1244 units = QString(
"%");
1247 if (QComboBox *comboBox = qobject_cast<QComboBox *>(widget)) {
1248 comboBox->setCurrentIndex(comboBox->findData(value.toString()));
1250 }
else if (QLabel *label = qobject_cast<QLabel *>(widget)) {
1251 if ((scale == 0) || (scale == 1))
1252 label->setText(value.toString() + units);
1254 label->setText(QString::number(value.toDouble() / scale,
'f', 1) + units);
1256 }
else if (QDoubleSpinBox *dblSpinBox = qobject_cast<QDoubleSpinBox *>(widget)) {
1257 dblSpinBox->setValue(value.toDouble() / scale);
1258 if (!units.isEmpty())
1259 dblSpinBox->setSuffix(units);
1261 }
else if (QSpinBox *spinBox = qobject_cast<QSpinBox *>(widget)) {
1262 spinBox->setValue(qRound(value.toDouble() / scale));
1263 if (!units.isEmpty())
1264 spinBox->setSuffix(units);
1266 }
else if (
LongLongSpinBox *spinBox = qobject_cast<LongLongSpinBox *>(widget)) {
1267 spinBox->setValue(qRound64(value.toDouble() / scale));
1268 if (!units.isEmpty())
1269 spinBox->setSuffix(units);
1271 }
else if (QSlider *slider = qobject_cast<QSlider *>(widget)) {
1272 slider->setValue(qRound(value.toDouble() / scale));
1274 }
else if (QGroupBox *groupBox = qobject_cast<QGroupBox *>(widget)) {
1277 }
else if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(widget)) {
1280 }
else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget)) {
1283 lineEdit->setText(value.toString() + units);
1285 lineEdit->setText(QString::number((value.toDouble() / scale)) + units);
1292 bool ConfigTaskWidget::setWidgetFromField(QWidget *widget,
UAVObjectField *field,
int index,
1293 double scale,
bool hasLimits,
bool useUnits)
1295 if (!widget || !field)
1299 if (!widget->toolTip().length()) {
1300 QString desc = field->
getDescription().trimmed().toHtmlEscaped();
1301 if (desc.length()) {
1303 desc.prepend(
"<span style='font-style: normal'>");
1304 desc.remove(
"@Ref", Qt::CaseInsensitive);
1305 desc.append(
"</span>");
1307 widget->setToolTip(desc);
1310 if (QComboBox *cb = qobject_cast<QComboBox *>(widget)) {
1311 if (cb->count() == 0)
1312 loadWidgetLimits(cb, field, index, hasLimits, useUnits, scale);
1315 QVariant var = field->
getValue(index);
1317 const QString units = useUnits ? field->
getUnits() :
"";
1321 qDebug() << __FUNCTION__ <<
"widget to uavobject relation not implemented for widget: "
1322 << widget->objectName() <<
"of class:" << widget->metaObject()->className();
1327 bool hasLimits,
bool useUnits, QVariant value,
1333 if (!widget->property(
"styleBackup").isValid())
1334 widget->setProperty(
"styleBackup", widget->styleSheet());
1335 widget->setStyleSheet(outOfLimitsStyle);
1336 widget->setProperty(
"wasOverLimits", (
bool)
true);
1337 if (!widget->property(
"toolTipBackup").isValid()) {
1338 QString tip = widget->toolTip();
1339 if (tip.length() && !tip.startsWith(
"<"))
1340 tip = tip.prepend(
"<p>").append(
"</p>");
1341 widget->setProperty(
"toolTipBackup", tip);
1343 widget->setToolTip(widget->property(
"toolTipBackup").toString()
1344 + tr(
"<p><strong>Warning:</strong> The value of this field exceeds the "
1345 "recommended limits! Please double-check before flying.</p>"));
1346 if (QComboBox *cb = qobject_cast<QComboBox *>(widget)) {
1347 if (cb->findData(value.toString()) == -1)
1348 cb->addItem(value.toString(), value);
1349 }
else if (QDoubleSpinBox *cb = qobject_cast<QDoubleSpinBox *>(widget)) {
1350 if ((
double)(value.toDouble() / scale) > cb->maximum()) {
1351 cb->setMaximum((
double)(value.toDouble() / scale));
1352 }
else if ((
double)(value.toDouble() / scale) < cb->minimum()) {
1353 cb->setMinimum((
double)(value.toDouble() / scale));
1356 }
else if (QSpinBox *cb = qobject_cast<QSpinBox *>(widget)) {
1357 if ((
int)qRound(value.toDouble() / scale) > cb->maximum()) {
1358 cb->setMaximum((
int)qRound(value.toDouble() / scale));
1359 }
else if ((
int)qRound(value.toDouble() / scale) < cb->minimum()) {
1360 cb->setMinimum((
int)qRound(value.toDouble() / scale));
1362 }
else if (
LongLongSpinBox *cb = qobject_cast<LongLongSpinBox *>(widget)) {
1363 if (qRound64(value.toDouble() / scale) > cb->maximum()) {
1364 cb->setMaximum(qRound64(value.toDouble() / scale));
1365 }
else if (qRound64(value.toDouble() / scale) < cb->minimum()) {
1366 cb->setMinimum(qRound64(value.toDouble() / scale));
1368 }
else if (QSlider *cb = qobject_cast<QSlider *>(widget)) {
1369 if ((
int)qRound(value.toDouble() / scale) > cb->maximum()) {
1370 cb->setMaximum((
int)qRound(value.toDouble() / scale));
1371 }
else if ((
int)qRound(value.toDouble() / scale) < cb->minimum()) {
1372 cb->setMinimum((
int)qRound(value.toDouble() / scale));
1376 }
else if (widget->property(
"wasOverLimits").isValid()) {
1377 if (widget->property(
"wasOverLimits").toBool()) {
1378 widget->setProperty(
"wasOverLimits", (
bool)
false);
1379 if (widget->property(
"styleBackup").isValid()) {
1380 QString style = widget->property(
"styleBackup").toString();
1381 widget->setStyleSheet(style);
1384 if (widget->property(
"toolTipBackup").isValid())
1385 widget->setToolTip(widget->property(
"toolTipBackup").toString());
1387 widget->setToolTip(
"");
1389 loadWidgetLimits(widget, field, index, hasLimits, useUnits, scale);
1394 void ConfigTaskWidget::loadWidgetLimits(QWidget *widget,
UAVObjectField *field,
int index,
1395 bool hasLimits,
bool useUnits,
double scale)
1397 if (!widget || !field)
1399 if (QComboBox *cb = qobject_cast<QComboBox *>(widget)) {
1402 foreach (QString str, option) {
1403 if (!hasLimits || field->
isWithinLimits(str, index, currentBoard)) {
1405 cb->addItem(str +
" " + field->
getUnits(), str);
1407 cb->addItem(str, str);
1413 else if (QDoubleSpinBox *cb = qobject_cast<QDoubleSpinBox *>(widget)) {
1415 cb->setMaximum((
double)(field->
getMaxLimit(index, currentBoard).toDouble() / scale));
1417 if (field->
getMinLimit(index, currentBoard).isValid()) {
1418 cb->setMinimum((
double)(field->
getMinLimit(index, currentBoard).toDouble() / scale));
1420 }
else if (QSpinBox *cb = qobject_cast<QSpinBox *>(widget)) {
1421 if (field->
getMaxLimit(index, currentBoard).isValid()) {
1422 cb->setMaximum((
int)qRound(field->
getMaxLimit(index, currentBoard).toDouble() / scale));
1424 if (field->
getMinLimit(index, currentBoard).isValid()) {
1425 cb->setMinimum((
int)qRound(field->
getMinLimit(index, currentBoard).toDouble() / scale));
1427 }
else if (
LongLongSpinBox *cb = qobject_cast<LongLongSpinBox *>(widget)) {
1428 if (field->
getMaxLimit(index, currentBoard).isValid()) {
1429 cb->setMaximum(qRound64(field->
getMaxLimit(index, currentBoard).toDouble() / scale));
1431 if (field->
getMinLimit(index, currentBoard).isValid()) {
1432 cb->setMinimum(qRound(field->
getMinLimit(index, currentBoard).toDouble() / scale));
1434 }
else if (QSlider *cb = qobject_cast<QSlider *>(widget)) {
1435 if (field->
getMaxLimit(index, currentBoard).isValid()) {
1436 cb->setMaximum((
int)qRound(field->
getMaxLimit(index, currentBoard).toDouble() / scale));
1438 if (field->
getMinLimit(index, currentBoard).isValid()) {
1439 cb->setMinimum((
int)(field->
getMinLimit(index, currentBoard).toDouble() / scale));
1447 foreach (QSpinBox *sp, findChildren<QSpinBox *>()) {
1448 sp->installEventFilter(
this);
1451 sp->installEventFilter(
this);
1453 foreach (QDoubleSpinBox *sp, findChildren<QDoubleSpinBox *>()) {
1454 sp->installEventFilter(
this);
1456 foreach (QSlider *sp, findChildren<QSlider *>()) {
1457 sp->installEventFilter(
this);
1459 foreach (QComboBox *sp, findChildren<QComboBox *>()) {
1460 sp->installEventFilter(
this);
1467 if (evt->type() == QEvent::Wheel
1468 && (qobject_cast<QAbstractSpinBox *>(obj) || qobject_cast<QComboBox *>(obj)
1469 || qobject_cast<QAbstractSlider *>(obj))) {
1473 return QWidget::eventFilter(obj, evt);
1485 return widget->property(
"checkedOption").isValid()
1486 ? widget->property(
"checkedOption").toString()
1489 return widget->property(
"unCheckedOption").isValid()
1490 ? widget->property(
"unCheckedOption").toString()
1502 if (widget->property(
"checkedOption").isValid())
1503 return option == widget->property(
"checkedOption").toString();
1504 if (widget->property(
"unCheckedOption").isValid())
1505 return option != widget->property(
"unCheckedOption").toString();
1506 return option ==
"TRUE";
1519 QString ConfigTaskWidget::applyScaleToUnits(QString units,
double scale)
1522 if (qFuzzyCompare(1, 1 + scale) || qFuzzyCompare(1.0, scale))
1525 int len = units.length();
1527 if (!len || len > 2)
1532 QChar p = units.at(0);
1535 else if (p ==
'u' || p == QString::fromLatin1(
"\xb5s"))
1547 units = units.at(1);
1550 if (qFuzzyCompare(1.0
e-9, scale))
1552 else if (qFuzzyCompare(1.0
e-6, scale))
1554 else if (qFuzzyCompare(1.0
e-3, scale))
1556 else if (qFuzzyCompare(1.0e3, scale))
1558 else if (qFuzzyCompare(1.0e6, scale))
1560 else if (qFuzzyCompare(1.0e9, scale))
1569 return QString::fromLatin1(
"\xb5") + units;
1597 widget->setProperty(prop, value);
1598 widget->style()->unpolish(widget);
1599 widget->style()->polish(widget);
1604 bool objDisabled =
false;
1605 objDisabled = widget->property(
"objDisabled").toBool();
1606 widget->setProperty(
"userDisabled", !enabled);
1607 widget->setEnabled(enabled && !objDisabled);
1610 void ConfigTaskWidget::setWidgetEnabledByObj(QWidget *widget,
bool enabled)
1612 bool userDisabled =
false;
1613 userDisabled = widget->property(
"userDisabled").toBool();
1614 widget->setProperty(
"objDisabled", !enabled);
1615 widget->setEnabled(enabled && !userDisabled);
QVariant getDefaultValue(int index=0) const
Get the default value (defined in the UAVO def) for the element.
Core plugin system that manages the plugins, their life cycle and their registered objects...
QVariant getValue(int index=0) const
UAVDataObject * dirtyClone()
virtual ConnectionManager * connectionManager() const =0
QString getDescription() const
QStringList getOptions() const
void saveObjectToFlash(UAVObject *obj)
UAVObjectUtilManager::saveObjectToSD Add a new object to save in the queue.
void setValue(const QVariant &data, int index=0)
void transactionCompleted(UAVObject *obj, bool success)
transactionCompleted. Triggered by a call to emitTransactionCompleted - done in telemetry.cpp whenever a transaction finishes.
static ICore * instance()
UAVObjectField * getField(const QString &name)
bool getIsPresentOnHardware() const
QVariant getMinLimit(int index, int board=0) const
QVariant getMaxLimit(int index, int board=0) const
bool isWithinLimits(QVariant var, int index, int board=0) const
UAVObject * getObject(const QString &name, quint32 instId=0)
save(matfile $(SAVEOBJECTSCODE))