BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GUI::View::PropertyEditorFactory Namespace Reference

Description

Creates editors for SessionItems.

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) conversion to string. More...
 
QString toString (const QModelIndex &index)
 Provides string representation of index data. More...
 

Function Documentation

◆ CreateEditor()

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

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

Definition at line 69 of file PropertyEditorFactory.cpp.

70 {
71  QWidget* result(nullptr);
72 
73  if (isDoubleProperty(item.value())) {
74  // only Scientific SpinBoxes in Fit-Window
75  auto* editor = new ScientificSpinBoxEditor;
76  editor->setLimits(item.limits());
77  editor->setDecimals(item.decimals());
78  editor->setSingleStep(getStep(item.roleProperty(Qt::EditRole).toDouble()));
79  result = editor;
80  } else if (isComboProperty(item.value()))
81  result = new ComboPropertyEditor;
82 
83  if (parent && result)
84  result->setParent(parent);
85 
86  return result;
87 }
Editor for ComboProperty variant.
Definition: CustomEditors.h:54
Editor for Double variant using ScientificSpinBox.
Definition: CustomEditors.h:77
void setLimits(const RealLimits &limits)
int decimals() const
QVariant value() const
Get value.
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::limits(), SessionItem::roleProperty(), ScientificSpinBoxEditor::setLimits(), and SessionItem::value().

Referenced by FitParameterDelegate::createEditorFromIndex().

Here is the call graph for this function:

◆ hasStringRepresentation()

bool GUI::View::PropertyEditorFactory::hasStringRepresentation ( const QModelIndex &  index)

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

Definition at line 43 of file PropertyEditorFactory.cpp.

44 {
45  auto variant = index.data();
46  if (isComboProperty(variant))
47  return true;
48  if (isDoubleProperty(variant) && index.internalPointer())
49  return true;
50 
51  return false;
52 }

Referenced by FitParameterDelegate::paint().

◆ toString()

QString GUI::View::PropertyEditorFactory::toString ( const QModelIndex &  index)

Provides string representation of index data.

Definition at line 54 of file PropertyEditorFactory.cpp.

55 {
56  auto variant = index.data();
57  if (isComboProperty(variant))
58  return variant.value<ComboProperty>().label();
59 
60  if (isDoubleProperty(variant) && index.internalPointer()) {
61  auto* item = static_cast<SessionItem*>(index.internalPointer());
62  // only "Scientific SpinBoxes" in Fit-Window
63  return ScientificSpinBox::toString(item->value().toDouble(), item->decimals());
64  }
65 
66  return "";
67 }
Custom property to define list of string values with multiple selections. Intended for QVariant.
Definition: ComboProperty.h:25
static QString toString(double val, int decimal_points)
Base class for a GUI data item.
Definition: SessionItem.h:204

References ScientificSpinBox::toString().

Referenced by JobModel::addJob(), JobItem::beginTime(), AboutDialog::createTextLayout(), JobItem::endTime(), JobItem::getStatus(), InstrumentCollection::insertCopy(), FitParameterDelegate::paint(), GUI::Model::JobFunctions::setupJobItemInstrument(), and GUI::Session::XML::writeUid().

Here is the call graph for this function: