From c54da9269f9fddc18650528a8cecee742973090e Mon Sep 17 00:00:00 2001 From: Michael Carpenter Date: Thu, 11 Apr 2013 06:48:21 -0400 Subject: [PATCH] New ComboBox param configuration UI element, and qgw widgets for general APM configuration, battery and extra sensors --- .../general/widgets/ardupilot-heading-pid.qgw | 26 ++ .../general/widgets/battery_monitoring.qgw | 67 +++ .../general/widgets/extra_sensors.qgw | 59 +++ qgroundcontrol.pro | 10 +- src/ui/QGCVehicleConfig.cc | 27 +- src/ui/QGCVehicleConfig.ui | 326 ++++++++------ src/ui/designer/QGCComboBox.cc | 404 ++++++++++++++++++ src/ui/designer/QGCComboBox.h | 65 +++ src/ui/designer/QGCComboBox.ui | 292 +++++++++++++ src/ui/designer/QGCToolWidget.cc | 6 + 10 files changed, 1154 insertions(+), 128 deletions(-) create mode 100644 files/ardupilotmega/general/widgets/ardupilot-heading-pid.qgw create mode 100644 files/ardupilotmega/general/widgets/battery_monitoring.qgw create mode 100644 files/ardupilotmega/general/widgets/extra_sensors.qgw create mode 100644 src/ui/designer/QGCComboBox.cc create mode 100644 src/ui/designer/QGCComboBox.h create mode 100644 src/ui/designer/QGCComboBox.ui diff --git a/files/ardupilotmega/general/widgets/ardupilot-heading-pid.qgw b/files/ardupilotmega/general/widgets/ardupilot-heading-pid.qgw new file mode 100644 index 000000000..20a6d1c1f --- /dev/null +++ b/files/ardupilotmega/general/widgets/ardupilot-heading-pid.qgw @@ -0,0 +1,26 @@ +[Heading%20PID%20Tuning] +QGC_TOOL_WIDGET_ITEMS\1\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_DESCRIPTION=Heading D Gain +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_PARAMID=HDNG2RLL_D +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_COMPONENTID=200 +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_MAX=1 +QGC_TOOL_WIDGET_ITEMS\2\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_DESCRIPTION=Heading P Gain +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_PARAMID=HDNG2RLL_P +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_COMPONENTID=200 +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_MAX=5 +QGC_TOOL_WIDGET_ITEMS\3\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_DESCRIPTION=Heading I Gain +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_PARAMID=HDNG2RLL_I +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_COMPONENTID=200 +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_MAX=1 +QGC_TOOL_WIDGET_ITEMS\4\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_DESCRIPTION=Heading I Limit +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_PARAMID=HDNG2RLL_IMAX +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_COMPONENTID=200 +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_MAX=3000 +QGC_TOOL_WIDGET_ITEMS\size=4 diff --git a/files/ardupilotmega/general/widgets/battery_monitoring.qgw b/files/ardupilotmega/general/widgets/battery_monitoring.qgw new file mode 100644 index 000000000..0b5598c20 --- /dev/null +++ b/files/ardupilotmega/general/widgets/battery_monitoring.qgw @@ -0,0 +1,67 @@ +[Battery%20Monitor] +QGC_TOOL_WIDGET_ITEMS\1\TYPE=COMBO +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_DESCRIPTION=Battery Monitor +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_PARAMID=BATT_MONITOR +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_MIN=0 +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_MAX=4 + +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_COUNT=3 +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_ITEM_0_TEXT=Disabled +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_ITEM_0_VAL=0 + +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_ITEM_1_TEXT=Voltage Only +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_ITEM_1_VAL=3 + +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_ITEM_2_TEXT=Voltage And Current +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_COMBOBOX_ITEM_2_VAL=4 + +QGC_TOOL_WIDGET_ITEMS\4\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_DESCRIPTION=APM Input Voltage +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_PARAMID=INPUT_VOLTS +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_MAX=24 + +QGC_TOOL_WIDGET_ITEMS\2\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_DESCRIPTION=Sensor Type +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_PARAMID=CMB_batmon +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_MAX=4 + +QGC_TOOL_WIDGET_ITEMS\5\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_DESCRIPTION=Measured Volts +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_PARAMID=INPUT_VOLTS +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_MAX=24 + +QGC_TOOL_WIDGET_ITEMS\3\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_DESCRIPTION=APM Version +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_PARAMID=CMB_apmversion +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_MAX=2 + +QGC_TOOL_WIDGET_ITEMS\6\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_DESCRIPTION=Battery Capacity +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_PARAMID=BATT_CAPACITY +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_MAX=10000 + +QGC_TOOL_WIDGET_ITEMS\7\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_DESCRIPTION=Voltage Divider +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_PARAMID=VOLT_DIVIDER +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_MAX=10 + +QGC_TOOL_WIDGET_ITEMS\8\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_DESCRIPTION=Amps per Volt +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_PARAMID=AMP_PER_VOLT +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_MAX=100 +QGC_TOOL_WIDGET_ITEMS\size=8 diff --git a/files/ardupilotmega/general/widgets/extra_sensors.qgw b/files/ardupilotmega/general/widgets/extra_sensors.qgw new file mode 100644 index 000000000..f9ad353dc --- /dev/null +++ b/files/ardupilotmega/general/widgets/extra_sensors.qgw @@ -0,0 +1,59 @@ +[Extra%20Sensors] + +QGC_TOOL_WIDGET_ITEMS\1\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_DESCRIPTION=Compass Enable +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_PARAMID=MAG_ENABLE +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\1\QGC_PARAM_SLIDER_MAX=1 + +QGC_TOOL_WIDGET_ITEMS\2\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_DESCRIPTION=Auto Declination +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_PARAMID=COMPASS_AUTODEC +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\2\QGC_PARAM_SLIDER_MAX=1 + +QGC_TOOL_WIDGET_ITEMS\3\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_DESCRIPTION=Compass Declination +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_PARAMID=COMPASS_DEC +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\3\QGC_PARAM_SLIDER_MAX=100 + +QGC_TOOL_WIDGET_ITEMS\4\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_DESCRIPTION=Sonar Enable +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_PARAMID=SONAR_ENABLE +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\4\QGC_PARAM_SLIDER_MAX=1 + +QGC_TOOL_WIDGET_ITEMS\5\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_DESCRIPTION=Sonar Type +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_PARAMID=SONAR_TYPE +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\5\QGC_PARAM_SLIDER_MAX=5 + +QGC_TOOL_WIDGET_ITEMS\6\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_DESCRIPTION=Air Speed Enable +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_PARAMID=ARSPD_ENABLE +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\6\QGC_PARAM_SLIDER_MAX=2 + +QGC_TOOL_WIDGET_ITEMS\7\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_DESCRIPTION=Use Air Speed +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_PARAMID=ARSPD_USE +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\7\QGC_PARAM_SLIDER_MAX=1 + +QGC_TOOL_WIDGET_ITEMS\8\TYPE=SLIDER +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_DESCRIPTION=Optical Flow Enable +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_PARAMID=FLOW_ENABLE +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_COMPONENTID=1 +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_MIN=0 +QGC_TOOL_WIDGET_ITEMS\8\QGC_PARAM_SLIDER_MAX=1 + +QGC_TOOL_WIDGET_ITEMS\size=8 diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 3e80875e5..dac4449cd 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -227,7 +227,8 @@ FORMS += src/ui/MainWindow.ui \ src/ui/QGCHilConfiguration.ui \ src/ui/QGCHilFlightGearConfiguration.ui \ src/ui/QGCHilJSBSimConfiguration.ui \ - src/ui/QGCHilXPlaneConfiguration.ui + src/ui/QGCHilXPlaneConfiguration.ui \ + src/ui/designer/QGCComboBox.ui INCLUDEPATH += src \ src/ui \ src/ui/linechart \ @@ -370,7 +371,8 @@ HEADERS += src/MG.h \ src/ui/QGCHilConfiguration.h \ src/ui/QGCHilFlightGearConfiguration.h \ src/ui/QGCHilJSBSimConfiguration.h \ - src/ui/QGCHilXPlaneConfiguration.h + src/ui/QGCHilXPlaneConfiguration.h \ + src/ui/designer/QGCComboBox.h # Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010::HEADERS += src/ui/map3D/QGCGoogleEarthView.h @@ -532,7 +534,8 @@ SOURCES += src/main.cc \ src/ui/QGCHilConfiguration.cc \ src/ui/QGCHilFlightGearConfiguration.cc \ src/ui/QGCHilJSBSimConfiguration.cc \ - src/ui/QGCHilXPlaneConfiguration.cc + src/ui/QGCHilXPlaneConfiguration.cc \ + src/ui/designer/QGCComboBox.cc # Enable Google Earth only on Mac OS and Windows with Visual Studio compiler macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc @@ -666,3 +669,4 @@ win32-msvc2008|win32-msvc2010 { } unix:!macx:!symbian: LIBS += -losg +>>>>>>> New ComboBox param configuration UI element, and qgw widgets for general diff --git a/src/ui/QGCVehicleConfig.cc b/src/ui/QGCVehicleConfig.cc index 59013fc86..24a898718 100644 --- a/src/ui/QGCVehicleConfig.cc +++ b/src/ui/QGCVehicleConfig.cc @@ -205,7 +205,7 @@ void QGCVehicleConfig::setActiveUAS(UASInterface* active) qDebug() << autopilotdir.absolutePath(); qDebug() << generaldir.absolutePath(); qDebug() << vehicledir.absolutePath(); - + int left = true; foreach (QString file,generaldir.entryList(QDir::Files | QDir::NoDotAndDotDot)) { if (file.toLower().endsWith(".qgw")) { @@ -218,13 +218,22 @@ void QGCVehicleConfig::setActiveUAS(UASInterface* active) box->setTitle(tool->objectName()); box->setLayout(new QVBoxLayout()); box->layout()->addWidget(tool); - ui->multiRotorAttitudeLayout->addWidget(box); + if (left) + { + left = false; + ui->leftGeneralLayout->addWidget(box); + } + else + { + left = true; + ui->rightGeneralLayout->addWidget(box); + } } else { delete tool; } } } - + left = true; foreach (QString file,vehicledir.entryList(QDir::Files | QDir::NoDotAndDotDot)) { if (file.toLower().endsWith(".qgw")) { @@ -237,7 +246,17 @@ void QGCVehicleConfig::setActiveUAS(UASInterface* active) box->setTitle(tool->objectName()); box->setLayout(new QVBoxLayout()); box->layout()->addWidget(tool); - ui->fixedWingAttitudeLayout->addWidget(box); + if (left) + { + left = false; + ui->leftHWSpecificLayout->addWidget(box); + } + else + { + left = true; + ui->rightHWSpecificLayout->addWidget(box); + } + } else { delete tool; } diff --git a/src/ui/QGCVehicleConfig.ui b/src/ui/QGCVehicleConfig.ui index 08334459d..ffc5ea3d4 100644 --- a/src/ui/QGCVehicleConfig.ui +++ b/src/ui/QGCVehicleConfig.ui @@ -40,7 +40,7 @@ - 0 + 2 @@ -776,69 +776,111 @@ p, li { white-space: pre-wrap; } General Config - - - 20 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Load Platform Defaults - - - - - + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Load Platform Defaults + + + + - - - - Configuration - - - - 0 - - - - - true + + + + + + Configuration + + + + 0 - - - - 0 - 0 - 740 - 442 - - - - - 0 + + + + true - - - - - - - - - + + + + 0 + 0 + 364 + 449 + + + + + 0 + + + + + + + + + + + + + + + Configuration + + + + 0 + + + + + true + + + + + 0 + 0 + 364 + 449 + + + + + 0 + + + + + + + + + + + + @@ -846,69 +888,111 @@ p, li { white-space: pre-wrap; } Hardware Specific Config - - - 20 - - - - - - - - Load Platform Defaults - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Load Platform Defaults + + + + - - - - Configuration - - - - 0 - - - - - true + + + + + + Configuration + + + + 0 - - - - 0 - 0 - 740 - 442 - - - - - 0 + + + + true - - - - - - - - - + + + + 0 + 0 + 364 + 449 + + + + + 0 + + + + + + + + + + + + + + + Configuration + + + + 0 + + + + + true + + + + + 0 + 0 + 364 + 449 + + + + + 0 + + + + + + + + + + + + diff --git a/src/ui/designer/QGCComboBox.cc b/src/ui/designer/QGCComboBox.cc new file mode 100644 index 000000000..25cee915e --- /dev/null +++ b/src/ui/designer/QGCComboBox.cc @@ -0,0 +1,404 @@ +#include +#include +#include +#include +#include + +#include "QGCComboBox.h" +#include "ui_QGCComboBox.h" +#include "UASInterface.h" +#include "UASManager.h" + + +QGCComboBox::QGCComboBox(QWidget *parent) : + QGCToolWidgetItem("Slider", parent), + parameterName(""), + parameterValue(0.0f), + parameterScalingFactor(0.0), + parameterMin(0.0f), + parameterMax(0.0f), + component(0), + ui(new Ui::QGCComboBox) +{ + ui->setupUi(this); + uas = NULL; + + + ui->editInfoCheckBox->hide(); + ui->editDoneButton->hide(); + ui->editNameLabel->hide(); + ui->editRefreshParamsButton->hide(); + ui->editSelectParamComboBox->hide(); + ui->editSelectComponentComboBox->hide(); + ui->editStatusLabel->hide(); + ui->editLine1->hide(); + ui->editLine2->hide(); + ui->editAddItemButton->hide(); + ui->editRemoveItemButton->hide(); + ui->editItemValueSpinBox->hide(); + ui->editItemNameLabel->hide(); + ui->itemValueLabel->hide(); + ui->itemNameLabel->hide(); + + ui->editLine1->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }"); + ui->editLine2->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }"); + + connect(ui->editDoneButton, SIGNAL(clicked()), this, SLOT(endEditMode())); + connect(ui->editOptionComboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(comboBoxIndexChanged(QString))); + connect(ui->editAddItemButton,SIGNAL(clicked()),this,SLOT(addButtonClicked())); + connect(ui->editRemoveItemButton,SIGNAL(clicked()),this,SLOT(delButtonClicked())); + + // Sending actions + connect(ui->writeButton, SIGNAL(clicked()), this, SLOT(sendParameter())); + connect(ui->editSelectComponentComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectComponent(int))); + connect(ui->editSelectParamComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectParameter(int))); + //connect(ui->valueSlider, SIGNAL(valueChanged(int)), this, SLOT(setSliderValue(int))); + //connect(ui->doubleValueSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setParamValue(double))); + //connect(ui->intValueSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setParamValue(int))); + connect(ui->editNameLabel, SIGNAL(textChanged(QString)), ui->nameLabel, SLOT(setText(QString))); + connect(ui->readButton, SIGNAL(clicked()), this, SLOT(requestParameter())); + connect(ui->editRefreshParamsButton, SIGNAL(clicked()), this, SLOT(refreshParamList())); + connect(ui->editInfoCheckBox, SIGNAL(clicked(bool)), this, SLOT(showInfo(bool))); + // connect to self + connect(ui->infoLabel, SIGNAL(released()), this, SLOT(showTooltip())); + // Set the current UAS if present + connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); +} + +QGCComboBox::~QGCComboBox() +{ + delete ui; +} + +void QGCComboBox::showTooltip() +{ + QWidget* sender = dynamic_cast(QObject::sender()); + + if (sender) + { + QPoint point = mapToGlobal(pos()); + QToolTip::showText(point, sender->toolTip()); + } +} + +void QGCComboBox::refreshParamList() +{ + ui->editSelectParamComboBox->setEnabled(true); + ui->editSelectComponentComboBox->setEnabled(true); + if (uas) + { + uas->getParamManager()->requestParameterList(); + ui->editStatusLabel->setText(tr("Parameter list updating..")); + } +} + +void QGCComboBox::setActiveUAS(UASInterface* activeUas) +{ + if (activeUas) + { + if (uas) + { + disconnect(uas, SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)), this, SLOT(setParameterValue(int,int,int,int,QString,QVariant))); + } + + // Connect buttons and signals + connect(activeUas, SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)), this, SLOT(setParameterValue(int,int,int,int,QString,QVariant)), Qt::UniqueConnection); + uas = activeUas; + // Update current param value + requestParameter(); + // Set param info + QString text = uas->getParamManager()->getParamInfo(parameterName); + ui->infoLabel->setToolTip(text); + // Force-uncheck and hide label if no description is available + if (ui->editInfoCheckBox->isChecked()) + { + showInfo((text.length() > 0)); + } + } +} + +void QGCComboBox::requestParameter() +{ + if (!parameterName.isEmpty() && uas) + { + uas->getParamManager()->requestParameterUpdate(this->component, this->parameterName); + } +} + +void QGCComboBox::showInfo(bool enable) +{ + ui->editInfoCheckBox->setChecked(enable); + ui->infoLabel->setVisible(enable); +} + +void QGCComboBox::selectComponent(int componentIndex) +{ + this->component = ui->editSelectComponentComboBox->itemData(componentIndex).toInt(); +} + +void QGCComboBox::selectParameter(int paramIndex) +{ + // Set name + parameterName = ui->editSelectParamComboBox->itemText(paramIndex); + + // Update min and max values if available + if (uas) + { + if (uas->getParamManager()) + { + // Current value + uas->getParamManager()->requestParameterUpdate(component, parameterName); + + // Minimum + if (uas->getParamManager()->isParamMinKnown(parameterName)) + { + parameterMin = uas->getParamManager()->getParamMin(parameterName); + } + + // Maximum + if (uas->getParamManager()->isParamMaxKnown(parameterName)) + { + parameterMax = uas->getParamManager()->getParamMax(parameterName); + } + + // Description + QString text = uas->getParamManager()->getParamInfo(parameterName); + ui->infoLabel->setText(text); + showInfo(!(text.length() > 0)); + } + } +} + +void QGCComboBox::startEditMode() +{ + ui->nameLabel->hide(); + ui->writeButton->hide(); + ui->readButton->hide(); + + ui->editInfoCheckBox->show(); + ui->editDoneButton->show(); + ui->editNameLabel->show(); + ui->editRefreshParamsButton->show(); + ui->editSelectParamComboBox->show(); + ui->editSelectComponentComboBox->show(); + ui->editStatusLabel->show(); + ui->writeButton->hide(); + ui->readButton->hide(); + ui->editLine1->show(); + ui->editLine2->show(); + ui->editAddItemButton->show(); + ui->editRemoveItemButton->show(); + ui->editItemValueSpinBox->show(); + ui->editItemNameLabel->show(); + ui->itemValueLabel->show(); + ui->itemNameLabel->show(); + isInEditMode = true; +} + +void QGCComboBox::endEditMode() +{ + // Store component id + selectComponent(ui->editSelectComponentComboBox->currentIndex()); + + // Store parameter name and id + selectParameter(ui->editSelectParamComboBox->currentIndex()); + + // Min/max + + ui->editInfoCheckBox->hide(); + ui->editDoneButton->hide(); + ui->editNameLabel->hide(); + ui->editRefreshParamsButton->hide(); + ui->editSelectParamComboBox->hide(); + ui->editSelectComponentComboBox->hide(); + ui->editStatusLabel->hide(); + ui->editLine1->hide(); + ui->editLine2->hide(); + ui->writeButton->show(); + ui->readButton->show(); + ui->editAddItemButton->hide(); + ui->editRemoveItemButton->hide(); + ui->editItemValueSpinBox->hide(); + ui->editItemNameLabel->hide(); + ui->itemValueLabel->hide(); + ui->itemNameLabel->hide(); + ui->nameLabel->show(); + isInEditMode = false; + emit editingFinished(); +} + +void QGCComboBox::sendParameter() +{ + if (uas) + { + // Set value, param manager handles retransmission + if (uas->getParamManager()) + { + uas->getParamManager()->setParameter(component, parameterName, parameterValue); + } + else + { + qDebug() << "UAS HAS NO PARAM MANAGER, DOING NOTHING"; + } + } + else + { + qDebug() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING"; + } +} + + +/** + * @brief uas Unmanned system sending the parameter + * @brief component UAS component sending the parameter + * @brief parameterName Key/name of the parameter + * @brief value Value of the parameter + */ +void QGCComboBox::setParameterValue(int uas, int component, int paramCount, int paramIndex, QString parameterName, QVariant value) +{ + Q_UNUSED(paramCount); + // Check if this component and parameter are part of the list + bool found = false; + for (int i = 0; i< ui->editSelectComponentComboBox->count(); ++i) + { + if (component == ui->editSelectComponentComboBox->itemData(i).toInt()) + { + found = true; + } + } + + if (!found) + { + ui->editSelectComponentComboBox->addItem(tr("Component #%1").arg(component), component); + } + + // Parameter checking + found = false; + for (int i = 0; i < ui->editSelectParamComboBox->count(); ++i) + { + if (parameterName == ui->editSelectParamComboBox->itemText(i)) + { + found = true; + } + } + + if (!found) + { + ui->editSelectParamComboBox->addItem(parameterName, paramIndex); + } + + Q_UNUSED(uas); + + //comboBoxTextToValMap[ui->editItemNameLabel->text()] = ui->editItemValueSpinBox->value(); + + if (component == this->component && parameterName == this->parameterName) + { + for (int i=0;ieditOptionComboBox->count();i++) + { + if (comboBoxTextToValMap[ui->editOptionComboBox->itemText(i)] == value.toInt()) + { + ui->editOptionComboBox->setCurrentIndex(i); + break; + } + } + } + + if (paramIndex == paramCount - 1) + { + ui->editStatusLabel->setText(tr("Complete parameter list received.")); + } +} + +void QGCComboBox::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + + +void QGCComboBox::writeSettings(QSettings& settings) +{ + settings.setValue("TYPE", "COMBOBOX"); + settings.setValue("QGC_PARAM_COMBOBOX_DESCRIPTION", ui->nameLabel->text()); + //settings.setValue("QGC_PARAM_COMBOBOX_BUTTONTEXT", ui->actionButton->text()); + settings.setValue("QGC_PARAM_COMBOBOX_PARAMID", parameterName); + settings.setValue("QGC_PARAM_COMBOBOX_COMPONENTID", component); + settings.setValue("QGC_PARAM_COMBOBOX_DISPLAY_INFO", ui->editInfoCheckBox->isChecked()); + + settings.setValue("QGC_PARAM_COMBOBOX_COUNT", ui->editOptionComboBox->count()); + for (int i=0;ieditOptionComboBox->count();i++) + { + settings.setValue("QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_TEXT",ui->editOptionComboBox->itemText(i)); + settings.setValue("QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_VAL",comboBoxTextToValMap[ui->editOptionComboBox->itemText(i)]); + } + settings.sync(); +} + +void QGCComboBox::readSettings(const QSettings& settings) +{ + parameterName = settings.value("QGC_PARAM_COMBOBOX_PARAMID").toString(); + component = settings.value("QGC_PARAM_COMBOBOX_COMPONENTID").toInt(); + ui->nameLabel->setText(settings.value("QGC_PARAM_COMBOBOX_DESCRIPTION").toString()); + ui->editNameLabel->setText(settings.value("QGC_PARAM_COMBOBOX_DESCRIPTION").toString()); + //settings.setValue("QGC_PARAM_SLIDER_BUTTONTEXT", ui->actionButton->text()); + ui->editSelectParamComboBox->addItem(settings.value("QGC_PARAM_COMBOBOX_PARAMID").toString()); + ui->editSelectParamComboBox->setCurrentIndex(ui->editSelectParamComboBox->count()-1); + ui->editSelectComponentComboBox->addItem(tr("Component #%1").arg(settings.value("QGC_PARAM_COMBOBOX_COMPONENTID").toInt()), settings.value("QGC_PARAM_COMBOBOX_COMPONENTID").toInt()); + showInfo(settings.value("QGC_PARAM_COMBOBOX_DISPLAY_INFO", true).toBool()); + ui->editSelectParamComboBox->setEnabled(true); + ui->editSelectComponentComboBox->setEnabled(true); + + + int num = settings.value("QGC_PARAM_COMBOBOX_COUNT").toInt(); + for (int i=0;ieditOptionComboBox->addItem(settings.value("QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_TEXT").toString()); + qDebug() << "Adding val:" << settings.value("QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i)).toString() << settings.value("QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_VAL").toInt(); + comboBoxTextToValMap[settings.value("QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_TEXT").toString()] = settings.value("QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_VAL").toInt(); + } + + setActiveUAS(UASManager::instance()->getActiveUAS()); + + // Get param value after settings have been loaded + requestParameter(); +} +void QGCComboBox::addButtonClicked() +{ + ui->editOptionComboBox->addItem(ui->editItemNameLabel->text()); + comboBoxTextToValMap[ui->editItemNameLabel->text()] = ui->editItemValueSpinBox->value(); +} + +void QGCComboBox::delButtonClicked() +{ + int index = ui->editOptionComboBox->currentIndex(); + comboBoxTextToValMap.remove(ui->editOptionComboBox->currentText()); + ui->editOptionComboBox->removeItem(index); +} +void QGCComboBox::comboBoxIndexChanged(QString val) +{ + qDebug() << "comboboxchanged:" << comboBoxTextToValMap[val] << val; + switch (parameterValue.type()) + { + case QVariant::Char: + parameterValue = QVariant(QChar((unsigned char)comboBoxTextToValMap[val])); + break; + case QVariant::Int: + parameterValue = (int)comboBoxTextToValMap[val]; + break; + case QVariant::UInt: + parameterValue = (unsigned int)comboBoxTextToValMap[val]; + break; + case QMetaType::Float: + parameterValue =(float)comboBoxTextToValMap[val]; + break; + default: + qCritical() << "ERROR: NO VALID PARAM TYPE"; + return; + } +} diff --git a/src/ui/designer/QGCComboBox.h b/src/ui/designer/QGCComboBox.h new file mode 100644 index 000000000..d6cb987c9 --- /dev/null +++ b/src/ui/designer/QGCComboBox.h @@ -0,0 +1,65 @@ +#ifndef QGCCOMBOBOX_H +#define QGCCOMBOBOX_H + +#include +#include +#include + +#include "QGCToolWidgetItem.h" + +namespace Ui +{ +class QGCComboBox; +} + +class QGCComboBox : public QGCToolWidgetItem +{ + Q_OBJECT + +public: + explicit QGCComboBox(QWidget *parent = 0); + ~QGCComboBox(); + +public slots: + void startEditMode(); + void endEditMode(); + /** @brief Send the parameter to the MAV */ + void sendParameter(); + /** @brief Update the UI with the new parameter value */ + void setParameterValue(int uas, int component, int paramCount, int paramIndex, QString parameterName, const QVariant value); + void writeSettings(QSettings& settings); + void readSettings(const QSettings& settings); + void refreshParamList(); + void setActiveUAS(UASInterface *uas); + void selectComponent(int componentIndex); + void selectParameter(int paramIndex); + /** @brief Show descriptive text next to slider */ + void showInfo(bool enable); + /** @brief Show tool tip of calling element */ + void showTooltip(); + +protected slots: + /** @brief Request the parameter of this widget from the MAV */ + void requestParameter(); + /** @brief Button click to add a new item to the combobox */ + void addButtonClicked(); + /** @brief Button click to remove the currently selected item from the combobox */ + void delButtonClicked(); + /** @brief Updates current parameter based on new combobox value */ + void comboBoxIndexChanged(QString val); +protected: + QMap comboBoxTextToValMap; ///< Comboboxtext/parameter value map + QString parameterName; ///< Key/Name of the parameter + QVariant parameterValue; ///< Value of the parameter + double parameterScalingFactor; ///< Factor to scale the parameter between slider and true value + float parameterMin; + float parameterMax; + int component; ///< ID of the MAV component to address + //double scaledInt; + void changeEvent(QEvent *e); + +private: + Ui::QGCComboBox *ui; +}; + +#endif // QGCCOMBOBOX_H diff --git a/src/ui/designer/QGCComboBox.ui b/src/ui/designer/QGCComboBox.ui new file mode 100644 index 000000000..40ba771b5 --- /dev/null +++ b/src/ui/designer/QGCComboBox.ui @@ -0,0 +1,292 @@ + + + QGCComboBox + + + + 0 + 0 + 789 + 244 + + + + Form + + + Qt::LeftToRight + + + + 6 + + + 3 + + + 6 + + + 3 + + + 6 + + + 12 + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + Done + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + Read the current parameter value on the system + + + Read the current parameter value on the system + + + R + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Transmit the current slider value to the system + + + Transmit the current slider value to the system + + + W + + + + + + + Show Info + + + true + + + + + + + Please click first on refresh to update selection menus.. + + + + + + + true + + + Refresh + + + + + + + false + + + Select parameter + + + Select parameter + + + + + + + + + + false + + + Select component + + + Select component + + + + + + + Delete Item + + + + + + + Add Item + + + + + + + + + + + + + Name + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Value + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + <Parameter Name / Label> + + + + + + + Qt::LeftToRight + + + + + + + :/files/images/status/dialog-information.svg:/files/images/status/dialog-information.svg + + + QToolButton::DelayedPopup + + + Qt::ToolButtonIconOnly + + + false + + + Qt::NoArrow + + + + + + + + 60 + 0 + + + + Name + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + diff --git a/src/ui/designer/QGCToolWidget.cc b/src/ui/designer/QGCToolWidget.cc index ef53e0d5b..58ee8e8d4 100644 --- a/src/ui/designer/QGCToolWidget.cc +++ b/src/ui/designer/QGCToolWidget.cc @@ -11,6 +11,7 @@ #include #include "QGCParamSlider.h" +#include "QGCComboBox.h" #include "QGCCommandButton.h" #include "UASManager.h" @@ -193,6 +194,11 @@ void QGCToolWidget::loadSettings(QSettings& settings) item = new QGCParamSlider(this); //qDebug() << "CREATED PARAM SLIDER"; } + else if (type == "COMBO") + { + item = new QGCComboBox(this); + qDebug() << "CREATED PARAM COMBOBOX"; + } if (item) { -- 2.22.0