BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskEditorPropertyPanel Class Reference

Description

Tool widget for MaskEditor.

Definition at line 37 of file MaskEditorPropertyPanel.h.

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

Signals

void itemContextMenuRequest (const QPoint &point)
 

Public Member Functions

 MaskEditorPropertyPanel (QWidget *parent=nullptr)
 
QSize minimumSizeHint () const override
 
void resetContext ()
 
QItemSelectionModel * selectionModel ()
 
void setMaskContext (SessionModel *model, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)
 
void setPanelHidden (bool hidden)
 Show/Hide panel. When panel is hidden, all property editors are disabled. More...
 
QSize sizeHint () const override
 

Private Slots

void onCustomContextMenuRequested (const QPoint &point)
 
void onSelectionChanged (const QItemSelection &selected, const QItemSelection &)
 

Private Member Functions

void addMaskCheckBox (const QString &title, function< bool()> getter, function< void(bool)> setter)
 Add a checkbox to edit a mask's boolean value. More...
 
void addMaskSpinBox (DoubleDescriptor d)
 Add a spinbox to edit a mask's double value. More...
 
void createMaskEditorUI ()
 Creates the UI to edit the current mask's properties. More...
 
MaskItemmaskItemForIndex (const QModelIndex &index)
 Return the mask item for the given index. nullptr if index invalid or not pointing to a mask item. More...
 
void setCurrentMaskItem (MaskItem *maskItem)
 Set the current mask and creates the UI to edit the mask's properties. More...
 

Private Attributes

MaskItemm_currentMaskItem
 the mask item whose properties shall be edited More...
 
bool m_inhibitSelectionChange
 
IntensityDataItemm_intensityDataItem
 
QListView * m_listView
 
SessionModelm_maskModel
 
QFormLayout * m_maskPropertiesLayout
 
IntensityDataPropertyWidgetm_plotPropertyEditor
 
QModelIndex m_rootIndex
 

Constructor & Destructor Documentation

◆ MaskEditorPropertyPanel()

MaskEditorPropertyPanel::MaskEditorPropertyPanel ( QWidget *  parent = nullptr)

Definition at line 30 of file MaskEditorPropertyPanel.cpp.

31  : QWidget(parent)
32  , m_listView(new QListView)
34  , m_maskModel(nullptr)
35  , m_intensityDataItem(nullptr)
36  , m_currentMaskItem(nullptr)
38 {
39  setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
40  setObjectName(QLatin1String("MaskEditorToolPanel"));
41  setAttribute(Qt::WA_StyledBackground, true);
42  setProperty("stylable", true); // for stylesheet addressing
43 
44  m_listView->setContextMenuPolicy(Qt::CustomContextMenu);
45  connect(m_listView, &QListView::customContextMenuRequested, this,
47 
48  auto* mainLayout = new QVBoxLayout;
49  mainLayout->setContentsMargins(0, 0, 0, 0);
50  mainLayout->setSpacing(8);
51 
52  // -- plot properties
53  auto* plotPropertiesGroup = new QGroupBox("Plot properties", this);
54  auto* plotPropertiesLayout = new QVBoxLayout(plotPropertiesGroup);
55  plotPropertiesLayout->setContentsMargins(0, 0, 0, 0);
56  m_plotPropertyEditor->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
57  plotPropertiesLayout->addWidget(m_plotPropertyEditor);
58  GroupBoxCollapser::installIntoGroupBox(plotPropertiesGroup);
59 
60  // -- mask stack
61  auto* maskStackGroup = new QGroupBox("Mask stack", this);
62  auto* maskStackLayout = new QVBoxLayout(maskStackGroup);
63  maskStackLayout->setContentsMargins(0, 0, 0, 0);
64  m_listView->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
65  maskStackLayout->addWidget(m_listView);
67 
68  // -- mask properties
69  auto* maskPropertiesGroup = new QGroupBox("Mask properties", this);
70  maskPropertiesGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
71  m_maskPropertiesLayout = new QFormLayout(maskPropertiesGroup);
72  m_maskPropertiesLayout->setContentsMargins(8, 8, 8, 8);
73  GroupBoxCollapser::installIntoGroupBox(maskPropertiesGroup);
74 
75  mainLayout->addWidget(plotPropertiesGroup);
76  mainLayout->addWidget(maskStackGroup);
77  mainLayout->addWidget(maskPropertiesGroup);
78  mainLayout->addSpacerItem(
79  new QSpacerItem(0, 10, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
80 
81  setLayout(mainLayout);
82 }
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
Widget to edit properties of an IntensityDataItem.
IntensityDataPropertyWidget * m_plotPropertyEditor
IntensityDataItem * m_intensityDataItem
void onCustomContextMenuRequested(const QPoint &point)
MaskItem * m_currentMaskItem
the mask item whose properties shall be edited

References GroupBoxCollapser::installIntoGroupBox(), m_listView, m_maskPropertiesLayout, m_plotPropertyEditor, and onCustomContextMenuRequested().

Here is the call graph for this function:

Member Function Documentation

◆ addMaskCheckBox()

void MaskEditorPropertyPanel::addMaskCheckBox ( const QString &  title,
function< bool()>  getter,
function< void(bool)>  setter 
)
private

Add a checkbox to edit a mask's boolean value.

Definition at line 236 of file MaskEditorPropertyPanel.cpp.

238 {
239  auto* checkBox = new QCheckBox(title, m_maskPropertiesLayout->parentWidget());
240  checkBox->setChecked(getter());
241  connect(checkBox, &QCheckBox::stateChanged, [=]() { setter(checkBox->isChecked()); });
242 
243  // listen on property change
245  [=](const QString&) {
246  QSignalBlocker b(checkBox);
247  checkBox->setChecked(getter());
248  },
249  this);
250 
251  m_maskPropertiesLayout->addRow(checkBox);
252 }
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:39
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.

References m_currentMaskItem, m_maskPropertiesLayout, SessionItem::mapper(), and ModelMapper::setOnPropertyChange().

Referenced by createMaskEditorUI().

Here is the call graph for this function:

◆ addMaskSpinBox()

void MaskEditorPropertyPanel::addMaskSpinBox ( DoubleDescriptor  d)
private

Add a spinbox to edit a mask's double value.

Definition at line 223 of file MaskEditorPropertyPanel.cpp.

224 {
225  auto* spinBox = new DoubleSpinBox(m_maskPropertiesLayout->parentWidget(), d);
226  spinBox->setBaseValue(d.get());
227  QObject::connect(spinBox, &DoubleSpinBox::baseValueChanged,
228  [=](double newValue) { d.set(newValue); });
229 
231  [=](const QString&) { spinBox->updateValue(); }, this);
232 
233  m_maskPropertiesLayout->addRow(d.label + ":", spinBox);
234 }
QString label
A label text (short, no trailing colon)
function< void(double)> set
function to set the value
function< double()> get
function to get the current value
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.

References DoubleSpinBox::baseValueChanged(), DoubleDescriptor::get, DoubleDescriptor::label, m_currentMaskItem, m_maskPropertiesLayout, SessionItem::mapper(), DoubleDescriptor::set, and ModelMapper::setOnPropertyChange().

Referenced by createMaskEditorUI().

Here is the call graph for this function:

◆ createMaskEditorUI()

void MaskEditorPropertyPanel::createMaskEditorUI ( )
private

Creates the UI to edit the current mask's properties.

Definition at line 178 of file MaskEditorPropertyPanel.cpp.

179 {
180  if (!m_currentMaskItem)
181  return;
182 
183  auto* maskItem = m_currentMaskItem; // shorthand
184  // -- mask value (only if not RoI)
185  if (!dynamic_cast<RegionOfInterestItem*>(maskItem)) {
186  const auto maskValueGetter = [=] { return maskItem->maskValue(); };
187  const auto maskValueSetter = [=](bool b) { maskItem->setMaskValue(b); };
188  addMaskCheckBox("Mask value", maskValueGetter, maskValueSetter);
189  }
190  // -- mask visibility
191  const auto visibilityValueGetter = [=] { return maskItem->isVisibleValue(); };
192  const auto visibilityValueSetter = [=](bool b) {
194  maskItem->setIsVisibleValue(b);
195  m_inhibitSelectionChange = false;
196  };
197  addMaskCheckBox("Show", visibilityValueGetter, visibilityValueSetter);
198 
199  // -- name (only if not RoI)
200  if (!dynamic_cast<RegionOfInterestItem*>(maskItem)) {
201  auto* edit = new QLineEdit(maskItem->maskName(), m_maskPropertiesLayout->parentWidget());
202  connect(edit, &QLineEdit::textEdited, [=](const QString& t) { maskItem->setMaskName(t); });
203  m_maskPropertiesLayout->addRow("Name:", edit);
204  }
205 
206  if (auto* c = dynamic_cast<RectangleItem*>(maskItem)) {
207  addMaskSpinBox(c->xLow());
208  addMaskSpinBox(c->yLow());
209  addMaskSpinBox(c->xUp());
210  addMaskSpinBox(c->yUp());
211  } else if (auto* c = dynamic_cast<EllipseItem*>(maskItem)) {
212  addMaskSpinBox(c->xCenter());
213  addMaskSpinBox(c->yCenter());
214  addMaskSpinBox(c->xRadius());
215  addMaskSpinBox(c->yRadius());
216  addMaskSpinBox(c->angle());
217  } else if (auto* c = dynamic_cast<VerticalLineItem*>(maskItem))
218  addMaskSpinBox(c->posX());
219  else if (auto* c = dynamic_cast<HorizontalLineItem*>(maskItem))
220  addMaskSpinBox(c->posY());
221 }
void addMaskSpinBox(DoubleDescriptor d)
Add a spinbox to edit a mask's double value.
void addMaskCheckBox(const QString &title, function< bool()> getter, function< void(bool)> setter)
Add a checkbox to edit a mask's boolean value.
bool maskValue() const
Definition: MaskItems.cpp:80

References addMaskCheckBox(), addMaskSpinBox(), m_currentMaskItem, m_inhibitSelectionChange, m_maskPropertiesLayout, and MaskItem::maskValue().

Referenced by setCurrentMaskItem().

Here is the call graph for this function:

◆ itemContextMenuRequest

void MaskEditorPropertyPanel::itemContextMenuRequest ( const QPoint &  point)
signal

◆ maskItemForIndex()

MaskItem * MaskEditorPropertyPanel::maskItemForIndex ( const QModelIndex &  index)
private

Return the mask item for the given index. nullptr if index invalid or not pointing to a mask item.

Definition at line 254 of file MaskEditorPropertyPanel.cpp.

255 {
256  return dynamic_cast<MaskItem*>(m_maskModel->itemForIndex(index));
257 }
A base class for all mask items.
Definition: MaskItems.h:27
SessionItem * itemForIndex(const QModelIndex &index) const

References SessionModel::itemForIndex(), and m_maskModel.

Referenced by onSelectionChanged(), and setPanelHidden().

Here is the call graph for this function:

◆ minimumSizeHint()

QSize MaskEditorPropertyPanel::minimumSizeHint ( ) const
override

Definition at line 89 of file MaskEditorPropertyPanel.cpp.

90 {
91  return QSize(128, 128);
92 }

◆ onCustomContextMenuRequested

void MaskEditorPropertyPanel::onCustomContextMenuRequested ( const QPoint &  point)
privateslot

Definition at line 161 of file MaskEditorPropertyPanel.cpp.

162 {
163  emit itemContextMenuRequest(m_listView->mapToGlobal(point));
164 }
void itemContextMenuRequest(const QPoint &point)

References itemContextMenuRequest(), and m_listView.

Referenced by MaskEditorPropertyPanel().

◆ onSelectionChanged

void MaskEditorPropertyPanel::onSelectionChanged ( const QItemSelection &  selected,
const QItemSelection &   
)
privateslot

Definition at line 149 of file MaskEditorPropertyPanel.cpp.

151 {
153  return;
154 
155  if (!selected.empty())
156  setCurrentMaskItem(maskItemForIndex(selected.indexes().front()));
157  else
158  setCurrentMaskItem(nullptr);
159 }
MaskItem * maskItemForIndex(const QModelIndex &index)
Return the mask item for the given index. nullptr if index invalid or not pointing to a mask item.
void setCurrentMaskItem(MaskItem *maskItem)
Set the current mask and creates the UI to edit the mask's properties.

References m_inhibitSelectionChange, maskItemForIndex(), and setCurrentMaskItem().

Referenced by setMaskContext().

Here is the call graph for this function:

◆ resetContext()

void MaskEditorPropertyPanel::resetContext ( )

Definition at line 113 of file MaskEditorPropertyPanel.cpp.

114 {
115  m_maskModel = nullptr;
116  m_rootIndex = {};
117  m_intensityDataItem = nullptr;
118  m_listView->setModel(nullptr);
119  setCurrentMaskItem(nullptr);
120  m_plotPropertyEditor->setItem(nullptr);
121 }
void setItem(IntensityDataItem *mainItem, IntensityDataItem *realItem=nullptr)

References m_intensityDataItem, m_listView, m_maskModel, m_plotPropertyEditor, m_rootIndex, setCurrentMaskItem(), and IntensityDataPropertyWidget::setItem().

Referenced by MaskEditor::resetContext().

Here is the call graph for this function:

◆ selectionModel()

QItemSelectionModel * MaskEditorPropertyPanel::selectionModel ( )

Definition at line 123 of file MaskEditorPropertyPanel.cpp.

124 {
125  ASSERT(m_listView);
126  return m_listView->selectionModel();
127 }

References m_listView.

Referenced by MaskEditor::setMaskContext(), and setPanelHidden().

◆ setCurrentMaskItem()

void MaskEditorPropertyPanel::setCurrentMaskItem ( MaskItem maskItem)
private

Set the current mask and creates the UI to edit the mask's properties.

Definition at line 166 of file MaskEditorPropertyPanel.cpp.

167 {
168  if (m_currentMaskItem)
170 
172 
173  m_currentMaskItem = maskItem;
174 
176 }
void createMaskEditorUI()
Creates the UI to edit the current mask's properties.
void unsubscribe(const void *caller)
Cancels all subscriptions of given caller.
Definition: ModelMapper.cpp:78
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:68

References GUI::Util::Layout::clearLayout(), createMaskEditorUI(), m_currentMaskItem, m_maskPropertiesLayout, SessionItem::mapper(), and ModelMapper::unsubscribe().

Referenced by onSelectionChanged(), resetContext(), and setPanelHidden().

Here is the call graph for this function:

◆ setMaskContext()

void MaskEditorPropertyPanel::setMaskContext ( SessionModel model,
const QModelIndex &  maskContainerIndex,
IntensityDataItem intensityItem 
)

Definition at line 94 of file MaskEditorPropertyPanel.cpp.

97 {
98  m_maskModel = model;
99  m_rootIndex = maskContainerIndex;
100  m_intensityDataItem = intensityItem;
101 
102  m_listView->setModel(m_maskModel);
103  m_listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
104 
105  m_listView->setRootIndex(m_rootIndex);
106 
107  connect(m_listView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
108  &MaskEditorPropertyPanel::onSelectionChanged, Qt::UniqueConnection);
109 
111 }
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &)

References m_intensityDataItem, m_listView, m_maskModel, m_plotPropertyEditor, m_rootIndex, onSelectionChanged(), and IntensityDataPropertyWidget::setItem().

Referenced by MaskEditor::setMaskContext().

Here is the call graph for this function:

◆ setPanelHidden()

void MaskEditorPropertyPanel::setPanelHidden ( bool  hidden)

Show/Hide panel. When panel is hidden, all property editors are disabled.

Definition at line 130 of file MaskEditorPropertyPanel.cpp.

131 {
132  setHidden(hidden);
133 
134  if (!m_rootIndex.isValid())
135  return;
136 
137  if (hidden) {
138  setCurrentMaskItem(nullptr);
139  m_plotPropertyEditor->setItem(nullptr);
140  } else {
141  QModelIndexList indexes = selectionModel()->selectedIndexes();
142  if (!indexes.empty())
143  setCurrentMaskItem(maskItemForIndex(indexes.front()));
144 
146  }
147 }
QItemSelectionModel * selectionModel()

References m_intensityDataItem, m_plotPropertyEditor, m_rootIndex, maskItemForIndex(), selectionModel(), setCurrentMaskItem(), and IntensityDataPropertyWidget::setItem().

Referenced by MaskEditor::MaskEditor(), and MaskEditor::onPropertyPanelRequest().

Here is the call graph for this function:

◆ sizeHint()

QSize MaskEditorPropertyPanel::sizeHint ( ) const
override

Definition at line 84 of file MaskEditorPropertyPanel.cpp.

85 {
86  return QSize(128, 128);
87 }

Member Data Documentation

◆ m_currentMaskItem

MaskItem* MaskEditorPropertyPanel::m_currentMaskItem
private

the mask item whose properties shall be edited

Definition at line 84 of file MaskEditorPropertyPanel.h.

Referenced by addMaskCheckBox(), addMaskSpinBox(), createMaskEditorUI(), and setCurrentMaskItem().

◆ m_inhibitSelectionChange

bool MaskEditorPropertyPanel::m_inhibitSelectionChange
private

Definition at line 85 of file MaskEditorPropertyPanel.h.

Referenced by createMaskEditorUI(), and onSelectionChanged().

◆ m_intensityDataItem

IntensityDataItem* MaskEditorPropertyPanel::m_intensityDataItem
private

Definition at line 82 of file MaskEditorPropertyPanel.h.

Referenced by resetContext(), setMaskContext(), and setPanelHidden().

◆ m_listView

QListView* MaskEditorPropertyPanel::m_listView
private

◆ m_maskModel

SessionModel* MaskEditorPropertyPanel::m_maskModel
private

Definition at line 80 of file MaskEditorPropertyPanel.h.

Referenced by maskItemForIndex(), resetContext(), and setMaskContext().

◆ m_maskPropertiesLayout

QFormLayout* MaskEditorPropertyPanel::m_maskPropertiesLayout
private

◆ m_plotPropertyEditor

IntensityDataPropertyWidget* MaskEditorPropertyPanel::m_plotPropertyEditor
private

◆ m_rootIndex

QModelIndex MaskEditorPropertyPanel::m_rootIndex
private

Definition at line 81 of file MaskEditorPropertyPanel.h.

Referenced by resetContext(), setMaskContext(), and setPanelHidden().


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