BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ComboProperty Class Reference

Description

Custom property to define list of string values with multiple selections. Intended for QVariant.

Definition at line 25 of file ComboProperty.h.

Public Member Functions

 ComboProperty ()
 
int currentIndex () const
 
QString getValue () const
 
QStringList getValues () const
 
QString label () const
 Returns the label to show. More...
 
bool operator!= (const ComboProperty &other) const
 
bool operator< (const ComboProperty &other) const
 
ComboPropertyoperator<< (const QString &str)
 
ComboPropertyoperator<< (const QStringList &str)
 
bool operator== (const ComboProperty &other) const
 
QVector< int > selectedIndices () const
 Returns vector of selected indices. More...
 
QStringList selectedValues () const
 Returns list of string with selected values;. More...
 
void setCurrentIndex (int index)
 
void setSelected (const QString &name, bool value=true)
 
void setSelected (int index, bool value=true)
 Sets given index selection flag. If false, index will be excluded from selection. More...
 
void setStringOfSelections (const QString &values)
 Sets selected indices from string. More...
 
void setStringOfValues (const QString &values)
 Sets values from the string containing delimeter ';'. More...
 
void setToolTips (const QStringList &tooltips)
 
void setValue (const QString &name)
 
void setValues (const QStringList &values)
 Sets new list of values. Current value will be preserved, if exists in a new list. More...
 
QString stringOfSelections () const
 Return string with coma separated list of selected indices. More...
 
QString stringOfValues () const
 Returns a single string containing values delimited with ';'. More...
 
QStringList toolTips () const
 Returns list of tool tips for all values. More...
 
QVariant variant () const
 Constructs variant enclosing given ComboProperty. More...
 

Static Public Member Functions

static ComboProperty fromList (const QStringList &values, const QString &current_value="")
 

Private Member Functions

 ComboProperty (QStringList values)
 

Private Attributes

QVector< int > m_selected_indices
 
QStringList m_tooltips
 
QStringList m_values
 

Constructor & Destructor Documentation

◆ ComboProperty() [1/2]

ComboProperty::ComboProperty ( )
default

◆ ComboProperty() [2/2]

ComboProperty::ComboProperty ( QStringList  values)
private

Definition at line 28 of file ComboProperty.cpp.

29  : m_values(std::move(values))
30 {
31 }
QStringList m_values
Definition: ComboProperty.h:68

Member Function Documentation

◆ currentIndex()

int ComboProperty::currentIndex ( ) const

Definition at line 83 of file ComboProperty.cpp.

84 {
85  return m_selected_indices.empty() ? -1 : m_selected_indices.at(0);
86 }
QVector< int > m_selected_indices
Definition: ComboProperty.h:70

References m_selected_indices.

Referenced by getValue(), and ComboPropertyEditor::internIndex().

◆ fromList()

ComboProperty ComboProperty::fromList ( const QStringList &  values,
const QString &  current_value = "" 
)
static

Definition at line 33 of file ComboProperty.cpp.

34 {
35  ComboProperty result(values);
36 
37  if (!current_value.isEmpty())
38  result.setValue(current_value);
39 
40  return result;
41 }
Custom property to define list of string values with multiple selections. Intended for QVariant.
Definition: ComboProperty.h:25

References setValue().

Referenced by DataItem::DataItem().

Here is the call graph for this function:

◆ getValue()

QString ComboProperty::getValue ( ) const

Definition at line 43 of file ComboProperty.cpp.

44 {
45  return currentIndex() < 0 ? QString() : m_values.at(currentIndex());
46 }
int currentIndex() const

References currentIndex(), and m_values.

Referenced by IntensityDataCanvas::applyPersistentSettings(), IntensityDataItem::getGradientValue(), label(), FitParameterItem::parameterType(), setStringOfValues(), and setValues().

Here is the call graph for this function:

◆ getValues()

QStringList ComboProperty::getValues ( ) const

Definition at line 57 of file ComboProperty.cpp.

58 {
59  return m_values;
60 }

References m_values.

Referenced by ComboPropertyEditor::internLabels().

◆ label()

QString ComboProperty::label ( ) const

Returns the label to show.

Definition at line 225 of file ComboProperty.cpp.

226 {
227  if (m_selected_indices.size() > 1)
228  return "Multiple";
229  if (m_selected_indices.size() == 1)
230  return getValue();
231  return "None";
232 }
QString getValue() const

References getValue(), and m_selected_indices.

Here is the call graph for this function:

◆ operator!=()

bool ComboProperty::operator!= ( const ComboProperty other) const

Definition at line 122 of file ComboProperty.cpp.

123 {
124  return !(*this == other);
125 }
@ other
The unit has no enum value defined in here (e.g. when defined as an explicit string)

References other.

◆ operator<()

bool ComboProperty::operator< ( const ComboProperty other) const

Definition at line 127 of file ComboProperty.cpp.

128 {
129  return m_selected_indices.size() < other.m_selected_indices.size()
130  && m_values.size() < other.m_values.size();
131 }

References m_selected_indices, m_values, and other.

◆ operator<<() [1/2]

ComboProperty & ComboProperty::operator<< ( const QString &  str)

Definition at line 97 of file ComboProperty.cpp.

98 {
99  m_values.append(str);
100  if (!m_values.empty())
101  setCurrentIndex(0);
102  return *this;
103 }
void setCurrentIndex(int index)

References m_values, and setCurrentIndex().

Here is the call graph for this function:

◆ operator<<() [2/2]

ComboProperty & ComboProperty::operator<< ( const QStringList &  str)

Definition at line 105 of file ComboProperty.cpp.

106 {
107  m_values.append(str);
108  if (!m_values.empty())
109  setCurrentIndex(0);
110  return *this;
111 }

References m_values, and setCurrentIndex().

Here is the call graph for this function:

◆ operator==()

bool ComboProperty::operator== ( const ComboProperty other) const

Definition at line 113 of file ComboProperty.cpp.

114 {
115  if (m_selected_indices != other.m_selected_indices)
116  return false;
117  if (m_values != other.m_values)
118  return false;
119  return true;
120 }

References m_selected_indices, m_values, and other.

◆ selectedIndices()

QVector< int > ComboProperty::selectedIndices ( ) const

Returns vector of selected indices.

Definition at line 160 of file ComboProperty.cpp.

161 {
162  return m_selected_indices;
163 }

References m_selected_indices.

◆ selectedValues()

QStringList ComboProperty::selectedValues ( ) const

Returns list of string with selected values;.

Definition at line 167 of file ComboProperty.cpp.

168 {
169  QStringList result;
170  for (auto index : m_selected_indices)
171  result.append(m_values.at(index));
172  return result;
173 }

References m_selected_indices, and m_values.

◆ setCurrentIndex()

void ComboProperty::setCurrentIndex ( int  index)

Definition at line 88 of file ComboProperty.cpp.

89 {
90  if (index < 0 || index >= m_values.size())
91  throw Error("ComboProperty::setCurrentIndex(int index) -> Error. "
92  "Invalid index");
93  m_selected_indices.clear();
94  m_selected_indices.push_back(index);
95 }

References Error, m_selected_indices, and m_values.

Referenced by SelectionDescriptor< T >::SelectionDescriptor(), GroupItemController::createCombo(), ComboPropertyEditor::onIndexChanged(), operator<<(), setStringOfValues(), setValue(), and setValues().

◆ setSelected() [1/2]

void ComboProperty::setSelected ( const QString &  name,
bool  value = true 
)

Definition at line 192 of file ComboProperty.cpp.

193 {
194  setSelected(m_values.indexOf(name), value);
195 }
void setSelected(int index, bool value=true)
Sets given index selection flag. If false, index will be excluded from selection.
QString const & name(EShape k)
Definition: particles.cpp:20

References m_values, GUI::RealSpace::Particles::name(), and setSelected().

Here is the call graph for this function:

◆ setSelected() [2/2]

void ComboProperty::setSelected ( int  index,
bool  value = true 
)

Sets given index selection flag. If false, index will be excluded from selection.

Definition at line 178 of file ComboProperty.cpp.

179 {
180  if (index < 0 || index >= m_values.size())
181  return;
182 
183  if (value) {
184  if (!m_selected_indices.contains(index))
185  m_selected_indices.push_back(index);
186  } else {
187  m_selected_indices.removeAll(index);
188  }
189  std::sort(m_selected_indices.begin(), m_selected_indices.end());
190 }

References m_selected_indices, and m_values.

Referenced by setSelected(), and setStringOfSelections().

◆ setStringOfSelections()

void ComboProperty::setStringOfSelections ( const QString &  values)

Sets selected indices from string.

Definition at line 209 of file ComboProperty.cpp.

210 {
211  m_selected_indices.clear();
212  if (values.isEmpty())
213  return;
214 
215  for (const auto& str : values.split(selection_separator)) {
216  bool success(false);
217  int num = str.toInt(&success);
218  if (success)
219  setSelected(num, true);
220  }
221 }

References m_selected_indices, and setSelected().

Referenced by GUI::Session::XML::readProperty().

Here is the call graph for this function:

◆ setStringOfValues()

void ComboProperty::setStringOfValues ( const QString &  values)

Sets values from the string containing delimeter ';'.

Definition at line 142 of file ComboProperty.cpp.

143 {
144  QString current = getValue();
145  m_values = values.split(value_separator);
146  setCurrentIndex(m_values.contains(current) ? m_values.indexOf(current) : 0);
147 }

References getValue(), m_values, and setCurrentIndex().

Referenced by GUI::Session::XML::readProperty().

Here is the call graph for this function:

◆ setToolTips()

void ComboProperty::setToolTips ( const QStringList &  tooltips)

Definition at line 78 of file ComboProperty.cpp.

79 {
80  m_tooltips = tooltips;
81 }
QStringList m_tooltips
Definition: ComboProperty.h:69

References m_tooltips.

Referenced by MinimizerItemCatalog::algorithmCombo().

◆ setValue()

void ComboProperty::setValue ( const QString &  name)

Definition at line 48 of file ComboProperty.cpp.

49 {
50  if (!m_values.contains(name))
51  throw Error("ComboProperty::setValue() -> Error. Combo doesn't contain "
52  "value "
53  + name);
54  setCurrentIndex(m_values.indexOf(name));
55 }

References Error, m_values, GUI::RealSpace::Particles::name(), and setCurrentIndex().

Referenced by MinimizerContainerItem::MinimizerContainerItem(), IntensityDataCanvas::applyPersistentSettings(), GUI::Model::JobItemUtils::availableUnits(), and fromList().

Here is the call graph for this function:

◆ setValues()

void ComboProperty::setValues ( const QStringList &  values)

Sets new list of values. Current value will be preserved, if exists in a new list.

Definition at line 64 of file ComboProperty.cpp.

65 {
66  ASSERT(values.size());
67  QString current = getValue();
68  m_values = values;
69  setCurrentIndex(m_values.contains(current) ? m_values.indexOf(current) : 0);
70 }

References getValue(), m_values, and setCurrentIndex().

Referenced by GroupItemController::createCombo().

Here is the call graph for this function:

◆ stringOfSelections()

QString ComboProperty::stringOfSelections ( ) const

Return string with coma separated list of selected indices.

Definition at line 199 of file ComboProperty.cpp.

200 {
201  QStringList text;
202  for (auto index : m_selected_indices)
203  text.append(QString::number(index));
204  return text.join(selection_separator);
205 }

References m_selected_indices.

◆ stringOfValues()

QString ComboProperty::stringOfValues ( ) const

Returns a single string containing values delimited with ';'.

Definition at line 135 of file ComboProperty.cpp.

136 {
137  return m_values.join(value_separator);
138 }

References m_values.

◆ toolTips()

QStringList ComboProperty::toolTips ( ) const

Returns list of tool tips for all values.

Definition at line 73 of file ComboProperty.cpp.

74 {
75  return m_tooltips;
76 }

References m_tooltips.

◆ variant()

QVariant ComboProperty::variant ( ) const

Constructs variant enclosing given ComboProperty.

Definition at line 151 of file ComboProperty.cpp.

152 {
153  QVariant result;
154  result.setValue(*this);
155  return result;
156 }

Referenced by MinimizerContainerItem::MinimizerContainerItem(), GroupItemController::createCombo(), GUI::Session::XML::readProperty(), Data1DViewItem::setAxesUnits(), and DataItem::setAxesUnits().

Member Data Documentation

◆ m_selected_indices

QVector<int> ComboProperty::m_selected_indices
private

◆ m_tooltips

QStringList ComboProperty::m_tooltips
private

Definition at line 69 of file ComboProperty.h.

Referenced by setToolTips(), and toolTips().

◆ m_values

QStringList ComboProperty::m_values
private

The documentation for this class was generated from the following files: