OptionProperty: ability to get the string description by passing a value

string getDescriptionByValue(int)
This commit is contained in:
Matthew Territo
2016-07-27 09:25:28 -06:00
parent 98e7b62834
commit f53c4b6193
2 changed files with 15 additions and 1 deletions

View File

@@ -96,7 +96,7 @@ public:
/**
* Returns the list of available options.
* /return The list of available options
* \return The list of available options
*/
const std::vector<Option>& options() const;
@@ -107,6 +107,12 @@ public:
*/
void setValue(int value) override;
/**
* Get the description of the option that matches <code>value</code>
* \param value The value of the option
*/
std::string getDescriptionByValue(int value);
private:
static const std::string OptionsKey;
std::string generateAdditionalDescription() const;

View File

@@ -103,6 +103,14 @@ void OptionProperty::setValue(int value) {
LERROR("Could not find an option for value '" << value << "' in OptionProperty");
}
std::string OptionProperty::getDescriptionByValue(int value) {
for (auto option : _options) {
if (option.value == value) {
return option.description;
}
}
}
std::string OptionProperty::generateAdditionalDescription() const {
// @REFACTOR from selectionproperty.cpp, possible refactoring? ---abock
std::string result;