5 #include <SimoxUtility/algorithm/string/string_conversion.h>
9 #include "../../ColorPalettes.h"
10 #include "../visitors/AronTreeWidgetConverter.h"
15 QTreeWidgetItem* currentItem) :
18 auto names = enumPtr->getAcceptedValueNames();
19 auto outerLayout =
new QHBoxLayout();
20 outerLayout->setContentsMargins(0, 0, 0, 0);
21 innerWidget =
new QComboBox();
22 outerLayout->addWidget(innerWidget);
24 for (
const auto& n :
names)
26 innerWidget->addItem(n.c_str());
28 innerWidget->setInsertPolicy(QComboBox::NoInsert);
29 innerWidget->setEditable(
true);
30 innerWidget->setCurrentIndex(0);
32 setLayout(outerLayout);
34 SIGNAL(currentTextChanged(
const QString&)),
36 SLOT(textChanged(
const QString&))));
66 innerWidget->setEditText(text);
67 highlightUnparsableEntries();
73 return innerWidget->currentText();
76 std::pair<bool, aron::data::IntPtr>
79 auto crAron = std::make_shared<aron::data::Int>(element_type->getPath());
82 auto valueMap = element_type->getAcceptedValueMap();
83 std::string toParse =
getText().toStdString();
85 auto searchRes = valueMap.find(toParse);
86 if (searchRes != valueMap.end())
88 crAron->setValue(searchRes->second);
89 return {
true, crAron};
92 auto accVals = element_type->getAcceptedValues();
96 res = simox::alg::to_<int>(toParse);
98 catch (
const simox::error::SimoxError& err)
100 ARMARX_VERBOSE <<
"Failed to parse IntEnum: Could not convert \'" << toParse
101 <<
"\' to an int. It also was not one of the accepted strings.";
102 return {
false,
nullptr};
104 if (std::find(accVals.begin(), accVals.end(), res) != accVals.end())
107 crAron->setValue(res);
112 <<
"but this int is not part of the accepted values.";
113 return {
false,
nullptr};
115 return {
true, crAron};
119 IntEnumWidget::highlightUnparsableEntries()
133 IntEnumWidget::textChanged(
const QString&)
136 highlightUnparsableEntries();