BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::DefaultCellDecorator Class Reference

Generates default cell decorations for Qt trees and tables. More...

Inheritance diagram for ModelView::DefaultCellDecorator:
[legend]
Collaboration diagram for ModelView::DefaultCellDecorator:
[legend]

Public Member Functions

bool hasCustomDecoration (const QModelIndex &index) const override
 
void initStyleOption (QStyleOptionViewItem *option, const QModelIndex &index) override
 

Protected Member Functions

virtual std::optional< std::string > cellText (const QModelIndex &index) const
 

Detailed Description

Generates default cell decorations for Qt trees and tables.

Definition at line 25 of file defaultcelldecorator.h.

Member Function Documentation

◆ cellText()

std::optional< std::string > DefaultCellDecorator::cellText ( const QModelIndex &  index) const
protectedvirtual

Definition at line 31 of file defaultcelldecorator.cpp.

32 {
33  auto variant = index.data();
34 
35  if (Utils::IsComboVariant(variant))
36  return std::optional<std::string>{variant.value<ComboProperty>().label()};
37 
38  else if (Utils::IsBoolVariant(variant))
39  return variant.value<bool>() ? std::optional<std::string>{"True"}
40  : std::optional<std::string>{"False"};
41 
42  else if (Utils::IsExtPropertyVariant(variant))
43  return std::optional<std::string>{variant.value<ExternalProperty>().text()};
44 
45  else if (Utils::IsColorVariant(variant))
46  return std::optional<std::string>{std::string()};
47 
48  else if (Utils::IsDoubleVariant(variant))
49  return std::optional<std::string>{
50  ScientificSpinBox::toString(index.data(Qt::EditRole).value<double>(),
52  .toStdString()};
53 
54  return {};
55 }
Custom property to define list of string values with multiple selections.
Definition: comboproperty.h:27
std::string value() const
Property to carry text, color and identifier.
static QString toString(double val, int decimal_points)
const int default_double_decimals
MVVM_MODEL_EXPORT bool IsColorVariant(const Variant &variant)
Returns true in the case of QColor based variant.
MVVM_MODEL_EXPORT bool IsDoubleVariant(const Variant &variant)
Returns true in the case of double value based variant.
MVVM_MODEL_EXPORT bool IsBoolVariant(const Variant &variant)
Returns true in the case of double value based variant.
MVVM_MODEL_EXPORT bool IsExtPropertyVariant(const Variant &variant)
Returns true in the case of ExternalProperty based variant.
MVVM_MODEL_EXPORT bool IsComboVariant(const Variant &variant)
Returns true in the case of double value based variant.

References ModelView::Constants::default_double_decimals, ModelView::Utils::IsBoolVariant(), ModelView::Utils::IsColorVariant(), ModelView::Utils::IsComboVariant(), ModelView::Utils::IsDoubleVariant(), ModelView::Utils::IsExtPropertyVariant(), ModelView::ScientificSpinBox::toString(), and ModelView::ComboProperty::value().

Referenced by hasCustomDecoration(), and initStyleOption().

Here is the call graph for this function:

◆ hasCustomDecoration()

bool DefaultCellDecorator::hasCustomDecoration ( const QModelIndex &  index) const
overridevirtual

Implements ModelView::CellDecoratorInterface.

Definition at line 26 of file defaultcelldecorator.cpp.

27 {
28  return cellText(index).has_value();
29 }
virtual std::optional< std::string > cellText(const QModelIndex &index) const

References cellText().

Referenced by initStyleOption().

Here is the call graph for this function:

◆ initStyleOption()

void DefaultCellDecorator::initStyleOption ( QStyleOptionViewItem *  option,
const QModelIndex &  index 
)
overridevirtual

Implements ModelView::CellDecoratorInterface.

Definition at line 57 of file defaultcelldecorator.cpp.

58 {
59  if (!hasCustomDecoration(index))
60  return;
61 
62  auto value = cellText(index).value();
63  option->text = QString::fromStdString(value);
64  if (value.empty())
65  option->features &= ~QStyleOptionViewItem::HasDisplay;
66 }
bool hasCustomDecoration(const QModelIndex &index) const override

References cellText(), and hasCustomDecoration().

Here is the call graph for this function:

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