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

Description

Tracks property change (axes range, units etc) for the collection of IntensityDataItems and sets same properties for all of them.

Definition at line 27 of file PropertyRepeater.h.

Inheritance diagram for PropertyRepeater:
[legend]
Collaboration diagram for PropertyRepeater:
[legend]

Public Member Functions

 PropertyRepeater (QObject *parent=nullptr, bool repeat_child_properties=false)
 
 ~PropertyRepeater () override
 
void addItem (SessionItem *sessionItem)
 
void clear ()
 
void setActive (bool isActive)
 

Private Member Functions

void onPropertyChanged (SessionItem *item, const QString &propertyName)
 
void setOnChildPropertyChange (SessionItem *item, const QString &propertyName)
 
QVector< SessionItem * > targetItems (SessionItem *sourceItem)
 Returns list of target items to update their properties. More...
 

Private Attributes

bool m_block_repeater
 
QVector< SessionItem * > m_dataItems
 
bool m_repeat_child_properties
 

Constructor & Destructor Documentation

◆ PropertyRepeater()

PropertyRepeater::PropertyRepeater ( QObject *  parent = nullptr,
bool  repeat_child_properties = false 
)
explicit

Definition at line 18 of file PropertyRepeater.cpp.

19  : QObject(parent)
20  , m_block_repeater(false)
21  , m_repeat_child_properties(repeat_child_properties)
22 {
23 }

◆ ~PropertyRepeater()

PropertyRepeater::~PropertyRepeater ( )
override

Definition at line 25 of file PropertyRepeater.cpp.

26 {
27  for (auto* item : m_dataItems)
28  item->mapper()->unsubscribe(this);
29 }
QVector< SessionItem * > m_dataItems

References m_dataItems.

Member Function Documentation

◆ addItem()

void PropertyRepeater::addItem ( SessionItem sessionItem)

Definition at line 31 of file PropertyRepeater.cpp.

32 {
33  if (!sessionItem || m_dataItems.contains(sessionItem))
34  return;
35 
36  sessionItem->mapper()->setOnItemDestroy(
37  [this](SessionItem* item) { m_dataItems.removeAll(item); }, this);
38 
39  sessionItem->mapper()->setOnPropertyChange(
40  [this](SessionItem* item, const QString& name) { onPropertyChanged(item, name); }, this);
41 
43  sessionItem->mapper()->setOnChildPropertyChange(
44  [this](SessionItem* item, const QString& name) {
46  },
47  this);
48  }
49  m_dataItems.push_back(sessionItem);
50 }
void setOnItemDestroy(std::function< void(SessionItem *)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:67
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:39
void setOnChildPropertyChange(std::function< void(SessionItem *, QString)> f, const void *caller=nullptr)
Calls back on child property change, report childItem and property name.
Definition: ModelMapper.cpp:53
void setOnChildPropertyChange(SessionItem *item, const QString &propertyName)
void onPropertyChanged(SessionItem *item, const QString &propertyName)
Base class for a GUI data item.
Definition: SessionItem.h:204
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
QString const & name(EShape k)
Definition: particles.cpp:20

References m_dataItems, m_repeat_child_properties, SessionItem::mapper(), GUI::RealSpace::Particles::name(), onPropertyChanged(), setOnChildPropertyChange(), ModelMapper::setOnChildPropertyChange(), ModelMapper::setOnItemDestroy(), and ModelMapper::setOnPropertyChange().

Referenced by FitComparisonController2D::setItem(), and FitComparison1DViewController::setItem().

Here is the call graph for this function:

◆ clear()

void PropertyRepeater::clear ( )

Definition at line 52 of file PropertyRepeater.cpp.

53 {
54  for (auto* item : m_dataItems)
55  item->mapper()->unsubscribe(this);
56 
57  m_dataItems.clear();
58 }

References m_dataItems.

Referenced by FitComparisonController2D::clear(), and FitComparison1DViewController::clear().

◆ onPropertyChanged()

void PropertyRepeater::onPropertyChanged ( SessionItem item,
const QString &  propertyName 
)
private

Definition at line 65 of file PropertyRepeater.cpp.

66 {
67  if (m_block_repeater)
68  return;
69 
70  m_block_repeater = true;
71 
72  QVariant value = item->getItemValue(propertyName);
73  for (auto* target : targetItems(item))
74  target->setItemValue(propertyName, value);
75  m_block_repeater = false;
76 }
QVector< SessionItem * > targetItems(SessionItem *sourceItem)
Returns list of target items to update their properties.
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.

References SessionItem::getItemValue(), m_block_repeater, and targetItems().

Referenced by addItem().

Here is the call graph for this function:

◆ setActive()

void PropertyRepeater::setActive ( bool  isActive)

Definition at line 60 of file PropertyRepeater.cpp.

61 {
62  m_block_repeater = !isActive;
63 }

References m_block_repeater.

◆ setOnChildPropertyChange()

void PropertyRepeater::setOnChildPropertyChange ( SessionItem item,
const QString &  propertyName 
)
private

Definition at line 78 of file PropertyRepeater.cpp.

79 {
80  if (m_block_repeater)
81  return;
82 
83  m_block_repeater = true;
84 
85  SessionItem* sourceItem = item->parentItem();
86  QString tag = sourceItem->tagFromItem(item);
87  QVariant value = item->getItemValue(propertyName);
88  for (auto* target : targetItems(sourceItem))
89  target->getItem(tag)->setItemValue(propertyName, value);
90  m_block_repeater = false;
91 }
SessionItem * parentItem() const
Returns parent of this item.
Definition: SessionItem.cpp:67
QString tagFromItem(const SessionItem *item) const
Returns the tag name of given item when existing.

References SessionItem::getItemValue(), m_block_repeater, SessionItem::parentItem(), SessionItem::tagFromItem(), and targetItems().

Referenced by addItem().

Here is the call graph for this function:

◆ targetItems()

QVector< SessionItem * > PropertyRepeater::targetItems ( SessionItem sourceItem)
private

Returns list of target items to update their properties.

Definition at line 95 of file PropertyRepeater.cpp.

96 {
97  QVector<SessionItem*> result = m_dataItems;
98  result.removeAll(sourceItem);
99  return result;
100 }

References m_dataItems.

Referenced by onPropertyChanged(), and setOnChildPropertyChange().

Member Data Documentation

◆ m_block_repeater

bool PropertyRepeater::m_block_repeater
private

Definition at line 45 of file PropertyRepeater.h.

Referenced by onPropertyChanged(), setActive(), and setOnChildPropertyChange().

◆ m_dataItems

QVector<SessionItem*> PropertyRepeater::m_dataItems
private

Definition at line 44 of file PropertyRepeater.h.

Referenced by ~PropertyRepeater(), addItem(), clear(), and targetItems().

◆ m_repeat_child_properties

bool PropertyRepeater::m_repeat_child_properties
private

Definition at line 46 of file PropertyRepeater.h.

Referenced by addItem().


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