21 const std::string value_separator =
";";
22 const std::string selection_separator =
",";
23 const std::string multiple_label =
"Multiple";
24 const std::string none_label =
"None";
26 template <
typename C,
typename T> std::string
toString(
const C& container,
const T& delim)
28 std::stringstream result;
29 for (
auto it = container.begin(); it != container.end(); ++it) {
31 if (std::distance(it, container.end()) != 1)
37 std::vector<std::string> tokenize(
const std::string& str,
const std::string& delimeter)
39 std::vector<std::string> result;
40 size_t start = str.find_first_not_of(delimeter);
43 while (start != std::string::npos) {
45 end = str.find(delimeter, start);
47 result.push_back(str.substr(start, end - start));
49 start = str.find_first_not_of(delimeter, end);
62 const std::string& current_value)
66 if (!current_value.empty())
82 throw std::runtime_error(
"ComboProperty::setValue() -> Error. Combo doesn't contain "
100 auto current =
value();
123 if (index < 0 || index >=
static_cast<int>(
m_values.size()))
124 throw std::runtime_error(
"ComboProperty::setCurrentIndex(int index) -> Error. "
157 return !(*
this == other);
176 auto current =
value();
192 std::vector<std::string> result;
194 result.push_back(
m_values.at(
static_cast<size_t>(index)));
203 if (index < 0 || index >=
static_cast<int>(
m_values.size()))
226 std::vector<std::string> text;
228 text.push_back(std::to_string(index));
229 return toString(text, selection_separator);
240 for (
const auto& str : tokenize(
values, selection_separator)) {
241 int num = std::stoi(str);
251 return multiple_label;
Custom property to define list of string values with multiple selections.
std::vector< std::string > toolTips() const
returns list of tool tips for all values
std::vector< int > selectedIndices() const
Returns vector of selected indices.
std::string label() const
Returns the label to show.
std::vector< std::string > m_tooltips
void setStringOfSelections(const std::string &values)
Sets selected indices from string.
bool operator==(const ComboProperty &other) const
bool operator<(const ComboProperty &other) const
std::string stringOfValues() const
Returns a single string containing values delimited with ';'.
void setStringOfValues(const std::string &values)
Sets values from the string containing delimeter ';'.
std::vector< std::string > m_values
void setSelected(int index, bool value=true)
Sets given index selection flag.
std::string value() const
void setValue(const std::string &name)
ComboProperty & operator<<(const std::string &str)
std::vector< std::string > values() const
void setValues(const std::vector< std::string > &values)
Sets new list of values. Current value will be preserved, if exists in a new list.
std::string stringOfSelections() const
Return string with coma separated list of selected indices.
void setToolTips(const std::vector< std::string > &tooltips)
bool operator!=(const ComboProperty &other) const
std::vector< std::string > selectedValues() const
Returns list of string with selected values;.
static ComboProperty createFrom(const std::vector< std::string > &values, const std::string ¤t_value={})
std::vector< int > m_selected_indices
void setCurrentIndex(int index)
bool Contains(const A &container, const B &element)
Returns true if container contains a given element.
int IndexOfItem(It begin, It end, const T &item)
Returns index corresponding to the first occurance of the item in the container.
materialitems.h Collection of materials to populate MaterialModel.
std::string toString(PyObject *obj)
Converts PyObject into string, if possible, or throws exception.
QString const & name(EShape k)