diff --git a/mc_rtc_rviz_panel/src/FormElement.cpp b/mc_rtc_rviz_panel/src/FormElement.cpp index 5bfaec4..01a9f3a 100644 --- a/mc_rtc_rviz_panel/src/FormElement.cpp +++ b/mc_rtc_rviz_panel/src/FormElement.cpp @@ -320,8 +320,9 @@ ComboInput::ComboInput(QWidget * parent, const std::string & name, bool required, const std::vector & values, - bool send_index) -: FormElement(parent, name, required), values_(values), send_index_(send_index) + bool send_index, + int def) +: FormElement(parent, name, required), values_(values), send_index_(send_index), def_(def) { auto layout = new QVBoxLayout(this); combo_ = new QComboBox(this); @@ -338,13 +339,13 @@ ComboInput::ComboInput(QWidget * parent, void ComboInput::reset() { - combo_->setCurrentIndex(-1); - ready_ = false; + combo_->setCurrentIndex(def_); + ready_ = (def_ >= 0); } -bool ComboInput::changed(bool required, const std::vector & values, bool send_index) +bool ComboInput::changed(bool required, const std::vector & values, bool send_index, int def) { - return changed_(required) || values_ != values || send_index_ != send_index; + return changed_(required) || values_ != values || send_index_ != send_index || def_ != def; } void ComboInput::currentIndexChanged(int idx) diff --git a/mc_rtc_rviz_panel/src/FormElement.h b/mc_rtc_rviz_panel/src/FormElement.h index c5a15fc..27d5905 100644 --- a/mc_rtc_rviz_panel/src/FormElement.h +++ b/mc_rtc_rviz_panel/src/FormElement.h @@ -458,9 +458,10 @@ struct ComboInput : public FormElement const std::string & name, bool required, const std::vector & values, - bool send_index); + bool send_index, + int def); - bool changed(bool required, const std::vector & values, bool send_index); + bool changed(bool required, const std::vector & values, bool send_index, int def); mc_rtc::Configuration serialize() const override; @@ -469,6 +470,7 @@ struct ComboInput : public FormElement private: std::vector values_; bool send_index_; + int def_; QComboBox * combo_; private slots: void currentIndexChanged(int); diff --git a/mc_rtc_rviz_panel/src/Panel.cpp b/mc_rtc_rviz_panel/src/Panel.cpp index ae8280f..6a56ff0 100644 --- a/mc_rtc_rviz_panel/src/Panel.cpp +++ b/mc_rtc_rviz_panel/src/Panel.cpp @@ -275,12 +275,12 @@ Panel::Panel(QWidget * parent) SIGNAL(signal_form_array_input(const WidgetId &, const std::string &, bool, const Eigen::VectorXd &, bool, bool)), this, SLOT(got_form_array_input(const WidgetId &, const std::string &, bool, const Eigen::VectorXd &, bool, bool))); - connect( - this, - SIGNAL( - signal_form_combo_input(const WidgetId &, const std::string &, bool, const std::vector &, bool)), - this, - SLOT(got_form_combo_input(const WidgetId &, const std::string &, bool, const std::vector &, bool))); + connect(this, + SIGNAL(signal_form_combo_input(const WidgetId &, const std::string &, bool, const std::vector &, + bool, int)), + this, + SLOT(got_form_combo_input(const WidgetId &, const std::string &, bool, const std::vector &, bool, + int))); connect(this, SIGNAL(signal_form_data_combo_input(const WidgetId &, const std::string &, bool, const std::vector &, bool)), @@ -585,9 +585,10 @@ void Panel::form_combo_input(const WidgetId & formId, const std::string & name, bool required, const std::vector & values, - bool send_index) + bool send_index, + int def) { - Q_EMIT signal_form_combo_input(formId, name, required, values, send_index); + Q_EMIT signal_form_combo_input(formId, name, required, values, send_index, def); } void Panel::form_data_combo_input(const WidgetId & formId, @@ -962,10 +963,11 @@ void Panel::got_form_combo_input(const WidgetId & formId, const std::string & name, bool required, const std::vector & values, - bool send_index) + bool send_index, + int def) { auto & form = get_widget(formId); - form.element(name, required, values, send_index); + form.element(name, required, values, send_index, def); } void Panel::got_form_data_combo_input(const WidgetId & formId, diff --git a/mc_rtc_rviz_panel/src/Panel.h b/mc_rtc_rviz_panel/src/Panel.h index 0db9cfe..a17c710 100644 --- a/mc_rtc_rviz_panel/src/Panel.h +++ b/mc_rtc_rviz_panel/src/Panel.h @@ -193,7 +193,8 @@ class Panel : public CategoryWidget, public mc_control::ControllerClient const std::string & name, bool required, const std::vector & values, - bool send_index) override; + bool send_index, + int def) override; void form_data_combo_input(const WidgetId & formId, const std::string & name, @@ -347,7 +348,8 @@ private slots: const std::string & name, bool required, const std::vector & values, - bool send_index); + bool send_index, + int def); void got_form_data_combo_input(const WidgetId & formId, const std::string & name, bool required, @@ -466,7 +468,8 @@ private slots: const std::string & name, bool required, const std::vector & values, - bool send_index); + bool send_index, + int def); void signal_form_data_combo_input(const WidgetId & formId, const std::string & name, bool required, diff --git a/mc_rtc_rviz_panel/src/Schema.cpp b/mc_rtc_rviz_panel/src/Schema.cpp index 47ba519..83e66f3 100644 --- a/mc_rtc_rviz_panel/src/Schema.cpp +++ b/mc_rtc_rviz_panel/src/Schema.cpp @@ -108,7 +108,7 @@ void Schema::init(const mc_rtc::Configuration & s, auto cf = create_form; create_form = [cf, k, required, values](QWidget * parent, const mc_rtc::Configuration & data) { auto v = cf(parent, data); - v.emplace_back(new form::ComboInput(parent, k, required, values, false)); + v.emplace_back(new form::ComboInput(parent, k, required, values, false, -1)); if(values.size() == 1 && required) { v.back()->hidden(true);