| 148 | } |
| 149 | |
| 150 | void PropertyEditor::addItemToForm(const mx::UIPropertyItem& item, const std::string& group, |
| 151 | ng::ref<ng::Widget> container, Viewer* viewer, bool editable) |
| 152 | { |
| 153 | const mx::UIProperties& ui = item.ui; |
| 154 | mx::ValuePtr value = item.variable->getValue(); |
| 155 | if (!value) |
| 156 | { |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | std::string label = item.label; |
| 161 | const std::string& unit = item.variable->getUnit(); |
| 162 | if (!unit.empty()) |
| 163 | { |
| 164 | label += std::string(" (") + unit + std::string(")"); |
| 165 | } |
| 166 | const std::string& path = item.variable->getPath(); |
| 167 | const mx::StringVec& enumeration = ui.enumeration; |
| 168 | const std::vector<mx::ValuePtr> enumValues = ui.enumerationValues; |
| 169 | |
| 170 | if (!group.empty()) |
| 171 | { |
| 172 | ng::ref<ng::Widget> twoColumns = new ng::Widget(container); |
| 173 | twoColumns->set_layout(_gridLayout2); |
| 174 | ng::ref<ng::Label> groupLabel = new ng::Label(twoColumns, group); |
| 175 | groupLabel->set_font_size(20); |
| 176 | groupLabel->set_font("sans-bold"); |
| 177 | new ng::Label(twoColumns, ""); |
| 178 | } |
| 179 | |
| 180 | // Integer input. Can map to a combo box if an enumeration |
| 181 | if (value->isA<int>()) |
| 182 | { |
| 183 | const size_t INVALID_INDEX = std::numeric_limits<size_t>::max(); |
| 184 | auto indexInEnumeration = [&value, &enumValues, &enumeration]() |
| 185 | { |
| 186 | size_t index = 0; |
| 187 | for (auto& enumValue : enumValues) |
| 188 | { |
| 189 | if (value->getValueString() == enumValue->getValueString()) |
| 190 | { |
| 191 | return index; |
| 192 | } |
| 193 | index++; |
| 194 | } |
| 195 | index = 0; |
| 196 | for (auto& enumName : enumeration) |
| 197 | { |
| 198 | if (value->getValueString() == enumName) |
| 199 | { |
| 200 | return index; |
| 201 | } |
| 202 | index++; |
| 203 | } |
| 204 | return std::numeric_limits<size_t>::max(); // INVALID_INDEX; |
| 205 | }; |
| 206 | |
| 207 | // Create a combo box. The items are the enumerations in order. |
nothing calls this directly
no test coverage detected