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

View to tests QListView working with ComponentProxyModel. More...

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

Public Member Functions

 TestComponentView (MainWindow *mainWindow=nullptr)
 

Private Slots

void onAddItemRequest ()
 
void onExpandRequest ()
 
void onUpdateRequest ()
 

Private Member Functions

QWidget * componentBoxPanel ()
 
QWidget * componentTreePanel ()
 
void init_source ()
 Inserts test items into source model. More...
 
void onSelectionChanged (const QItemSelection &selected, const QItemSelection &)
 

Private Attributes

QPushButton * m_addItemButton
 
ComponentEditorm_componentFlat
 
ComponentEditorm_componentTree
 
SessionModelDelegatem_delegate
 
QPushButton * m_expandButton
 
bool m_isExpaned
 
MainWindowm_mainWindow
 
MaterialModelm_materialModel
 
SampleModelm_sampleModel
 
QTreeView * m_sourceTree
 
QSplitter * m_splitter
 
QPushButton * m_updateButton
 

Detailed Description

View to tests QListView working with ComponentProxyModel.

Definition at line 35 of file TestComponentView.h.

Constructor & Destructor Documentation

◆ TestComponentView()

TestComponentView::TestComponentView ( MainWindow mainWindow = nullptr)

Definition at line 41 of file TestComponentView.cpp.

42  : m_mainWindow(mainWindow)
43  , m_sampleModel(new SampleModel(this))
44  , m_materialModel(new MaterialModel(this))
45  , m_sourceTree(new QTreeView)
48  , m_updateButton(new QPushButton("Update models"))
49  , m_addItemButton(new QPushButton("Add item"))
50  , m_expandButton(new QPushButton("Expand tree"))
51  , m_splitter(new QSplitter)
52  , m_delegate(new SessionModelDelegate(this))
53  , m_isExpaned(false)
54 {
55  auto buttonLayout = new QHBoxLayout;
56  buttonLayout->addWidget(m_updateButton);
57  buttonLayout->addWidget(m_addItemButton);
58  buttonLayout->addWidget(m_expandButton);
59 
60  m_sourceTree->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
61  m_sourceTree->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
62 
63  m_splitter->addWidget(m_sourceTree);
64  m_splitter->addWidget(componentTreePanel());
65  m_splitter->addWidget(componentBoxPanel());
66 
67  auto layout = new QVBoxLayout();
68  layout->setMargin(0);
69  layout->setSpacing(0);
70  layout->addLayout(buttonLayout);
71  layout->addWidget(m_splitter);
72 
73  setLayout(layout);
74 
75  init_source();
76 
77  connect(m_updateButton, &QPushButton::clicked, this, &TestComponentView::onUpdateRequest);
78  connect(m_addItemButton, &QPushButton::clicked, this, &TestComponentView::onAddItemRequest);
79  connect(m_expandButton, &QPushButton::clicked, this, &TestComponentView::onExpandRequest);
80 
81  m_sourceTree->setModel(m_sampleModel);
82  m_sourceTree->setItemDelegate(m_delegate);
84  connect(m_sourceTree->selectionModel(), &QItemSelectionModel::selectionChanged, this,
86 }
Component editor for SessionItem.
Main model to hold sample items.
Definition: SampleModel.h:24
The SessionModelDelegate class presents the content of SessionModel items in standard QTreeView.
void init_source()
Inserts test items into source model.
MainWindow * m_mainWindow
ComponentEditor * m_componentTree
QWidget * componentBoxPanel()
QPushButton * m_updateButton
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &)
QTreeView * m_sourceTree
QWidget * componentTreePanel()
SessionModelDelegate * m_delegate
QSplitter * m_splitter
QPushButton * m_expandButton
MaterialModel * m_materialModel
ComponentEditor * m_componentFlat
SampleModel * m_sampleModel
QPushButton * m_addItemButton
void setPropertyStyle(QTreeView *tree)
Sets style for the tree to use in property editors.
Definition: StyleUtils.cpp:36

References componentBoxPanel(), componentTreePanel(), init_source(), m_addItemButton, m_delegate, m_expandButton, m_sampleModel, m_sourceTree, m_splitter, m_updateButton, onAddItemRequest(), onExpandRequest(), onSelectionChanged(), onUpdateRequest(), and StyleUtils::setPropertyStyle().

Here is the call graph for this function:

Member Function Documentation

◆ componentBoxPanel()

QWidget * TestComponentView::componentBoxPanel ( )
private

Definition at line 157 of file TestComponentView.cpp.

158 {
159  auto* result = new QSplitter(Qt::Vertical);
160  result->addWidget(m_componentFlat);
161 
162  m_componentFlat->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
163 
164  return result;
165 }

References m_componentFlat.

Referenced by TestComponentView().

◆ componentTreePanel()

QWidget * TestComponentView::componentTreePanel ( )
private

Definition at line 148 of file TestComponentView.cpp.

149 {
150  auto* result = new QSplitter(Qt::Vertical);
151  result->addWidget(m_componentTree);
152 
153  m_componentTree->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
154  return result;
155 }

References m_componentTree.

Referenced by TestComponentView().

◆ init_source()

void TestComponentView::init_source ( )
private

Inserts test items into source model.

Definition at line 122 of file TestComponentView.cpp.

123 {
124  SampleBuilderFactory factory;
125  const std::unique_ptr<MultiLayer> sample(
126  factory.createSampleByName("CylindersWithSizeDistributionBuilder"));
131 }
Factory to create standard pre-defined samples.
MultiLayer * createSampleByName(const std::string &name)
Retrieves a SampleBuilder from the registry, does the build, and returns the result.
T * insertItem(SessionItem *parent=nullptr, int row=-1, QString tag="")
Definition: SessionModel.h:125
SessionItem * populateSampleModel(SampleModel *sampleModel, MaterialModel *materialModel, const MultiLayer &sample, const QString &sample_name="")

References SampleBuilderFactory::createSampleByName(), SessionModel::insertItem(), m_materialModel, m_sampleModel, and GUIObjectBuilder::populateSampleModel().

Referenced by TestComponentView().

Here is the call graph for this function:

◆ onAddItemRequest

void TestComponentView::onAddItemRequest ( )
privateslot

Definition at line 93 of file TestComponentView.cpp.

References SessionModel::insertItem(), and m_sampleModel.

Referenced by TestComponentView().

Here is the call graph for this function:

◆ onExpandRequest

void TestComponentView::onExpandRequest ( )
privateslot

Definition at line 98 of file TestComponentView.cpp.

99 {
100  if (!m_isExpaned) {
101  m_sourceTree->expandAll();
102  m_sourceTree->resizeColumnToContents(0);
103  m_sourceTree->resizeColumnToContents(1);
104  // m_componentTree->treeView()->expandAll();
105  // m_componentTree->treeView()->resizeColumnToContents(0);
106  // m_componentTree->treeView()->resizeColumnToContents(1);
107  } else {
108  m_sourceTree->collapseAll();
109  // m_componentTree->treeView()->collapseAll();
110  }
111 
112  // const auto imax = std::numeric_limits<int>::max();
113  const int imax = 1;
114  QList<int> sizes = {imax, imax, imax};
115  m_splitter->setSizes(sizes);
116 
118 }

References m_isExpaned, m_sourceTree, and m_splitter.

Referenced by TestComponentView().

◆ onSelectionChanged()

void TestComponentView::onSelectionChanged ( const QItemSelection &  selected,
const QItemSelection &   
)
private

Definition at line 133 of file TestComponentView.cpp.

134 {
135  QModelIndexList indices = selected.indexes();
136 
137  if (!indices.empty()) {
138  // QModelIndex selectedIndex = indices.front();
139  // m_componentTree->setRootIndex(selectedIndex);
140  // m_componentTree->treeView()->expandAll();
141 
142  auto item = m_sampleModel->itemForIndex(indices.front());
143  m_componentTree->setItem(item);
144  m_componentFlat->setItem(item);
145  }
146 }
void setItem(SessionItem *item)
SessionItem * itemForIndex(const QModelIndex &index) const

References SessionModel::itemForIndex(), m_componentFlat, m_componentTree, m_sampleModel, and ComponentEditor::setItem().

Referenced by TestComponentView().

Here is the call graph for this function:

◆ onUpdateRequest

void TestComponentView::onUpdateRequest ( )
privateslot

Definition at line 88 of file TestComponentView.cpp.

89 {
90  // m_componentTree->setModel(m_sourceModel);
91 }

Referenced by TestComponentView().

Member Data Documentation

◆ m_addItemButton

QPushButton* TestComponentView::m_addItemButton
private

Definition at line 58 of file TestComponentView.h.

Referenced by TestComponentView().

◆ m_componentFlat

ComponentEditor* TestComponentView::m_componentFlat
private

Definition at line 56 of file TestComponentView.h.

Referenced by componentBoxPanel(), and onSelectionChanged().

◆ m_componentTree

ComponentEditor* TestComponentView::m_componentTree
private

Definition at line 55 of file TestComponentView.h.

Referenced by componentTreePanel(), and onSelectionChanged().

◆ m_delegate

SessionModelDelegate* TestComponentView::m_delegate
private

Definition at line 61 of file TestComponentView.h.

Referenced by TestComponentView().

◆ m_expandButton

QPushButton* TestComponentView::m_expandButton
private

Definition at line 59 of file TestComponentView.h.

Referenced by TestComponentView().

◆ m_isExpaned

bool TestComponentView::m_isExpaned
private

Definition at line 62 of file TestComponentView.h.

Referenced by onExpandRequest().

◆ m_mainWindow

MainWindow* TestComponentView::m_mainWindow
private

Definition at line 51 of file TestComponentView.h.

◆ m_materialModel

MaterialModel* TestComponentView::m_materialModel
private

Definition at line 53 of file TestComponentView.h.

Referenced by init_source().

◆ m_sampleModel

SampleModel* TestComponentView::m_sampleModel
private

◆ m_sourceTree

QTreeView* TestComponentView::m_sourceTree
private

Definition at line 54 of file TestComponentView.h.

Referenced by TestComponentView(), and onExpandRequest().

◆ m_splitter

QSplitter* TestComponentView::m_splitter
private

Definition at line 60 of file TestComponentView.h.

Referenced by TestComponentView(), and onExpandRequest().

◆ m_updateButton

QPushButton* TestComponentView::m_updateButton
private

Definition at line 57 of file TestComponentView.h.

Referenced by TestComponentView().


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