5#include <SimoxUtility/algorithm/string/string_conversion.h>
6#include <SimoxUtility/error/SimoxError.h>
14 QTreeWidgetItem* currentItem) :
17 auto outerLayout =
new QHBoxLayout();
18 outerLayout->setContentsMargins(0, 0, 0, 0);
19 innerWidget =
new QComboBox();
20 outerLayout->addWidget(innerWidget);
22 for (
const auto& [name, value] : enumPtr->getAcceptedValueMap())
24 innerWidget->addItem(QString::fromStdString(toDisplayText(name, value)));
26 innerWidget->setInsertPolicy(QComboBox::NoInsert);
27 innerWidget->setEditable(
true);
28 innerWidget->setCurrentIndex(0);
30 setLayout(outerLayout);
32 SIGNAL(currentTextChanged(
const QString&)),
34 SLOT(textChanged(
const QString&))));
62 IntEnumWidget::toDisplayText(
const std::string& name,
int value)
64 return name +
" (" + std::to_string(value) +
")";
67 std::optional<std::pair<std::string, int>>
68 IntEnumWidget::resolveText(
const std::string& text)
const
70 const auto valueMap = element_type->getAcceptedValueMap();
73 for (
const auto& [name, value] : valueMap)
75 if (text == toDisplayText(name, value) || text == name)
77 return std::make_pair(name, value);
84 const int parsed = simox::alg::to_<int>(text);
85 for (
const auto& [name, value] : valueMap)
89 return std::make_pair(name, value);
93 catch (
const simox::error::SimoxError&)
105 if (
const auto resolved = resolveText(text.toStdString()))
107 innerWidget->setEditText(
108 QString::fromStdString(toDisplayText(resolved->first, resolved->second)));
112 innerWidget->setEditText(text);
114 highlightUnparsableEntries();
120 return innerWidget->currentText();
123 std::pair<bool, aron::data::IntPtr>
128 const std::string toParse =
getText().toStdString();
129 const auto resolved = resolveText(toParse);
130 if (not resolved.has_value())
133 <<
"\' is neither an accepted name nor an accepted value.";
134 return {
false,
nullptr};
137 auto crAron = std::make_shared<aron::data::Int>(element_type->getPath());
138 crAron->setValue(resolved->second);
139 return {
true, crAron};
143 IntEnumWidget::highlightUnparsableEntries()
157 IntEnumWidget::textChanged(
const QString&)
160 highlightUnparsableEntries();
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_VERBOSE
The logging level for verbose information.
std::shared_ptr< IntEnum > IntEnumPtr
QPalette getErrorPalette()
QPalette getNormalPalette()