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

Component property widget for SessionItems. More...

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

Public Slots

void onDataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
 

Public Member Functions

 ComponentFlatView (QWidget *parent=nullptr)
 
 ~ComponentFlatView ()
 
void addItem (SessionItem *item)
 
void clearEditor ()
 
void setItem (SessionItem *item)
 
void setModel (SessionModel *model)
 
void setShowChildren (bool show)
 

Private Member Functions

void clearLayout ()
 
PropertyWidgetItemcreateWidget (const SessionItem *item)
 
void initGridLayout ()
 
void updateItemProperties ()
 
void updateItemRoles (SessionItem *item)
 

Private Attributes

QGridLayout * m_gridLayout
 
QBoxLayout * m_mainLayout
 
SessionModelm_model
 
bool m_show_children
 
QVector< const SessionItem * > m_topItems
 
QVector< PropertyWidgetItem * > m_widgetItems
 

Detailed Description

Component property widget for SessionItems.

On the contrary to ComponentTreeView properties are presented as widgets in grid layout. Shows only PropertyItems and current items of GroupProperties.

Definition at line 31 of file ComponentFlatView.h.

Constructor & Destructor Documentation

◆ ComponentFlatView()

ComponentFlatView::ComponentFlatView ( QWidget *  parent = nullptr)

Definition at line 28 of file ComponentFlatView.cpp.

29  : ComponentView(parent)
30  , m_mainLayout(new QVBoxLayout)
31  , m_gridLayout(nullptr)
32  , m_model(nullptr)
33  , m_show_children(true)
34 {
35  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
36 
37  m_mainLayout->setMargin(10);
38  m_mainLayout->setSpacing(0);
39 
41 
42  setLayout(m_mainLayout);
43 }
QBoxLayout * m_mainLayout
SessionModel * m_model
QGridLayout * m_gridLayout
ComponentView(QWidget *parent=nullptr)
Definition: ComponentView.h:27

References initGridLayout(), and m_mainLayout.

Here is the call graph for this function:

◆ ~ComponentFlatView()

ComponentFlatView::~ComponentFlatView ( )
default

Member Function Documentation

◆ addItem()

void ComponentFlatView::addItem ( SessionItem item)
virtual

Reimplemented from ComponentView.

Definition at line 56 of file ComponentFlatView.cpp.

57 {
58  if (m_topItems.isEmpty()) {
59  setItem(item);
60  return;
61  }
62  m_topItems.push_back(item);
64 }
QVector< const SessionItem * > m_topItems
void setItem(SessionItem *item)

References m_topItems, setItem(), and updateItemProperties().

Here is the call graph for this function:

◆ clearEditor()

void ComponentFlatView::clearEditor ( )
virtual

Implements ComponentView.

Definition at line 105 of file ComponentFlatView.cpp.

106 {
107  m_topItems.clear();
108  clearLayout();
109 }

References clearLayout(), and m_topItems.

Referenced by setItem(), SimulationOptionsWidget::setItem(), and DistributionEditor::subscribeToItem().

Here is the call graph for this function:

◆ clearLayout()

void ComponentFlatView::clearLayout ( )
private

Definition at line 77 of file ComponentFlatView.cpp.

78 {
81 
82  for (auto widget : m_widgetItems)
83  widget->deleteLater();
84  m_widgetItems.clear();
85 }
#define ASSERT(condition)
Definition: Assert.h:31
QVector< PropertyWidgetItem * > m_widgetItems
void clearGridLayout(QGridLayout *layout, bool deleteWidgets=true)
Clear layout completely.
Definition: LayoutUtils.cpp:81

References ASSERT, LayoutUtils::clearGridLayout(), m_gridLayout, and m_widgetItems.

Referenced by clearEditor(), and updateItemProperties().

Here is the call graph for this function:

◆ createWidget()

PropertyWidgetItem * ComponentFlatView::createWidget ( const SessionItem item)
private

Definition at line 147 of file ComponentFlatView.cpp.

148 {
149  auto editor = PropertyEditorFactory::CreateEditor(*item);
150  if (!editor)
151  return nullptr;
152 
153  auto result = new PropertyWidgetItem(this);
154  result->setItemEditor(item, editor);
155 
156  return result;
157 }
Container to hold label and editor for PropertyItem.
QWidget * CreateEditor(const SessionItem &item, QWidget *parent=nullptr)
Creates an editor suitable for editing of item.value()

References PropertyEditorFactory::CreateEditor().

Referenced by updateItemProperties().

Here is the call graph for this function:

◆ initGridLayout()

void ComponentFlatView::initGridLayout ( )
private

Definition at line 138 of file ComponentFlatView.cpp.

139 {
140  delete m_gridLayout;
141  m_gridLayout = new QGridLayout;
142  m_gridLayout->setSpacing(6);
143  m_mainLayout->addLayout(m_gridLayout);
144  m_mainLayout->addStretch(1);
145 }

References m_gridLayout, and m_mainLayout.

Referenced by ComponentFlatView().

◆ onDataChanged

void ComponentFlatView::onDataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight,
const QVector< int > &  roles 
)
slot

Definition at line 92 of file ComponentFlatView.cpp.

94 {
95  Q_UNUSED(bottomRight);
96  SessionItem* item = m_model->itemForIndex(topLeft);
97  ASSERT(item);
98  if (item->modelType() == "GroupProperty")
100 
101  if (roles.contains(SessionFlags::FlagRole))
102  updateItemRoles(item);
103 }
void updateItemRoles(SessionItem *item)
QString modelType() const
Get model type.
SessionItem * itemForIndex(const QModelIndex &index) const

References ASSERT, SessionFlags::FlagRole, SessionModel::itemForIndex(), m_model, SessionItem::modelType(), updateItemProperties(), and updateItemRoles().

Referenced by setModel().

Here is the call graph for this function:

◆ setItem()

void ComponentFlatView::setItem ( SessionItem item)
virtual

Implements ComponentView.

Definition at line 47 of file ComponentFlatView.cpp.

48 {
49  clearEditor();
50 
51  m_topItems.push_back(item);
52  setModel(item->model());
54 }
void setModel(SessionModel *model)
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:66

References clearEditor(), m_topItems, SessionItem::model(), setModel(), and updateItemProperties().

Referenced by addItem(), SimulationOptionsWidget::setItem(), and DistributionEditor::subscribeToItem().

Here is the call graph for this function:

◆ setModel()

void ComponentFlatView::setModel ( SessionModel model)

Definition at line 66 of file ComponentFlatView.cpp.

67 {
68  if (m_model) {
69  disconnect(m_model, &SessionModel::dataChanged, this, &ComponentFlatView::onDataChanged);
70  }
71  m_model = model;
72  if (m_model) {
73  connect(m_model, &SessionModel::dataChanged, this, &ComponentFlatView::onDataChanged);
74  }
75 }
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)

References m_model, and onDataChanged().

Referenced by setItem().

Here is the call graph for this function:

◆ setShowChildren()

void ComponentFlatView::setShowChildren ( bool  show)

Definition at line 87 of file ComponentFlatView.cpp.

88 {
89  m_show_children = show;
90 }

References m_show_children.

Referenced by ComponentEditor::createComponentView().

◆ updateItemProperties()

void ComponentFlatView::updateItemProperties ( )
private

Definition at line 111 of file ComponentFlatView.cpp.

112 {
113  clearLayout();
114 
115  QList<const SessionItem*> allitems;
116  for (auto item : m_topItems)
117  allitems += ComponentUtils::componentItems(*item);
118 
119  int nrow(0);
120  for (auto child : allitems) {
121  auto widget = createWidget(child);
122  if (!widget)
123  continue;
124  widget->addToGrid(m_gridLayout, ++nrow);
125  m_widgetItems.push_back(widget);
126  if (!m_show_children)
127  break;
128  }
129 }
PropertyWidgetItem * createWidget(const SessionItem *item)
QList< const SessionItem * > componentItems(const SessionItem &item)
Returns list of SessionItem's children suitable for editing in property editors.

References clearLayout(), ComponentUtils::componentItems(), createWidget(), m_gridLayout, m_show_children, m_topItems, and m_widgetItems.

Referenced by addItem(), onDataChanged(), and setItem().

Here is the call graph for this function:

◆ updateItemRoles()

void ComponentFlatView::updateItemRoles ( SessionItem item)
private

Definition at line 131 of file ComponentFlatView.cpp.

132 {
133  for (auto widget : m_widgetItems)
134  if (widget->item() == item)
135  widget->updateItemRoles();
136 }

References m_widgetItems.

Referenced by onDataChanged().

Member Data Documentation

◆ m_gridLayout

QGridLayout* ComponentFlatView::m_gridLayout
private

Definition at line 58 of file ComponentFlatView.h.

Referenced by clearLayout(), initGridLayout(), and updateItemProperties().

◆ m_mainLayout

QBoxLayout* ComponentFlatView::m_mainLayout
private

Definition at line 57 of file ComponentFlatView.h.

Referenced by ComponentFlatView(), and initGridLayout().

◆ m_model

SessionModel* ComponentFlatView::m_model
private

Definition at line 60 of file ComponentFlatView.h.

Referenced by onDataChanged(), and setModel().

◆ m_show_children

bool ComponentFlatView::m_show_children
private

Definition at line 61 of file ComponentFlatView.h.

Referenced by setShowChildren(), and updateItemProperties().

◆ m_topItems

QVector<const SessionItem*> ComponentFlatView::m_topItems
private

Definition at line 62 of file ComponentFlatView.h.

Referenced by addItem(), clearEditor(), setItem(), and updateItemProperties().

◆ m_widgetItems

QVector<PropertyWidgetItem*> ComponentFlatView::m_widgetItems
private

Definition at line 59 of file ComponentFlatView.h.

Referenced by clearLayout(), updateItemProperties(), and updateItemRoles().


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