BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskEditorPropertyPanel.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/MaskWidgets/MaskEditorPropertyPanel.cpp
6 //! @brief Implements class MaskEditorPropertyPanel
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 <QListView>
21 #include <QVBoxLayout>
22 
23 //! Widget to cheat Accordion to resize correctly.
24 
25 class EnvelopWidget : public QWidget {
26 public:
27  EnvelopWidget(QWidget* content)
28  {
29  QVBoxLayout* mainLayout = new QVBoxLayout;
30  mainLayout->setContentsMargins(0, 0, 0, 0);
31  mainLayout->setSpacing(0);
32  setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
33  mainLayout->addWidget(content);
34  setLayout(mainLayout);
35  }
36 
37  QSize sizeHint() const { return QSize(128, 500); }
38 };
39 
41  : QWidget(parent)
42  , m_listView(new QListView)
43  , m_maskPropertyEditor(new ComponentEditor)
44  , m_plotPropertyEditor(new ComponentEditor(ComponentEditor::MiniTree))
45  , m_accordion(new AccordionWidget)
46  , m_maskModel(nullptr)
47  , m_intensityDataItem(nullptr)
48 {
49  setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
50  setObjectName(QLatin1String("MaskEditorToolPanel"));
51 
52  m_listView->setContextMenuPolicy(Qt::CustomContextMenu);
53  connect(m_listView, &QListView::customContextMenuRequested, this,
55 
56  QVBoxLayout* mainLayout = new QVBoxLayout;
57  mainLayout->setContentsMargins(0, 0, 0, 0);
58  mainLayout->setSpacing(0);
59 
64 
65  mainLayout->addWidget(m_accordion);
66 
67  setLayout(mainLayout);
68 }
69 
71 {
72  return QSize(128, 128);
73 }
74 
76 {
77  return QSize(128, 128);
78 }
79 
81  const QModelIndex& maskContainerIndex,
82  IntensityDataItem* intensityItem)
83 {
84  m_maskModel = model;
85  m_rootIndex = maskContainerIndex;
86  m_intensityDataItem = intensityItem;
87 
88  m_listView->setModel(m_maskModel);
89  m_listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
90 
91  m_listView->setRootIndex(m_rootIndex);
92 
93  connect(m_listView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
94  &MaskEditorPropertyPanel::onSelectionChanged, Qt::UniqueConnection);
95 
97 }
98 
100 {
101  m_maskModel = nullptr;
102  m_rootIndex = {};
103  m_intensityDataItem = nullptr;
104  m_listView->setModel(nullptr);
105  m_maskPropertyEditor->setItem(nullptr);
106  m_plotPropertyEditor->setItem(nullptr);
107 }
108 
110 {
112  return m_listView->selectionModel();
113 }
114 
115 //! Show/Hide panel. When panel is hidden, all property editors are disabled.
117 {
118  this->setHidden(value);
119 
120  if (!m_rootIndex.isValid())
121  return;
122 
123  if (value) {
124  m_maskPropertyEditor->setItem(nullptr);
125  m_plotPropertyEditor->setItem(nullptr);
126  } else {
127  QModelIndexList indexes = selectionModel()->selectedIndexes();
128  if (!indexes.empty())
130 
132  }
133 }
134 
135 void MaskEditorPropertyPanel::onSelectionChanged(const QItemSelection& selected,
136  const QItemSelection&)
137 {
138  if (!selected.empty())
139  m_maskPropertyEditor->setItem(m_maskModel->itemForIndex(selected.indexes().front()));
140  else
141  m_maskPropertyEditor->setItem(nullptr);
142 }
143 
145 {
146  emit itemContextMenuRequest(m_listView->mapToGlobal(point));
147 }
148 
150 {
151  ContentPane* cp = accordion->getContentPane(accordion->addContentPane("Plot properties"));
152  cp->setMaximumHeight(600);
153  cp->setHeaderTooltip("Plot properties editor");
154  cp->setContainerFrameStyle(QFrame::Plain);
155  QFrame* contentFrame = cp->getContentFrame();
156 
157  QVBoxLayout* layout = new QVBoxLayout();
158  layout->setContentsMargins(0, 0, 0, 0);
159  m_plotPropertyEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
160  layout->addWidget(new EnvelopWidget(m_plotPropertyEditor));
161  contentFrame->setLayout(layout);
162 }
163 
165 {
166  ContentPane* cp = accordion->getContentPane(accordion->addContentPane("Mask stack"));
167  cp->setMaximumHeight(600);
168  cp->setHeaderTooltip("List of created masks representing mask stacking order.");
169  cp->setContainerFrameStyle(QFrame::Plain);
170  QFrame* contentFrame = cp->getContentFrame();
171 
172  QVBoxLayout* layout = new QVBoxLayout();
173  layout->setContentsMargins(0, 0, 0, 0);
174  layout->addWidget(m_listView);
175  layout->addWidget(new EnvelopWidget(m_listView));
176  contentFrame->setLayout(layout);
177 }
178 
180 {
181  ContentPane* cp = accordion->getContentPane(accordion->addContentPane("Mask properties"));
182  cp->setMaximumHeight(600);
183  cp->setHeaderTooltip("Property editor for currently selected mask.");
184  cp->setContainerFrameStyle(QFrame::Plain);
185  QFrame* contentFrame = cp->getContentFrame();
186 
187  QVBoxLayout* layout = new QVBoxLayout();
188  layout->setContentsMargins(0, 0, 0, 0);
189  layout->addWidget(new EnvelopWidget(m_maskPropertyEditor));
190  contentFrame->setLayout(layout);
191 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines ComponentEditor class.
Defines ContentPane class.
Defines class IntensityDataItem.
Defines class MaskEditorPropertyPanel.
Defines class SessionModel.
QAccordion base class.
ContentPane * getContentPane(uint index)
Get content pane.
int addContentPane(QString header)
Add a new content Pane.
Component editor for SessionItem.
void setItem(SessionItem *item)
Content Pane class.
Definition: ContentPane.h:75
void setHeaderTooltip(QString tooltip)
Set header tooltip.
Definition: ContentPane.cpp:92
QFrame * getContentFrame()
Get the content frame of the content pane.
Definition: ContentPane.cpp:53
void setMaximumHeight(int maxHeight)
Set the maximum height of the content pane container.
Definition: ContentPane.cpp:72
void headerClicked()
Slot that is called when the header has been triggered.
void setContainerFrameStyle(int style)
Set the container frame style.
Widget to cheat Accordion to resize correctly.
EnvelopWidget(QWidget *content)
void setup_MaskStack(AccordionWidget *accordion)
ComponentEditor * m_plotPropertyEditor
ComponentEditor * m_maskPropertyEditor
void setPanelHidden(bool value)
Show/Hide panel. When panel is hidden, all property editors are disabled.
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &)
void itemContextMenuRequest(const QPoint &point)
IntensityDataItem * m_intensityDataItem
void setMaskContext(SessionModel *model, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)
void onCustomContextMenuRequested(const QPoint &point)
QItemSelectionModel * selectionModel()
MaskEditorPropertyPanel(QWidget *parent=nullptr)
void setup_MaskProperties(AccordionWidget *accordion)
void setup_PlotProperties(AccordionWidget *accordion)
SessionItem * itemForIndex(const QModelIndex &index) const