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

Custom property to define list of string values with multiple selections. More...

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. 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
 

Detailed Description

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

Intended for QVariant.

Definition at line 25 of file ComboProperty.h.

Constructor & Destructor Documentation

◆ ComboProperty() [1/2]

ComboProperty::ComboProperty ( )
default

◆ ComboProperty() [2/2]

ComboProperty::ComboProperty ( QStringList  values)
private

Definition at line 26 of file ComboProperty.cpp.

26 : m_values(std::move(values)) {}
QStringList m_values
Definition: ComboProperty.h:68

Member Function Documentation

◆ currentIndex()

int ComboProperty::currentIndex ( ) const

Definition at line 78 of file ComboProperty.cpp.

79 {
80  return m_selected_indices.empty() ? -1 : m_selected_indices.at(0);
81 }
QVector< int > m_selected_indices
Definition: ComboProperty.h:70

References m_selected_indices.

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

◆ fromList()

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

Definition at line 28 of file ComboProperty.cpp.

29 {
30  ComboProperty result(values);
31 
32  if (!current_value.isEmpty())
33  result.setValue(current_value);
34 
35  return result;
36 }
Custom property to define list of string values with multiple selections.
Definition: ComboProperty.h:25

References setValue().

Referenced by ParticleDistributionItem::updateLinkedParameterList(), and ParticleDistributionItem::updateMainParameterList().

Here is the call graph for this function:

◆ getValue()

◆ getValues()

QStringList ComboProperty::getValues ( ) const

◆ label()

QString ComboProperty::label ( ) const

Returns the label to show.

Definition at line 220 of file ComboProperty.cpp.

221 {
222  if (m_selected_indices.size() > 1) {
223  return "Multiple";
224  } else if (m_selected_indices.size() == 1) {
225  return getValue();
226  } else {
227  return "None";
228  }
229 }
QString getValue() const

References getValue(), and m_selected_indices.

Referenced by MultiComboPropertyEditor::updateBoxLabel().

Here is the call graph for this function:

◆ operator!=()

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

Definition at line 117 of file ComboProperty.cpp.

118 {
119  return !(*this == other);
120 }

◆ operator<()

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

Definition at line 122 of file ComboProperty.cpp.

123 {
124  return m_selected_indices.size() < other.m_selected_indices.size()
125  && m_values.size() < other.m_values.size();
126 }

References m_selected_indices, and m_values.

◆ operator<<() [1/2]

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

Definition at line 92 of file ComboProperty.cpp.

93 {
94  m_values.append(str);
95  if (!m_values.empty())
96  setCurrentIndex(0);
97  return *this;
98 }
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 100 of file ComboProperty.cpp.

101 {
102  m_values.append(str);
103  if (!m_values.empty())
104  setCurrentIndex(0);
105  return *this;
106 }

References m_values, and setCurrentIndex().

Here is the call graph for this function:

◆ operator==()

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

Definition at line 108 of file ComboProperty.cpp.

109 {
111  return false;
112  if (m_values != other.m_values)
113  return false;
114  return true;
115 }

References m_selected_indices, and m_values.

◆ selectedIndices()

QVector< int > ComboProperty::selectedIndices ( ) const

Returns vector of selected indices.

Definition at line 155 of file ComboProperty.cpp.

156 {
157  return m_selected_indices;
158 }

References m_selected_indices.

◆ selectedValues()

QStringList ComboProperty::selectedValues ( ) const

Returns list of string with selected values;.

Definition at line 162 of file ComboProperty.cpp.

163 {
164  QStringList result;
165  for (auto index : m_selected_indices)
166  result.append(m_values.at(index));
167  return result;
168 }

References m_selected_indices, and m_values.

Referenced by ParticleDistributionItem::updateLinkedParameterList().

◆ setCurrentIndex()

void ComboProperty::setCurrentIndex ( int  index)

Definition at line 83 of file ComboProperty.cpp.

84 {
85  if (index < 0 || index >= m_values.size())
86  throw GUIHelpers::Error("ComboProperty::setCurrentIndex(int index) -> Error. "
87  "Invalid index");
88  m_selected_indices.clear();
89  m_selected_indices.push_back(index);
90 }

References m_selected_indices, and m_values.

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

◆ setSelected() [1/2]

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

Definition at line 187 of file ComboProperty.cpp.

188 {
189  setSelected(m_values.indexOf(name), value);
190 }
void setSelected(int index, bool value=true)
Sets given index selection flag.
QString const & name(EShape k)
Definition: particles.cpp:21

References m_values, 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 173 of file ComboProperty.cpp.

174 {
175  if (index < 0 || index >= m_values.size())
176  return;
177 
178  if (value) {
179  if (!m_selected_indices.contains(index))
180  m_selected_indices.push_back(index);
181  } else {
182  m_selected_indices.removeAll(index);
183  }
184  std::sort(m_selected_indices.begin(), m_selected_indices.end());
185 }

References m_selected_indices, and m_values.

Referenced by MultiComboPropertyEditor::onModelDataChanged(), setSelected(), setStringOfSelections(), and ParticleDistributionItem::updateLinkedParameterList().

◆ setStringOfSelections()

void ComboProperty::setStringOfSelections ( const QString &  values)

Sets selected indices from string.

Definition at line 204 of file ComboProperty.cpp.

205 {
206  m_selected_indices.clear();
207  if (values.isEmpty())
208  return;
209 
210  for (auto str : values.split(selection_separator)) {
211  bool success(false);
212  int num = str.toInt(&success);
213  if (success)
214  setSelected(num, true);
215  }
216 }

References m_selected_indices, and setSelected().

Referenced by SessionXML::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 137 of file ComboProperty.cpp.

138 {
139  QString current = getValue();
140  m_values = values.split(value_separator);
141  setCurrentIndex(m_values.contains(current) ? m_values.indexOf(current) : 0);
142 }

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

Referenced by SessionXML::readProperty().

Here is the call graph for this function:

◆ setToolTips()

void ComboProperty::setToolTips ( const QStringList &  tooltips)

Definition at line 73 of file ComboProperty.cpp.

74 {
75  m_tooltips = tooltips;
76 }
QStringList m_tooltips
Definition: ComboProperty.h:69

References m_tooltips.

Referenced by SimulationOptionsItem::SimulationOptionsItem(), and MinimizerItemCatalog::algorithmCombo().

◆ setValue()

void ComboProperty::setValue ( const QString &  name)

◆ 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 59 of file ComboProperty.cpp.

60 {
61  ASSERT(values.size());
62  QString current = getValue();
63  m_values = values;
64  setCurrentIndex(m_values.contains(current) ? m_values.indexOf(current) : 0);
65 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT, 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 194 of file ComboProperty.cpp.

195 {
196  QStringList text;
197  for (auto index : m_selected_indices)
198  text.append(QString::number(index));
199  return text.join(selection_separator);
200 }

References m_selected_indices.

Referenced by SessionXML::writeVariant().

◆ stringOfValues()

QString ComboProperty::stringOfValues ( ) const

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

Definition at line 130 of file ComboProperty.cpp.

131 {
132  return m_values.join(value_separator);
133 }

References m_values.

Referenced by SessionXML::writeVariant().

◆ toolTips()

QStringList ComboProperty::toolTips ( ) const

returns list of tool tips for all values

Definition at line 68 of file ComboProperty.cpp.

69 {
70  return m_tooltips;
71 }

References m_tooltips.

◆ variant()

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: