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

Equivalent of QTreeView for SessionModel allowing to add visual decorations to the tree. More...

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

Public Slots

bool isExpanded () const
 
void setExpanded (bool expanded)
 
void toggleExpanded ()
 

Public Member Functions

 ModelTreeView (QWidget *parent, SessionModel *model)
 
void setItemDelegate (QAbstractItemDelegate *delegate)
 

Private Attributes

SessionDecorationModelm_decorationProxy
 
bool m_is_expanded
 
QTreeView * m_tree
 

Detailed Description

Equivalent of QTreeView for SessionModel allowing to add visual decorations to the tree.

Additionaly provides expand/collapse utility methods.

Definition at line 28 of file ModelTreeView.h.

Constructor & Destructor Documentation

◆ ModelTreeView()

ModelTreeView::ModelTreeView ( QWidget *  parent,
SessionModel model 
)

Definition at line 23 of file ModelTreeView.cpp.

24  : QWidget(parent)
25  , m_tree(new QTreeView)
26  , m_decorationProxy(new SessionDecorationModel(this, model))
27  , m_is_expanded(false)
28 {
29  if (!model)
30  throw GUIHelpers::Error("ModelTreeView::ModelTreeView() -> Error. Nullptr as model.");
31 
32  setObjectName(model->getModelTag());
33 
34  auto layout = new QVBoxLayout;
35  layout->setMargin(0);
36  layout->setSpacing(0);
37  layout->addWidget(m_tree);
38 
40 
42  m_tree->setModel(m_decorationProxy);
43 
44  if (m_decorationProxy->rowCount(QModelIndex()) > 0)
45  setExpanded(true);
46 
47  setLayout(layout);
48 }
QTreeView * m_tree
Definition: ModelTreeView.h:41
void setExpanded(bool expanded)
SessionDecorationModel * m_decorationProxy
Definition: ModelTreeView.h:42
Provides decorations (text color, icons, etc) for SessionModel in SessionModelView context.
void setSessionModel(SessionModel *model)
QString getModelTag() const
Definition: SessionModel.h:191
void setPropertyStyle(QTreeView *tree)
Sets style for the tree to use in property editors.
Definition: StyleUtils.cpp:36

References SessionModel::getModelTag(), m_decorationProxy, m_tree, setExpanded(), StyleUtils::setPropertyStyle(), and SessionDecorationModel::setSessionModel().

Here is the call graph for this function:

Member Function Documentation

◆ isExpanded

bool ModelTreeView::isExpanded ( ) const
inlineslot

Definition at line 38 of file ModelTreeView.h.

38 { return m_is_expanded; }

References m_is_expanded.

Referenced by toggleExpanded().

◆ setExpanded

void ModelTreeView::setExpanded ( bool  expanded)
slot

Definition at line 60 of file ModelTreeView.cpp.

61 {
62  ASSERT(m_tree);
63  if (expanded) {
64  m_tree->expandAll();
65  m_tree->resizeColumnToContents(0);
66  m_tree->resizeColumnToContents(1);
67  } else {
68  m_tree->collapseAll();
69  }
70  m_is_expanded = expanded;
71 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT, m_is_expanded, and m_tree.

Referenced by ModelTreeView(), and toggleExpanded().

◆ setItemDelegate()

void ModelTreeView::setItemDelegate ( QAbstractItemDelegate *  delegate)

Definition at line 50 of file ModelTreeView.cpp.

51 {
52  m_tree->setItemDelegate(delegate);
53 }

References m_tree.

◆ toggleExpanded

void ModelTreeView::toggleExpanded ( )
slot

Definition at line 55 of file ModelTreeView.cpp.

56 {
58 }
bool isExpanded() const
Definition: ModelTreeView.h:38

References isExpanded(), and setExpanded().

Here is the call graph for this function:

Member Data Documentation

◆ m_decorationProxy

SessionDecorationModel* ModelTreeView::m_decorationProxy
private

Definition at line 42 of file ModelTreeView.h.

Referenced by ModelTreeView().

◆ m_is_expanded

bool ModelTreeView::m_is_expanded
private

Definition at line 43 of file ModelTreeView.h.

Referenced by isExpanded(), and setExpanded().

◆ m_tree

QTreeView* ModelTreeView::m_tree
private

Definition at line 41 of file ModelTreeView.h.

Referenced by ModelTreeView(), setExpanded(), and setItemDelegate().


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