diff --git a/ground/openpilotgcs/src/plugins/config/channelform.cpp b/ground/openpilotgcs/src/plugins/config/channelform.cpp new file mode 100644 index 000000000..a15a5f713 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/config/channelform.cpp @@ -0,0 +1,73 @@ +#include "channelform.h" + +#include + + +ChannelForm::ChannelForm(const int index, QWidget *parent) : ConfigTaskWidget(parent), m_index(index) +{} + +ChannelForm::~ChannelForm() +{} + +int ChannelForm::index() const +{ + return m_index; +} + +void ChannelForm::moveTo(QGridLayout &dstLayout) +{ + QGridLayout *srcLayout = dynamic_cast(layout()); + + Q_ASSERT(srcLayout); + + // if we are the first row to be inserted then show the legend + bool showLegend = (dstLayout.rowCount() == 1); + + if (showLegend) { + // move legend row to target grid layout + moveRow(0, *srcLayout, dstLayout); + } else { + removeRow(0, *srcLayout); + } + + // move field row to target grid layout + moveRow(1, *srcLayout, dstLayout); + + // this form is now empty so hide it + setVisible(false); +} + +void ChannelForm::moveRow(int row, QGridLayout &srcLayout, QGridLayout &dstLayout) +{ + int dstRow = dstLayout.rowCount(); + + for (int col = 0; col < srcLayout.columnCount(); col++) { + QLayoutItem *item = srcLayout.itemAtPosition(row, col); + if (!item) { + continue; + } + QWidget *widget = item->widget(); + if (widget) { + dstLayout.addWidget(widget, dstRow, col); + continue; + } + // TODO handle item of type QLayout + } +} + +void ChannelForm::removeRow(int row, QGridLayout &layout) +{ + for (int col = 0; col < layout.columnCount(); col++) { + QLayoutItem *item = layout.itemAtPosition(row, col); + if (!item) { + continue; + } + QWidget *widget = item->widget(); + if (widget) { + layout.removeWidget(widget); + delete widget; + continue; + } + // TODO handle item of type QLayout + } +} diff --git a/ground/openpilotgcs/src/plugins/config/channelform.h b/ground/openpilotgcs/src/plugins/config/channelform.h new file mode 100644 index 000000000..6c62a2f4b --- /dev/null +++ b/ground/openpilotgcs/src/plugins/config/channelform.h @@ -0,0 +1,36 @@ +#ifndef CHANNELFORM_H +#define CHANNELFORM_H + +#include "configtaskwidget.h" + +#include + +namespace Ui { +class ChannelForm; +} + +class QGridLayout; + +class ChannelForm : public ConfigTaskWidget { + Q_OBJECT + +public: + explicit ChannelForm(const int index, QWidget *parent = 0); + ~ChannelForm(); + + int index() const; + + virtual QString name() = 0; + virtual void setName(const QString &name) = 0; + + void moveTo(QGridLayout &dstLayout); + +private: + // Channel index + int m_index; + + static void moveRow(int row, QGridLayout &srcLayout, QGridLayout &dstLayout); + static void removeRow(int row, QGridLayout &layout); +}; + +#endif // CHANNELFORM_H diff --git a/ground/openpilotgcs/src/plugins/config/config.pro b/ground/openpilotgcs/src/plugins/config/config.pro index 06b56a8f1..747557191 100644 --- a/ground/openpilotgcs/src/plugins/config/config.pro +++ b/ground/openpilotgcs/src/plugins/config/config.pro @@ -1,18 +1,19 @@ TEMPLATE = lib TARGET = Config DEFINES += CONFIG_LIBRARY -QT += svg -QT += opengl -QT += qml quick + +QT += svg opengl qml quick include(config_dependencies.pri) INCLUDEPATH += ../../libs/eigen -OTHER_FILES += Config.pluginspec \ +OTHER_FILES += \ + Config.pluginspec \ calibration/WizardStepIndicator.qml -HEADERS += configplugin.h \ +HEADERS += \ + configplugin.h \ configgadgetwidget.h \ configgadgetfactory.h \ configgadget.h \ @@ -27,6 +28,7 @@ HEADERS += configplugin.h \ assertions.h \ defaultattitudewidget.h \ defaulthwsettingswidget.h \ + channelform.h \ inputchannelform.h \ configcamerastabilizationwidget.h \ configtxpidwidget.h \ @@ -53,7 +55,8 @@ HEADERS += configplugin.h \ calibration/thermal/settingshandlingtransitions.h \ calibration/thermal/compensationcalculationtransition.h -SOURCES += configplugin.cpp \ +SOURCES += \ + configplugin.cpp \ configgadgetwidget.cpp \ configgadgetfactory.cpp \ configgadget.cpp \ @@ -67,6 +70,7 @@ SOURCES += configplugin.cpp \ configpipxtremewidget.cpp \ defaultattitudewidget.cpp \ defaulthwsettingswidget.cpp \ + channelform.cpp \ inputchannelform.cpp \ configcamerastabilizationwidget.cpp \ configrevowidget.cpp \ @@ -88,7 +92,8 @@ SOURCES += configplugin.cpp \ calibration/thermal/thermalcalibrationhelper.cpp \ calibration/thermal/thermalcalibrationmodel.cpp -FORMS += airframe.ui \ +FORMS += \ + airframe.ui \ airframe_ccpm.ui \ airframe_fixedwing.ui \ airframe_ground.ui \ diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index 491e36ab8..709eabf8f 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -80,9 +80,9 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : unsigned int indexRT = 0; foreach(QString name, manualSettingsObj->getField("ChannelNumber")->getElementNames()) { Q_ASSERT(index < ManualControlSettings::CHANNELGROUPS_NUMELEM); - InputChannelForm *form = new InputChannelForm(this); - form->addToGrid(ui->channelLayout); + InputChannelForm *form = new InputChannelForm(index, this); form->setName(name); + form->moveTo(*(ui->channelLayout)); // The order of the following binding calls is important. Since the values will be populated // in reverse order of the binding order otherwise the 'Reversed' logic will floor the neutral value @@ -100,9 +100,9 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : // Reversing supported for some channels only bool reversable = ((index == ManualControlSettings::CHANNELGROUPS_THROTTLE) || - (index == ManualControlSettings::CHANNELGROUPS_ROLL) || - (index == ManualControlSettings::CHANNELGROUPS_PITCH) || - (index == ManualControlSettings::CHANNELGROUPS_YAW)); + (index == ManualControlSettings::CHANNELGROUPS_ROLL) || + (index == ManualControlSettings::CHANNELGROUPS_PITCH) || + (index == ManualControlSettings::CHANNELGROUPS_YAW)); form->ui->channelRev->setVisible(reversable); // Input filter response time fields supported for some channels only diff --git a/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp index 5108d9b0f..ba9618eea 100644 --- a/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp @@ -77,7 +77,7 @@ ConfigOutputWidget::ConfigOutputWidget(QWidget *parent) : ConfigTaskWidget(paren // Register for ActuatorSettings changes: for (unsigned int i = 0; i < ActuatorCommand::CHANNEL_NUMELEM; i++) { OutputChannelForm *form = new OutputChannelForm(i, this); - form->addToGrid(ui->channelLayout); + form->moveTo(*(ui->channelLayout)); connect(ui->channelOutTest, SIGNAL(toggled(bool)), form, SLOT(enableChannelTest(bool))); connect(form, SIGNAL(channelChanged(int, int)), this, SLOT(sendChannelTest(int, int))); @@ -196,7 +196,7 @@ OutputChannelForm *ConfigOutputWidget::getOutputChannelForm(const int index) con /** * Set the label for a channel output assignement */ -void ConfigOutputWidget::assignOutputChannel(UAVDataObject *obj, QString str) +void ConfigOutputWidget::assignOutputChannel(UAVDataObject *obj, QString &str) { // FIXME: use signal/ slot approach UAVObjectField *field = obj->getField(str); @@ -206,7 +206,7 @@ void ConfigOutputWidget::assignOutputChannel(UAVDataObject *obj, QString str) OutputChannelForm *outputChannelForm = getOutputChannelForm(index); if (outputChannelForm) { - outputChannelForm->setAssignment(str); + outputChannelForm->setName(str); } } @@ -256,15 +256,15 @@ void ConfigOutputWidget::refreshWidgetsValues(UAVObject *obj) // Initialize output forms QList outputChannelForms = findChildren(); foreach(OutputChannelForm * outputChannelForm, outputChannelForms) { - outputChannelForm->setAssignment(ChannelDesc[outputChannelForm->index()]); + outputChannelForm->setName(ChannelDesc[outputChannelForm->index()]); // init min,max,neutral int minValue = actuatorSettingsData.ChannelMin[outputChannelForm->index()]; int maxValue = actuatorSettingsData.ChannelMax[outputChannelForm->index()]; - outputChannelForm->minmax(minValue, maxValue); + outputChannelForm->setRange(minValue, maxValue); int neutral = actuatorSettingsData.ChannelNeutral[outputChannelForm->index()]; - outputChannelForm->neutral(neutral); + outputChannelForm->setNeutral(neutral); } // Get the SpinWhileArmed setting @@ -351,10 +351,10 @@ void ConfigOutputWidget::refreshWidgetsValues(UAVObject *obj) int minValue = actuatorSettingsData.ChannelMin[outputChannelForm->index()]; int maxValue = actuatorSettingsData.ChannelMax[outputChannelForm->index()]; - outputChannelForm->minmax(minValue, maxValue); + outputChannelForm->setRange(minValue, maxValue); int neutral = actuatorSettingsData.ChannelNeutral[outputChannelForm->index()]; - outputChannelForm->neutral(neutral); + outputChannelForm->setNeutral(neutral); } setDirty(dirty); diff --git a/ground/openpilotgcs/src/plugins/config/configoutputwidget.h b/ground/openpilotgcs/src/plugins/config/configoutputwidget.h index 1cabfb5a2..fda2922c6 100644 --- a/ground/openpilotgcs/src/plugins/config/configoutputwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configoutputwidget.h @@ -47,6 +47,8 @@ public: ConfigOutputWidget(QWidget *parent = 0); ~ConfigOutputWidget(); +protected: + void enableControls(bool enable); private: Ui_OutputWidget *ui; @@ -55,14 +57,14 @@ private: void updateChannelInSlider(QSlider *slider, QLabel *min, QLabel *max, QCheckBox *rev, int value); - void assignChannel(UAVDataObject *obj, QString str); - void assignOutputChannel(UAVDataObject *obj, QString str); + void assignOutputChannel(UAVDataObject *obj, QString &str); OutputChannelForm *getOutputChannelForm(const int index) const; int mccDataRate; UAVObject::Metadata accInitialData; bool wasItMe; + private slots: void stopTests(); void disableIfNotMe(UAVObject *obj); @@ -71,8 +73,6 @@ private slots: void runChannelTests(bool state); void sendChannelTest(int index, int value); void openHelp(); -protected: - void enableControls(bool enable); }; -#endif // ifndef CONFIGOUTPUTWIDGET_H +#endif // CONFIGOUTPUTWIDGET_H diff --git a/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp index 788b96d2f..8d5ff8c7f 100644 --- a/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp @@ -4,7 +4,8 @@ #include "manualcontrolsettings.h" #include "gcsreceiver.h" -InputChannelForm::InputChannelForm(QWidget *parent) : ConfigTaskWidget(parent), ui(new Ui::InputChannelForm) +InputChannelForm::InputChannelForm(const int index, QWidget *parent) : + ChannelForm(index, parent), ui(new Ui::InputChannelForm) { ui->setupUi(this); @@ -22,70 +23,15 @@ InputChannelForm::~InputChannelForm() delete ui; } -void InputChannelForm::addToGrid(QGridLayout *gridLayout) +QString InputChannelForm::name() { - // if we are the first row to be inserted the show the legend - bool showLegend = (gridLayout->rowCount() == 1); - - // The first time through the loop, keep the legend. All other times, delete it. - if (false && !showLegend) { - QLayout *legendLayout = layout()->itemAt(0)->layout(); - Q_ASSERT(legendLayout); - // remove every item - while (legendLayout->count()) { - QLayoutItem *item = legendLayout->takeAt(0); - if (!item) { - continue; - } - // get widget from layout item - QWidget *widget = item->widget(); - if (widget) { - delete widget; - continue; - } - } - // and finally remove and delete the legend layout - layout()->removeItem(legendLayout); - delete legendLayout; - } - - QGridLayout *srcLayout = dynamic_cast(layout()); - Q_ASSERT(srcLayout); - - if (showLegend) { - Q_ASSERT(srcLayout); - int row = gridLayout->rowCount(); - for(int col = 0; col < srcLayout->columnCount(); col++) { - QLayoutItem *item = srcLayout->itemAtPosition(0, col); - if (!item) { - continue; - } - QWidget *widget = item->widget(); - if (widget) { - gridLayout->addWidget(widget, row, col); - continue; - } - } - } - - int row = gridLayout->rowCount(); - for(int col = 0; col < srcLayout->columnCount(); col++) { - QLayoutItem *item = srcLayout->itemAtPosition(1, col); - if (!item) { - continue; - } - QWidget *widget = item->widget(); - if (widget) { - gridLayout->addWidget(widget, row, col); - continue; - } - } - - // - setVisible(false); + return ui->channelName->text(); } -void InputChannelForm::setName(QString &name) +/** + * Set the channel assignment label. + */ +void InputChannelForm::setName(const QString &name) { ui->channelName->setText(name); } diff --git a/ground/openpilotgcs/src/plugins/config/inputchannelform.h b/ground/openpilotgcs/src/plugins/config/inputchannelform.h index ad17d0963..f48bcbd0a 100644 --- a/ground/openpilotgcs/src/plugins/config/inputchannelform.h +++ b/ground/openpilotgcs/src/plugins/config/inputchannelform.h @@ -1,6 +1,7 @@ #ifndef INPUTCHANNELFORM_H #define INPUTCHANNELFORM_H +#include "channelform.h" #include "configinputwidget.h" #include @@ -9,17 +10,17 @@ namespace Ui { class InputChannelForm; } -class InputChannelForm : public ConfigTaskWidget { +class InputChannelForm : public ChannelForm { Q_OBJECT public: - explicit InputChannelForm(QWidget *parent = 0); + explicit InputChannelForm(const int index, QWidget *parent = NULL); ~InputChannelForm(); friend class ConfigInputWidget; - void setName(QString &name); - void addToGrid(QGridLayout *gridLayout); + virtual QString name(); + virtual void setName(const QString &name); private slots: void minMaxUpdated(); diff --git a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp index b5d9c2358..da8514855 100644 --- a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp @@ -26,15 +26,14 @@ */ #include "outputchannelform.h" -#include "configoutputwidget.h" OutputChannelForm::OutputChannelForm(const int index, QWidget *parent) : - ConfigTaskWidget(parent), ui(), m_index(index), m_inChannelTest(false) + ChannelForm(index, parent), ui(), m_inChannelTest(false) { ui.setupUi(this); // The convention for OP is Channel 1 to Channel 10. - ui.actuatorNumber->setText(QString("%1:").arg(m_index + 1)); + ui.actuatorNumber->setText(QString("%1:").arg(index + 1)); // Register for ActuatorSettings changes: connect(ui.actuatorMin, SIGNAL(editingFinished()), this, SLOT(setChannelRange())); @@ -54,66 +53,17 @@ OutputChannelForm::~OutputChannelForm() // Do nothing } -void OutputChannelForm::addToGrid(QGridLayout *gridLayout) +QString OutputChannelForm::name() { - // if we are the first row to be inserted the show the legend - bool showLegend = (gridLayout->rowCount() == 1); + return ui.actuatorName->text(); +} - if (false && !showLegend) { - QLayout *legendLayout = layout()->itemAt(0)->layout(); - Q_ASSERT(legendLayout); - // remove every item - while (legendLayout->count()) { - QLayoutItem *item = legendLayout->takeAt(0); - if (!item) { - continue; - } - // get widget from layout item - QWidget *widget = item->widget(); - if (widget) { - delete widget; - continue; - } - } - // and finally remove and delete the legend layout - layout()->removeItem(legendLayout); - delete legendLayout; - } - - QGridLayout *srcLayout = dynamic_cast(layout()); - Q_ASSERT(srcLayout); - - if (showLegend) { - Q_ASSERT(srcLayout); - int row = gridLayout->rowCount(); - for(int col = 0; col < srcLayout->columnCount(); col++) { - QLayoutItem *item = srcLayout->itemAtPosition(0, col); - if (!item) { - continue; - } - QWidget *widget = item->widget(); - if (widget) { - gridLayout->addWidget(widget, row, col); - continue; - } - } - } - - int row = gridLayout->rowCount(); - for(int col = 0; col < srcLayout->columnCount(); col++) { - QLayoutItem *item = srcLayout->itemAtPosition(1, col); - if (!item) { - continue; - } - QWidget *widget = item->widget(); - if (widget) { - gridLayout->addWidget(widget, row, col); - continue; - } - } - - // - setVisible(false); +/** + * Set the channel assignment label. + */ +void OutputChannelForm::setName(const QString &name) +{ + ui.actuatorName->setText(name); } /** @@ -184,26 +134,49 @@ void OutputChannelForm::linkToggled(bool state) } } +int OutputChannelForm::max() const +{ + return ui.actuatorMax->value(); +} + /** * Set maximal channel value. */ -void OutputChannelForm::max(int maximum) +void OutputChannelForm::setMax(int maximum) { - minmax(ui.actuatorMin->value(), maximum); + setRange(ui.actuatorMin->value(), maximum); +} + +int OutputChannelForm::min() const +{ + return ui.actuatorMin->value(); } /** * Set minimal channel value. */ -void OutputChannelForm::min(int minimum) +void OutputChannelForm::setMin(int minimum) { - minmax(minimum, ui.actuatorMax->value()); + setRange(minimum, ui.actuatorMax->value()); +} + +int OutputChannelForm::neutral() const +{ + return ui.actuatorNeutral->value(); +} + +/** + * Set neutral of channel. + */ +void OutputChannelForm::setNeutral(int value) +{ + ui.actuatorNeutral->setValue(value); } /** * Set minimal and maximal channel value. */ -void OutputChannelForm::minmax(int minimum, int maximum) +void OutputChannelForm::setRange(int minimum, int maximum) { ui.actuatorMin->setValue(minimum); ui.actuatorMax->setValue(maximum); @@ -215,22 +188,6 @@ void OutputChannelForm::minmax(int minimum, int maximum) } } -/** - * Set neutral of channel. - */ -void OutputChannelForm::neutral(int value) -{ - ui.actuatorNeutral->setValue(value); -} - -/** - * Set the channel assignment label. - */ -void OutputChannelForm::setAssignment(const QString &assignment) -{ - ui.actuatorName->setText(assignment); -} - /** * Sets the minimum/maximum value of the channel output sliders. * Have to do it here because setMinimum is not a slot. diff --git a/ground/openpilotgcs/src/plugins/config/outputchannelform.h b/ground/openpilotgcs/src/plugins/config/outputchannelform.h index c854548b2..78d008115 100644 --- a/ground/openpilotgcs/src/plugins/config/outputchannelform.h +++ b/ground/openpilotgcs/src/plugins/config/outputchannelform.h @@ -27,11 +27,13 @@ #ifndef OUTPUTCHANNELFORM_H #define OUTPUTCHANNELFORM_H -#include +#include "channelform.h" +#include "configoutputwidget.h" #include "ui_outputchannelform.h" -#include "configtaskwidget.h" -class OutputChannelForm : public ConfigTaskWidget { +#include + +class OutputChannelForm : public ChannelForm { Q_OBJECT public: @@ -40,18 +42,17 @@ public: friend class ConfigOutputWidget; - void setAssignment(const QString &assignment); - int index() const; - void addToGrid(QGridLayout *gridLayout); + virtual QString name(); + virtual void setName(const QString &name); public slots: - void max(int maximum); - int max() const; - void min(int minimum); int min() const; - void minmax(int minimum, int maximum); - void neutral(int value); + void setMin(int minimum); + int max() const; + void setMax(int maximum); int neutral() const; + void setNeutral(int value); + void setRange(int minimum, int maximum); void enableChannelTest(bool state); signals: @@ -59,8 +60,6 @@ signals: private: Ui::outputChannelForm ui; - // Channel index - int m_index; bool m_inChannelTest; private slots: @@ -70,23 +69,4 @@ private slots: void setChannelRange(); }; -inline int OutputChannelForm::index() const -{ - return m_index; -} - -inline int OutputChannelForm::max() const -{ - return ui.actuatorMax->value(); -} - -inline int OutputChannelForm::min() const -{ - return ui.actuatorMin->value(); -} - -inline int OutputChannelForm::neutral() const -{ - return ui.actuatorNeutral->value(); -} #endif // OUTPUTCHANNELFORM_H