From 5e303777a765c20727856a206b3529be952ab174 Mon Sep 17 00:00:00 2001 From: Masaki Murooka Date: Wed, 28 Jul 2021 21:53:09 +0900 Subject: [PATCH 1/3] [mc_rtc_rviz_panel] allow to set default value for form::ComboInput. --- mc_rtc_rviz_panel/src/FormElement.cpp | 21 +++++++++++++++------ mc_rtc_rviz_panel/src/FormElement.h | 8 ++++++-- mc_rtc_rviz_panel/src/Panel.cpp | 24 ++++++++++++++---------- mc_rtc_rviz_panel/src/Panel.h | 12 +++++++++--- mc_rtc_rviz_panel/src/Schema.cpp | 2 +- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/mc_rtc_rviz_panel/src/FormElement.cpp b/mc_rtc_rviz_panel/src/FormElement.cpp index 5bfaec4..6b44d13 100644 --- a/mc_rtc_rviz_panel/src/FormElement.cpp +++ b/mc_rtc_rviz_panel/src/FormElement.cpp @@ -320,8 +320,10 @@ 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) + int def, + bool send_index, + bool user_def) +: FormElement(parent, name, required), values_(values), def_(def), send_index_(send_index), user_def_(user_def) { auto layout = new QVBoxLayout(this); combo_ = new QComboBox(this); @@ -338,13 +340,20 @@ ComboInput::ComboInput(QWidget * parent, void ComboInput::reset() { - combo_->setCurrentIndex(-1); - ready_ = false; + if(user_def_) + { + combo_->setCurrentIndex(def_); + } + else + { + combo_->setCurrentIndex(-1); + } + ready_ = user_def_; } -bool ComboInput::changed(bool required, const std::vector & values, bool send_index) +bool ComboInput::changed(bool required, const std::vector & values, int def, bool send_index, bool user_def) { - return changed_(required) || values_ != values || send_index_ != send_index; + return changed_(required) || values_ != values || def_ != def || send_index_ != send_index || user_def_ != user_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..200a092 100644 --- a/mc_rtc_rviz_panel/src/FormElement.h +++ b/mc_rtc_rviz_panel/src/FormElement.h @@ -458,9 +458,11 @@ struct ComboInput : public FormElement const std::string & name, bool required, const std::vector & values, - bool send_index); + int def, + bool send_index, + bool user_def); - bool changed(bool required, const std::vector & values, bool send_index); + bool changed(bool required, const std::vector & values, int def, bool send_index, bool user_def); mc_rtc::Configuration serialize() const override; @@ -468,7 +470,9 @@ struct ComboInput : public FormElement private: std::vector values_; + int def_; bool send_index_; + bool user_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..2b9269e 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 &, + int, bool, bool)), + this, + SLOT(got_form_combo_input(const WidgetId &, const std::string &, bool, const std::vector &, int, + bool, bool))); connect(this, SIGNAL(signal_form_data_combo_input(const WidgetId &, const std::string &, bool, const std::vector &, bool)), @@ -585,9 +585,11 @@ void Panel::form_combo_input(const WidgetId & formId, const std::string & name, bool required, const std::vector & values, - bool send_index) + int def, + bool send_index, + bool def_from_user) { - Q_EMIT signal_form_combo_input(formId, name, required, values, send_index); + Q_EMIT signal_form_combo_input(formId, name, required, values, def, send_index, def_from_user); } void Panel::form_data_combo_input(const WidgetId & formId, @@ -962,10 +964,12 @@ void Panel::got_form_combo_input(const WidgetId & formId, const std::string & name, bool required, const std::vector & values, - bool send_index) + int def, + bool send_index, + bool def_from_user) { auto & form = get_widget(formId); - form.element(name, required, values, send_index); + form.element(name, required, values, def, send_index, def_from_user); } 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..56f3d95 100644 --- a/mc_rtc_rviz_panel/src/Panel.h +++ b/mc_rtc_rviz_panel/src/Panel.h @@ -193,7 +193,9 @@ class Panel : public CategoryWidget, public mc_control::ControllerClient const std::string & name, bool required, const std::vector & values, - bool send_index) override; + int def, + bool send_index, + bool def_from_user) override; void form_data_combo_input(const WidgetId & formId, const std::string & name, @@ -347,7 +349,9 @@ private slots: const std::string & name, bool required, const std::vector & values, - bool send_index); + int def, + bool send_index, + bool def_from_user); void got_form_data_combo_input(const WidgetId & formId, const std::string & name, bool required, @@ -466,7 +470,9 @@ private slots: const std::string & name, bool required, const std::vector & values, - bool send_index); + int def, + bool send_index, + bool def_from_user); 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..7267411 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, -1, false, false)); if(values.size() == 1 && required) { v.back()->hidden(true); From 7338817cbdd963b0615d9dfd2263db9844a21eec Mon Sep 17 00:00:00 2001 From: Masaki Murooka Date: Thu, 29 Jul 2021 14:11:06 +0900 Subject: [PATCH 2/3] [mc_rtc_rviz_panel] delete def_from_user based on review comments. --- mc_rtc_rviz_panel/src/FormElement.cpp | 20 ++++++-------------- mc_rtc_rviz_panel/src/FormElement.h | 8 +++----- mc_rtc_rviz_panel/src/Panel.cpp | 16 +++++++--------- mc_rtc_rviz_panel/src/Panel.h | 9 +++------ mc_rtc_rviz_panel/src/Schema.cpp | 2 +- 5 files changed, 20 insertions(+), 35 deletions(-) diff --git a/mc_rtc_rviz_panel/src/FormElement.cpp b/mc_rtc_rviz_panel/src/FormElement.cpp index 6b44d13..83489c0 100644 --- a/mc_rtc_rviz_panel/src/FormElement.cpp +++ b/mc_rtc_rviz_panel/src/FormElement.cpp @@ -320,10 +320,9 @@ ComboInput::ComboInput(QWidget * parent, const std::string & name, bool required, const std::vector & values, - int def, bool send_index, - bool user_def) -: FormElement(parent, name, required), values_(values), def_(def), send_index_(send_index), user_def_(user_def) + int def) +: FormElement(parent, name, required), values_(values), send_index_(send_index), def_(def) { auto layout = new QVBoxLayout(this); combo_ = new QComboBox(this); @@ -340,20 +339,13 @@ ComboInput::ComboInput(QWidget * parent, void ComboInput::reset() { - if(user_def_) - { - combo_->setCurrentIndex(def_); - } - else - { - combo_->setCurrentIndex(-1); - } - ready_ = user_def_; + combo_->setCurrentIndex(def_); + ready_ = (def_ != -1); } -bool ComboInput::changed(bool required, const std::vector & values, int def, bool send_index, bool user_def) +bool ComboInput::changed(bool required, const std::vector & values, bool send_index, int def) { - return changed_(required) || values_ != values || def_ != def || send_index_ != send_index || user_def_ != user_def; + 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 200a092..27d5905 100644 --- a/mc_rtc_rviz_panel/src/FormElement.h +++ b/mc_rtc_rviz_panel/src/FormElement.h @@ -458,11 +458,10 @@ struct ComboInput : public FormElement const std::string & name, bool required, const std::vector & values, - int def, bool send_index, - bool user_def); + int def); - bool changed(bool required, const std::vector & values, int def, bool send_index, bool user_def); + bool changed(bool required, const std::vector & values, bool send_index, int def); mc_rtc::Configuration serialize() const override; @@ -470,9 +469,8 @@ struct ComboInput : public FormElement private: std::vector values_; - int def_; bool send_index_; - bool user_def_; + 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 2b9269e..6a56ff0 100644 --- a/mc_rtc_rviz_panel/src/Panel.cpp +++ b/mc_rtc_rviz_panel/src/Panel.cpp @@ -277,10 +277,10 @@ Panel::Panel(QWidget * parent) 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 &, - int, bool, bool)), + bool, int)), this, - SLOT(got_form_combo_input(const WidgetId &, const std::string &, bool, const std::vector &, int, - bool, bool))); + 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,11 +585,10 @@ void Panel::form_combo_input(const WidgetId & formId, const std::string & name, bool required, const std::vector & values, - int def, bool send_index, - bool def_from_user) + int def) { - Q_EMIT signal_form_combo_input(formId, name, required, values, def, send_index, def_from_user); + Q_EMIT signal_form_combo_input(formId, name, required, values, send_index, def); } void Panel::form_data_combo_input(const WidgetId & formId, @@ -964,12 +963,11 @@ void Panel::got_form_combo_input(const WidgetId & formId, const std::string & name, bool required, const std::vector & values, - int def, bool send_index, - bool def_from_user) + int def) { auto & form = get_widget(formId); - form.element(name, required, values, def, send_index, def_from_user); + 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 56f3d95..a17c710 100644 --- a/mc_rtc_rviz_panel/src/Panel.h +++ b/mc_rtc_rviz_panel/src/Panel.h @@ -193,9 +193,8 @@ class Panel : public CategoryWidget, public mc_control::ControllerClient const std::string & name, bool required, const std::vector & values, - int def, bool send_index, - bool def_from_user) override; + int def) override; void form_data_combo_input(const WidgetId & formId, const std::string & name, @@ -349,9 +348,8 @@ private slots: const std::string & name, bool required, const std::vector & values, - int def, bool send_index, - bool def_from_user); + int def); void got_form_data_combo_input(const WidgetId & formId, const std::string & name, bool required, @@ -470,9 +468,8 @@ private slots: const std::string & name, bool required, const std::vector & values, - int def, bool send_index, - bool def_from_user); + 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 7267411..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, -1, false, false)); + v.emplace_back(new form::ComboInput(parent, k, required, values, false, -1)); if(values.size() == 1 && required) { v.back()->hidden(true); From 956ef9897d738db837c42bf2c1b8435db6cfa352 Mon Sep 17 00:00:00 2001 From: Masaki Murooka Date: Thu, 29 Jul 2021 14:15:25 +0900 Subject: [PATCH 3/3] [mc_rtc_rviz_panel] change the condition of default value proviated. --- mc_rtc_rviz_panel/src/FormElement.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mc_rtc_rviz_panel/src/FormElement.cpp b/mc_rtc_rviz_panel/src/FormElement.cpp index 83489c0..01a9f3a 100644 --- a/mc_rtc_rviz_panel/src/FormElement.cpp +++ b/mc_rtc_rviz_panel/src/FormElement.cpp @@ -340,7 +340,7 @@ ComboInput::ComboInput(QWidget * parent, void ComboInput::reset() { combo_->setCurrentIndex(def_); - ready_ = (def_ != -1); + ready_ = (def_ >= 0); } bool ComboInput::changed(bool required, const std::vector & values, bool send_index, int def)