BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelTreeView.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/CommonWidgets/ModelTreeView.cpp
6 //! @brief Implements class ModelTreeView
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
20 #include <QTreeView>
21 #include <QVBoxLayout>
22 
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 }
49 
50 void ModelTreeView::setItemDelegate(QAbstractItemDelegate* delegate)
51 {
52  m_tree->setItemDelegate(delegate);
53 }
54 
56 {
58 }
59 
60 void ModelTreeView::setExpanded(bool expanded)
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
Defines class GUIHelpers functions.
Defines class ModelTreeView.
Defines class SessionDecorationModel.
Defines class SessionModel.
DefinesStyleUtils namespace.
QTreeView * m_tree
Definition: ModelTreeView.h:41
ModelTreeView(QWidget *parent, SessionModel *model)
void setItemDelegate(QAbstractItemDelegate *delegate)
void setExpanded(bool expanded)
void toggleExpanded()
SessionDecorationModel * m_decorationProxy
Definition: ModelTreeView.h:42
bool isExpanded() const
Definition: ModelTreeView.h:38
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