BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SessionModelView.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/SessionModelView.cpp
6 //! @brief Implements class SessionModelView
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 
25 #include <QToolBar>
26 #include <QToolButton>
27 #include <QVBoxLayout>
28 
29 namespace {
30 const bool show_test_view = false;
31 }
32 
34  : QWidget(mainWindow)
35  , m_mainWindow(mainWindow)
36  , m_toolBar(new QToolBar)
37  , m_tabs(new QTabWidget)
38  , m_expandCollapseButton(new QToolButton)
39  , m_delegate(new SessionModelDelegate(this))
40 {
41  auto layout = new QVBoxLayout;
42  layout->setMargin(0);
43  layout->setSpacing(0);
44 
45  m_expandCollapseButton->setText("Expand / collapse tree");
46  m_expandCollapseButton->setIcon(QIcon(":/images/toolbar_expand_collapse_tree.svg"));
47  m_expandCollapseButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
48  m_expandCollapseButton->setToolTip("Click to switch between expanded/collapsed tree view");
50  connect(m_expandCollapseButton, &QToolButton::clicked, this,
52 
53  layout->addWidget(m_toolBar);
54  layout->addWidget(m_tabs);
55  setLayout(layout);
56 
57  init_tabs();
58 
59  if (show_test_view)
61 }
62 
64 {
65  m_content.at(m_tabs->currentIndex())->toggleExpanded();
66 }
67 
68 //! Creates content for tab widget.
69 
71 {
72  ASSERT(m_content.empty());
73 
74  for (auto model : modelsForTabs()) {
75  auto treeView = new ModelTreeView(this, model);
76  treeView->setItemDelegate(m_delegate);
77  m_tabs->addTab(treeView, treeView->objectName());
78  m_content.push_back(treeView);
79  }
80 }
81 
82 //! Returns list of models to show in tabs.
83 
84 QList<SessionModel*> SessionModelView::modelsForTabs()
85 {
86  QList<SessionModel*> result = QList<SessionModel*>()
89  << m_mainWindow->jobModel();
90  return result;
91 }
92 
94 {
95  auto view = new TestView(m_mainWindow);
96  int index = m_tabs->addTab(view, "Test View");
97  m_tabs->setCurrentIndex(index);
98 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines class MainWindow.
Defines class InstrumentModel.
Defines class JobModel.
Defines class MaterialModel.
Defines class ModelTreeView.
Defines class RealDataModel.
Defines class SampleModel.
Defines class SessionModelDelegate.
Defines class SessionModelView.
Defines class TestView.
InstrumentModel * instrumentModel()
Definition: mainwindow.cpp:139
SampleModel * sampleModel()
Definition: mainwindow.cpp:144
JobModel * jobModel()
Definition: mainwindow.cpp:154
MaterialModel * materialModel()
Definition: mainwindow.cpp:134
RealDataModel * realDataModel()
Definition: mainwindow.cpp:149
Equivalent of QTreeView for SessionModel allowing to add visual decorations to the tree.
Definition: ModelTreeView.h:28
The SessionModelDelegate class presents the content of SessionModel items in standard QTreeView.
SessionModelDelegate * m_delegate
QToolButton * m_expandCollapseButton
QTabWidget * m_tabs
QToolBar * m_toolBar
QList< SessionModel * > modelsForTabs()
Returns list of models to show in tabs.
SessionModelView(MainWindow *mainWindow=0)
QVector< ModelTreeView * > m_content
void init_tabs()
Creates content for tab widget.
MainWindow * m_mainWindow