Skip to content

Commit

Permalink
Merge pull request #24 from mmurooka/form-combo-default
Browse files Browse the repository at this point in the history
[mc_rtc_rviz_panel] allow to set default value for form::ComboInput
  • Loading branch information
gergondet authored Jul 30, 2021
2 parents c63cc9e + 956ef98 commit 30e2e9e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
13 changes: 7 additions & 6 deletions mc_rtc_rviz_panel/src/FormElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ ComboInput::ComboInput(QWidget * parent,
const std::string & name,
bool required,
const std::vector<std::string> & 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);
Expand All @@ -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<std::string> & values, bool send_index)
bool ComboInput::changed(bool required, const std::vector<std::string> & 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)
Expand Down
6 changes: 4 additions & 2 deletions mc_rtc_rviz_panel/src/FormElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,10 @@ struct ComboInput : public FormElement
const std::string & name,
bool required,
const std::vector<std::string> & values,
bool send_index);
bool send_index,
int def);

bool changed(bool required, const std::vector<std::string> & values, bool send_index);
bool changed(bool required, const std::vector<std::string> & values, bool send_index, int def);

mc_rtc::Configuration serialize() const override;

Expand All @@ -469,6 +470,7 @@ struct ComboInput : public FormElement
private:
std::vector<std::string> values_;
bool send_index_;
int def_;
QComboBox * combo_;
private slots:
void currentIndexChanged(int);
Expand Down
22 changes: 12 additions & 10 deletions mc_rtc_rviz_panel/src/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> &, bool)),
this,
SLOT(got_form_combo_input(const WidgetId &, const std::string &, bool, const std::vector<std::string> &, bool)));
connect(this,
SIGNAL(signal_form_combo_input(const WidgetId &, const std::string &, bool, const std::vector<std::string> &,
bool, int)),
this,
SLOT(got_form_combo_input(const WidgetId &, const std::string &, bool, const std::vector<std::string> &, bool,
int)));
connect(this,
SIGNAL(signal_form_data_combo_input(const WidgetId &, const std::string &, bool,
const std::vector<std::string> &, bool)),
Expand Down Expand Up @@ -585,9 +585,10 @@ void Panel::form_combo_input(const WidgetId & formId,
const std::string & name,
bool required,
const std::vector<std::string> & 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,
Expand Down Expand Up @@ -962,10 +963,11 @@ void Panel::got_form_combo_input(const WidgetId & formId,
const std::string & name,
bool required,
const std::vector<std::string> & values,
bool send_index)
bool send_index,
int def)
{
auto & form = get_widget<FormWidget>(formId);
form.element<form::ComboInput>(name, required, values, send_index);
form.element<form::ComboInput>(name, required, values, send_index, def);
}

void Panel::got_form_data_combo_input(const WidgetId & formId,
Expand Down
9 changes: 6 additions & 3 deletions mc_rtc_rviz_panel/src/Panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class Panel : public CategoryWidget, public mc_control::ControllerClient
const std::string & name,
bool required,
const std::vector<std::string> & values,
bool send_index) override;
bool send_index,
int def) override;

void form_data_combo_input(const WidgetId & formId,
const std::string & name,
Expand Down Expand Up @@ -347,7 +348,8 @@ private slots:
const std::string & name,
bool required,
const std::vector<std::string> & values,
bool send_index);
bool send_index,
int def);
void got_form_data_combo_input(const WidgetId & formId,
const std::string & name,
bool required,
Expand Down Expand Up @@ -466,7 +468,8 @@ private slots:
const std::string & name,
bool required,
const std::vector<std::string> & values,
bool send_index);
bool send_index,
int def);
void signal_form_data_combo_input(const WidgetId & formId,
const std::string & name,
bool required,
Expand Down
2 changes: 1 addition & 1 deletion mc_rtc_rviz_panel/src/Schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 30e2e9e

Please sign in to comment.