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

Container to hold label and editor for PropertyItem. More...

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

Public Member Functions

 PropertyWidgetItem (QWidget *parent=nullptr)
 
 ~PropertyWidgetItem ()
 
void addToGrid (QGridLayout *gridLayout, int nrow)
 
const SessionItemitem ()
 
void setItemEditor (const SessionItem *item, QWidget *editor)
 
void updateItemRoles ()
 

Private Member Functions

void connectEditor (QWidget *editor)
 Provide additional connections of editor to model mapper. More...
 

Private Attributes

QDataWidgetMapper * m_dataMapper
 
SessionModelDelegatem_delegate
 
QWidget * m_editor
 
const SessionItemm_item
 
QLabel * m_label
 

Detailed Description

Container to hold label and editor for PropertyItem.

Contains also logic to map editor to SessionModel.

Definition at line 30 of file PropertyWidgetItem.h.

Constructor & Destructor Documentation

◆ PropertyWidgetItem()

PropertyWidgetItem::PropertyWidgetItem ( QWidget *  parent = nullptr)
explicit

Definition at line 29 of file PropertyWidgetItem.cpp.

30  : QObject(parent)
31  , m_label(new QLabel)
32  , m_editor(nullptr)
33  , m_dataMapper(new QDataWidgetMapper(this))
34  , m_delegate(new SessionModelDelegate(nullptr))
35  , m_item(nullptr)
36 {
37  m_label->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
38 }
SessionModelDelegate * m_delegate
const SessionItem * m_item
QDataWidgetMapper * m_dataMapper
The SessionModelDelegate class presents the content of SessionModel items in standard QTreeView.

References m_label.

◆ ~PropertyWidgetItem()

PropertyWidgetItem::~PropertyWidgetItem ( )

Definition at line 40 of file PropertyWidgetItem.cpp.

41 {
42  m_editor->clearFocus();
43  delete m_label;
44  delete m_editor;
45  delete m_delegate;
46 }

References m_delegate, m_editor, and m_label.

Member Function Documentation

◆ addToGrid()

void PropertyWidgetItem::addToGrid ( QGridLayout *  gridLayout,
int  nrow 
)

Definition at line 74 of file PropertyWidgetItem.cpp.

75 {
76  ASSERT(m_label);
78 
79  gridLayout->addWidget(m_label, nrow, 0);
80  gridLayout->addWidget(m_editor, nrow, 1);
81 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT, m_editor, and m_label.

◆ connectEditor()

void PropertyWidgetItem::connectEditor ( QWidget *  editor)
private

Provide additional connections of editor to model mapper.

Definition at line 99 of file PropertyWidgetItem.cpp.

100 {
101  if (auto customEditor = dynamic_cast<CustomEditor*>(editor)) {
102  connect(customEditor, &CustomEditor::dataChanged, m_delegate,
104  }
105 }
Base class for all custom variants editors.
Definition: CustomEditors.h:28
void dataChanged(const QVariant &data)
Signal emit then user changed the data through the editor.
void onCustomEditorDataChanged(const QVariant &)
Notifies everyone that the editor has completed editing the data.

References CustomEditor::dataChanged(), m_delegate, and SessionModelDelegate::onCustomEditorDataChanged().

Referenced by setItemEditor().

Here is the call graph for this function:

◆ item()

const SessionItem * PropertyWidgetItem::item ( )

Definition at line 92 of file PropertyWidgetItem.cpp.

93 {
94  return m_item;
95 }

References m_item.

Referenced by setItemEditor().

◆ setItemEditor()

void PropertyWidgetItem::setItemEditor ( const SessionItem item,
QWidget *  editor 
)

Definition at line 48 of file PropertyWidgetItem.cpp.

49 {
50  ASSERT(m_item == nullptr);
51  m_item = item;
52  m_editor = editor;
53 
54  m_label->setText(item->displayName());
55 
56  m_editor->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
57 
58  m_dataMapper->setModel(item->model());
59  m_dataMapper->setRootIndex(item->parent()->index());
60  m_dataMapper->setCurrentModelIndex(item->index());
61  m_dataMapper->addMapping(m_label, 0);
62  m_dataMapper->addMapping(m_editor, 1);
63  m_dataMapper->setItemDelegate(m_delegate);
64 
65  QModelIndex valueIndex = item->index().sibling(item->index().row(), 1);
66  if (valueIndex.isValid())
67  m_delegate->setEditorData(editor, valueIndex);
68 
69  connectEditor(editor);
70 
72 }
const SessionItem * item()
void connectEditor(QWidget *editor)
Provide additional connections of editor to model mapper.
QString displayName() const
Get display name of item, append index if ambigue.
SessionItem * parent() const
Returns parent of this item.
Definition: SessionItem.cpp:73
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:66
QModelIndex index() const
Returns model index of this item.
Definition: SessionItem.cpp:80
void setEditorData(QWidget *editor, const QModelIndex &index) const
Propagates the data change from the model to the editor (if it is still opened).

References ASSERT, connectEditor(), SessionItem::displayName(), SessionItem::index(), item(), m_dataMapper, m_delegate, m_editor, m_item, m_label, SessionItem::model(), SessionItem::parent(), SessionModelDelegate::setEditorData(), and updateItemRoles().

Here is the call graph for this function:

◆ updateItemRoles()

void PropertyWidgetItem::updateItemRoles ( )

Definition at line 83 of file PropertyWidgetItem.cpp.

84 {
85  ASSERT(m_item);
86  m_label->setEnabled(m_item->isEnabled());
87  m_editor->setEnabled(m_item->isEnabled());
88  m_label->setToolTip(SessionItemUtils::ToolTipRole(*m_item).toString());
89  m_editor->setToolTip(SessionItemUtils::ToolTipRole(*m_item).toString());
90 }
bool isEnabled() const
QVariant ToolTipRole(const SessionItem &item, int ncol=0)
Returns tooltip for given item.

References ASSERT, SessionItem::isEnabled(), m_editor, m_item, m_label, and SessionItemUtils::ToolTipRole().

Referenced by setItemEditor().

Here is the call graph for this function:

Member Data Documentation

◆ m_dataMapper

QDataWidgetMapper* PropertyWidgetItem::m_dataMapper
private

Definition at line 48 of file PropertyWidgetItem.h.

Referenced by setItemEditor().

◆ m_delegate

SessionModelDelegate* PropertyWidgetItem::m_delegate
private

Definition at line 49 of file PropertyWidgetItem.h.

Referenced by ~PropertyWidgetItem(), connectEditor(), and setItemEditor().

◆ m_editor

QWidget* PropertyWidgetItem::m_editor
private

◆ m_item

const SessionItem* PropertyWidgetItem::m_item
private

Definition at line 50 of file PropertyWidgetItem.h.

Referenced by item(), setItemEditor(), and updateItemRoles().

◆ m_label

QLabel* PropertyWidgetItem::m_label
private

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