BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
PropertyEditorFactory Namespace Reference

Creates editors for SessionItem's values. More...

Functions

QWidget * CreateEditor (const SessionItem &item, QWidget *parent=nullptr)
 Creates an editor suitable for editing of item.value() More...
 
bool hasStringRepresentation (const QModelIndex &index)
 Returns true if the index data has known (custom) convertion to string. More...
 
QString toString (const QModelIndex &index)
 Provides string representation of index data. More...
 

Detailed Description

Creates editors for SessionItem's values.

Function Documentation

◆ CreateEditor()

QWidget * PropertyEditorFactory::CreateEditor ( const SessionItem item,
QWidget *  parent = nullptr 
)

Creates an editor suitable for editing of item.value()

Definition at line 101 of file PropertyEditorFactory.cpp.

102 {
103  QWidget* result(nullptr);
104 
105  if (isDoubleProperty(item.value())) {
106  if (item.editorType() == "ScientificDouble") {
107  auto editor = new ScientificDoublePropertyEditor;
108  auto limits = item.limits();
109  editor->setLimits(limits);
110  result = editor;
111  } else if (item.editorType() == "ScientificSpinBox") {
112  auto editor = new ScientificSpinBoxEditor;
113  auto limits = item.limits();
114  editor->setLimits(limits);
115  editor->setDecimals(item.decimals());
116  editor->setSingleStep(getStep(item.roleProperty(Qt::EditRole).toDouble()));
117  result = editor;
118  } else {
119  auto editor = new DoubleEditor;
120  editor->setLimits(item.limits());
121  editor->setDecimals(item.decimals());
122  result = editor;
123  }
124  } else if (isIntProperty(item.value())) {
125  auto editor = new IntEditor;
126  editor->setLimits(item.limits());
127  result = editor;
128  } else if (isBoolProperty(item.value())) {
129  auto editor = new BoolEditor;
130  result = editor;
131  } else if (isStringProperty(item.value())) {
132  result = createCustomStringEditor(item);
133  } else if (isExternalProperty(item.value())) {
134  auto editor = new ExternalPropertyEditor;
135  if (item.editorType() != "Default")
136  editor->setExternalDialogType(item.editorType());
137  result = editor;
138  } else if (isComboProperty(item.value())) {
139  if (item.editorType() == "Default") {
140  auto editor = new ComboPropertyEditor;
141  result = editor;
142  } else if (item.editorType() == "MultiSelectionComboEditor") {
143  auto editor = new MultiComboPropertyEditor;
144  result = editor;
145  }
146  }
147  if (parent && result)
148  result->setParent(parent);
149 
150  return result;
151 }
Editor for ComboProperty variant.
Definition: CustomEditors.h:72
Editor for Double variant.
void setLimits(const RealLimits &limits)
Editor for ExternalProperty variant.
Definition: CustomEditors.h:50
void setExternalDialogType(const QString &dialogType)
Editor for Int variant.
void setLimits(const RealLimits &limits)
Provides custom editor for ComboProperty with multi-select option.
void setLimits(double xmin, double xmax)
Sets lower and upper limits.
Definition: RealLimits.cpp:84
Editor for ScientificDoubleProperty variant.
Definition: CustomEditors.h:95
Editor for Double variant using ScientificSpinBox.
int decimals() const
QVariant value() const
Get value.
QString editorType() const
QVariant roleProperty(int role) const
Returns corresponding variant under given role, invalid variant when role is not present.
RealLimits limits() const

References SessionItem::decimals(), SessionItem::editorType(), SessionItem::limits(), SessionItem::roleProperty(), ExternalPropertyEditor::setExternalDialogType(), DoubleEditor::setLimits(), IntEditor::setLimits(), RealLimits::setLimits(), and SessionItem::value().

Referenced by ComponentFlatView::createWidget().

Here is the call graph for this function:

◆ hasStringRepresentation()

bool PropertyEditorFactory::hasStringRepresentation ( const QModelIndex &  index)

Returns true if the index data has known (custom) convertion to string.

Definition at line 64 of file PropertyEditorFactory.cpp.

65 {
66  auto variant = index.data();
67  if (isExternalProperty(variant))
68  return true;
69  if (isComboProperty(variant))
70  return true;
71  if (isBoolProperty(variant))
72  return true;
73  if (isDoubleProperty(variant) && index.internalPointer())
74  return true;
75 
76  return false;
77 }

Referenced by SessionModelDelegate::paint().

◆ toString()

QString PropertyEditorFactory::toString ( const QModelIndex &  index)

Provides string representation of index data.

Definition at line 79 of file PropertyEditorFactory.cpp.

80 {
81  auto variant = index.data();
82  if (isExternalProperty(variant))
83  return variant.value<ExternalProperty>().text();
84  if (isComboProperty(variant))
85  return variant.value<ComboProperty>().label();
86  if (isBoolProperty(variant))
87  return variant.toBool() ? "True" : "False";
88 
89  if (isDoubleProperty(variant) && index.internalPointer()) {
90  auto item = static_cast<SessionItem*>(index.internalPointer());
91  return item->editorType() == "ScientificDouble"
92  ? QString::number(item->value().toDouble(), 'g')
93  : item->editorType() == "ScientificSpinBox"
94  ? ScientificSpinBox::toString(item->value().toDouble(), item->decimals())
95  : QString::number(item->value().toDouble(), 'f', item->decimals());
96  }
97 
98  return "";
99 }
Custom property to define list of string values with multiple selections.
Definition: ComboProperty.h:25
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
std::string toString(PyObject *obj)
Converts PyObject into string, if possible, or throws exception.
Definition: PyUtils.cpp:24

References SessionItem::editorType(), and ScientificSpinBox::toString().

Referenced by SessionModelDelegate::paint().

Here is the call graph for this function: