19 #include <QFormLayout>
27 std::string::size_type pos = name.find_last_of(
'.');
28 if (pos == std::string::npos)
30 label = QString::fromStdString(name);
32 else if (pos < name.length() - 1)
34 label = QString::fromStdString(name.substr(pos + 1));
39 static QWidget *
GetAnyWidget(
const std::string &name,
const us::Any &any,
const std::string &defaultValue)
41 const std::type_info &anyType = any.
Type();
43 if (anyType ==
typeid(std::string))
47 else if (anyType ==
typeid(std::vector<std::string>))
59 else if (anyType ==
typeid(
bool))
63 else if (anyType ==
typeid(
short))
67 else if (anyType ==
typeid(
int))
71 else if (anyType ==
typeid(
unsigned short))
75 else if (anyType ==
typeid(
unsigned int))
79 else if (anyType ==
typeid(
float))
83 else if (anyType ==
typeid(
double))
96 Options filteredOptions = options;
97 std::map<std::string, std::string> optionToDefaultValue;
98 for (
const auto &option : options)
100 const std::string &name = option.first;
101 if (name.size() > 4 && name.substr(name.size() - 4) ==
"enum")
103 filteredOptions.erase(name);
105 std::string nameWithoutEnum = name.substr(0, name.size() - 5);
106 us::Any value = filteredOptions[nameWithoutEnum];
109 optionToDefaultValue[nameWithoutEnum] = value.
ToString();
111 filteredOptions[nameWithoutEnum] = option.second;
115 auto formLayout =
new QFormLayout();
116 for (Options::const_iterator iter = filteredOptions.begin(), iterEnd = filteredOptions.end(); iter != iterEnd; ++iter)
119 GetAnyWidget(iter->first, iter->second, optionToDefaultValue[iter->first]));
122 this->setLayout(formLayout);
129 QFormLayout *layout = qobject_cast<QFormLayout *>(this->layout());
130 const int rows = layout->rowCount();
131 for (
int i = 0; i < rows; ++i)
136 options.insert(std::make_pair(anyAdapter->
GetName(), anyAdapter->
GetAny()));
145 this->setText(QString::fromStdString(any.
ToString()));
150 return us::Any(this->text().toStdString());
156 this->setChecked(us::any_cast<bool>(any));
161 return us::Any(this->isChecked());
168 this->setValue(us::any_cast<short>(any));
173 return us::Any(static_cast<short>(this->value()));
180 this->setValue(us::any_cast<unsigned short>(any));
185 return us::Any(static_cast<unsigned short>(this->value()));
192 this->setValue(us::any_cast<int>(any));
204 this->setValue(us::any_cast<unsigned int>(any));
209 return us::Any(static_cast<unsigned int>(this->value()));
216 this->setValue(static_cast<double>(us::any_cast<float>(any)));
221 return us::Any(static_cast<float>(this->value()));
228 this->setValue(us::any_cast<double>(any));
239 this->setText(QString(
"Unknown option type '%1'").arg(any.
Type().name()));
249 const QString &defaultValue,
253 const std::vector<std::string> &entries =
us::ref_any_cast<std::vector<std::string>>(any);
255 int defaultIndex = 0;
256 for (
auto iter = entries.begin(), iterEnd = entries.end(); iter != iterEnd; ++iter, ++index)
258 QString item = QString::fromStdString(*iter);
260 if (item == defaultValue)
262 defaultIndex = index;
265 this->setCurrentIndex(defaultIndex);
270 return us::Any(std::string(this->currentText().toStdString()));
const std::type_info & Type() const
virtual us::Any GetAny() const =0
std::string ToString() const
const ValueType & ref_any_cast(const Any &operand)
std::string GetName() const