BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SamplePropertyWidget.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/SampleDesigner/SamplePropertyWidget.cpp
6 //! @brief Implements class IntensityDataPropertyWidget
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 
18 #include <QItemSelection>
19 #include <QModelIndexList>
20 #include <QSortFilterProxyModel>
21 #include <QVBoxLayout>
22 
23 SamplePropertyWidget::SamplePropertyWidget(QItemSelectionModel* selection_model, QWidget* parent)
24  : QWidget(parent)
25  , m_selection_model(nullptr)
26  , m_propertyEditor(new ComponentEditor(ComponentEditor::FullTree))
27 {
28  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
29  setWindowTitle(QLatin1String("Property Editor"));
30  setObjectName(QLatin1String("SamplePropertyWidget"));
31 
32  setSelectionModel(selection_model);
33 
34  auto mainLayout = new QVBoxLayout;
35  mainLayout->setMargin(0);
36  mainLayout->setSpacing(0);
37  mainLayout->addWidget(m_propertyEditor);
38 
39  setLayout(mainLayout);
40 }
41 
43 {
44  return QSize(230, 256);
45 }
46 
48 {
49  return QSize(230, 64);
50 }
51 
52 void SamplePropertyWidget::setSelectionModel(QItemSelectionModel* selection_model)
53 {
54  if (selection_model == m_selection_model)
55  return;
56 
57  if (m_selection_model) {
58  disconnect(m_selection_model, &QItemSelectionModel::selectionChanged, this,
60  }
61 
62  m_selection_model = selection_model;
63 
64  if (m_selection_model) {
65  connect(m_selection_model, &QItemSelectionModel::selectionChanged, this,
67  }
68 }
69 
70 // TODO Refactor this together with whole SampleView. Remove knowledge about proxy model.
71 
72 void SamplePropertyWidget::selectionChanged(const QItemSelection& selected, const QItemSelection&)
73 {
74  QModelIndexList indices = selected.indexes();
75 
76  if (!indices.empty()) {
77  QModelIndex index = indices.back();
78 
79  if (auto proxy = dynamic_cast<QSortFilterProxyModel*>(
80  const_cast<QAbstractItemModel*>(indices.front().model())))
81  index = proxy->mapToSource(indices.back());
82 
83  SessionItem* item = static_cast<SessionItem*>(index.internalPointer());
84  if (item)
86 
87  } else {
88  m_propertyEditor->setItem(nullptr);
89  }
90 }
Defines ComponentEditor class.
Defines class SamplePropertyWidget.
Defines class SessionItem.
Component editor for SessionItem.
void setItem(SessionItem *item)
void selectionChanged(const QItemSelection &selected, const QItemSelection &)
SamplePropertyWidget(QItemSelectionModel *selection_model, QWidget *parent=nullptr)
void setSelectionModel(QItemSelectionModel *selection_model)
ComponentEditor * m_propertyEditor
QItemSelectionModel * m_selection_model