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

Description

Definition at line 28 of file SampleView.h.

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

Public Types

enum  ESubWindows { PYTHONPANEL , REALSPACEPANEL , SAMPLE_LIST }
 

Public Member Functions

 SampleView (QWidget *parent, ProjectDocument *document)
 
void fillViewMenu (QMenu *menu)
 
void toggleRealSpaceView ()
 

Protected Member Functions

void showEvent (QShowEvent *) override
 

Private Member Functions

void onAboutToRemoveItem (SampleItem item)
 
void onRequestViewInRealSpace (SampleItem itemToView)
 Show the item in the real space view. More...
 
void resetLayout ()
 
void updateSingleSampleMode ()
 

Private Attributes

DocksControllerm_docks = nullptr
 
ProjectDocumentm_document = nullptr
 
RealSpacePanelm_realSpacePanel = nullptr
 
SampleListViewm_sampleSelectionView = nullptr
 

Member Enumeration Documentation

◆ ESubWindows

Enumerator
PYTHONPANEL 
REALSPACEPANEL 
SAMPLE_LIST 

Definition at line 31 of file SampleView.h.

Constructor & Destructor Documentation

◆ SampleView()

SampleView::SampleView ( QWidget *  parent,
ProjectDocument document 
)

Definition at line 34 of file SampleView.cpp.

35  : QMainWindow(parent)
36  , m_document(document)
37 {
38  setObjectName("SampleView");
39 
42 
43  m_docks = new DocksController(this);
44 
45  auto* editor = new LayerOrientedSampleEditor(this, document);
46 
47  auto* sampleSelectionPane = new QWidget(this);
48  auto* sampleSelectionLayout = new QVBoxLayout(sampleSelectionPane);
49  sampleSelectionLayout->setContentsMargins(0, 0, 0, 0);
50  sampleSelectionLayout->setSpacing(0);
51 
52  auto* sampleSelectionToolbar = new StyledToolbar(sampleSelectionPane);
54  sampleSelectionToolbar->addAction(m_sampleSelectionView->newSampleAction());
55 #ifdef BORNAGAIN_PYTHON
56  sampleSelectionToolbar->addAction(m_sampleSelectionView->importSampleAction());
57 #endif
58  sampleSelectionToolbar->addAction(m_sampleSelectionView->chooseFromLibraryAction());
59  if (auto* btn = dynamic_cast<QToolButton*>(sampleSelectionToolbar->widgetForAction(
61  btn->setPopupMode(QToolButton::InstantPopup);
62 
63  sampleSelectionToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
64  sampleSelectionLayout->addWidget(sampleSelectionToolbar);
65  sampleSelectionLayout->addWidget(m_sampleSelectionView);
66  m_sampleSelectionView->setSizePolicy(QSizePolicy::MinimumExpanding,
67  QSizePolicy::MinimumExpanding);
68 
69  auto* scriptPanel = new ScriptPanel(this);
70  m_realSpacePanel = new RealSpacePanel(this);
71 
72  sampleSelectionPane->setWindowTitle("Samples");
73 
74  m_docks->addWidget(SAMPLE_LIST, sampleSelectionPane, Qt::LeftDockWidgetArea);
75  m_docks->addWidget(REALSPACEPANEL, m_realSpacePanel, Qt::BottomDockWidgetArea);
76  m_docks->addWidget(PYTHONPANEL, scriptPanel, Qt::BottomDockWidgetArea);
77 
80 
83 
86 
87  connect(editor, &LayerOrientedSampleEditor::modified, scriptPanel,
89 
92 
95 
96  connect(editor, &LayerOrientedSampleEditor::aboutToRemoveItem, this,
98 
100  m_sampleSelectionView->newSampleAction(), &QAction::trigger, Qt::QueuedConnection);
101 
104 
106  Qt::UniqueConnection);
107 
108  setCentralWidget(editor);
109  resetLayout();
110 }
Handles creation and appearance of docked widgets in the context of QMainWindow. It is used for Sampl...
void addWidget(int id, QWidget *widget, Qt::DockWidgetArea area)
Sample editor with layer oriented presentation of a sample.
void setCurrentSample(MultiLayerItem *sampleItem)
void aboutToRemoveItem(SampleItem item)
void requestViewInRealSpace(SampleItem itemToShow)
void singleSampleModeChanged()
Emitted when single sample mode has changed.
Panel to show 3D view of sample. Contains toolbar and RealSpaceCanvas.
RealSpaceCanvas * canvas()
List view to select one sample (left side of layer-oriented sample editor)
QAction * chooseFromLibraryAction()
QAction * importSampleAction()
void currentSampleChanged(MultiLayerItem *current)
QAction * newSampleAction()
void onAboutToRemoveItem(SampleItem item)
Definition: SampleView.cpp:136
RealSpacePanel * m_realSpacePanel
Definition: SampleView.h:54
void resetLayout()
Definition: SampleView.cpp:193
SampleListView * m_sampleSelectionView
Definition: SampleView.h:55
void updateSingleSampleMode()
Definition: SampleView.cpp:112
ProjectDocument * m_document
Definition: SampleView.h:53
void onRequestViewInRealSpace(SampleItem itemToView)
Show the item in the real space view.
Definition: SampleView.cpp:117
DocksController * m_docks
Definition: SampleView.h:52
Resides at the bottom of SampleView and displays a Python script.
Definition: ScriptPanel.h:31
void onSampleModified()
Definition: ScriptPanel.cpp:67
void setCurrentSample(MultiLayerItem *sampleItem)
Definition: ScriptPanel.cpp:61
The StyledToolbar class represents our standard narrow toolbar with the height 24 pixels.
Definition: StyledToolbar.h:22

References LayerOrientedSampleEditor::aboutToRemoveItem(), DocksController::addWidget(), RealSpacePanel::canvas(), SampleListView::chooseFromLibraryAction(), SampleListView::currentSampleChanged(), SampleListView::importSampleAction(), m_docks, m_document, m_realSpacePanel, m_sampleSelectionView, LayerOrientedSampleEditor::modified(), SampleListView::newSampleAction(), onAboutToRemoveItem(), onRequestViewInRealSpace(), SampleListView::onSampleModified(), ScriptPanel::onSampleModified(), PYTHONPANEL, REALSPACEPANEL, LayerOrientedSampleEditor::requestCreateNewSample(), LayerOrientedSampleEditor::requestViewInRealSpace(), resetLayout(), SAMPLE_LIST, LayerOrientedSampleEditor::setCurrentSample(), ScriptPanel::setCurrentSample(), ProjectDocument::setModified(), ProjectDocument::singleSampleModeChanged(), RealSpaceCanvas::updateScene(), and updateSingleSampleMode().

Here is the call graph for this function:

Member Function Documentation

◆ fillViewMenu()

void SampleView::fillViewMenu ( QMenu *  menu)

Definition at line 175 of file SampleView.cpp.

176 {
178 
179  menu->addSeparator();
180 
181  auto* action = new QAction(menu);
182  action->setText("Reset to default layout");
183  connect(action, &QAction::triggered, this, &SampleView::resetLayout);
184  menu->addAction(action);
185 }
void addDockActionsToMenu(QMenu *menu)

References DocksController::addDockActionsToMenu(), m_docks, and resetLayout().

Here is the call graph for this function:

◆ onAboutToRemoveItem()

void SampleView::onAboutToRemoveItem ( SampleItem  item)
private

Definition at line 136 of file SampleView.cpp.

137 {
138  // If an item shall be deleted from the sample, check whether RealSpace is affected.
139  // Its current item could be itemToRemmove itself, or it could be a child of itemToRemove.
140 
141  // -- for convenience access later on
142  auto* canvas = m_realSpacePanel->canvas();
143  auto* currentAsLayer = canvas->currentItemAs<LayerItem*>();
144  auto* currentAsLayout = canvas->currentItemAs<ParticleLayoutItem*>();
145  auto* currentAsParticle = canvas->currentItemAs<ItemWithParticles*>();
146  const auto resetIf = [&](bool b) {
147  if (b)
148  canvas->resetScene();
149  };
150 
151  if (itemToRemove.get_if<MultiLayerItem*>()) {
152  // -- itemToRemove is a sample. In this case: always reset
153  canvas->resetScene();
154  } else if (auto* layerToRemove = itemToRemove.get_if<LayerItem*>()) {
155  // -- itemToRemove is a layer
156  resetIf(layerToRemove == currentAsLayer);
157  resetIf(layerToRemove->layouts().contains(currentAsLayout));
158  resetIf(layerToRemove->itemsWithParticles().contains(currentAsParticle));
159  } else if (auto* layoutToRemove = itemToRemove.get_if<ParticleLayoutItem*>()) {
160  // -- itemToRemove is a particle layout
161  resetIf(layoutToRemove == currentAsLayout);
162  resetIf(layoutToRemove->containedItemsWithParticles().contains(currentAsParticle));
163  } else if (auto* particleToRemove = itemToRemove.get_if<ItemWithParticles*>()) {
164  // -- itemToRemove is a particle
165  resetIf(particleToRemove == currentAsParticle);
166  resetIf(particleToRemove->containedItemsWithParticles().contains(currentAsParticle));
167  }
168 }
T currentItemAs() const

References RealSpacePanel::canvas(), RealSpaceCanvas::currentItemAs(), SampleItem::get_if(), and m_realSpacePanel.

Referenced by SampleView().

Here is the call graph for this function:

◆ onRequestViewInRealSpace()

void SampleView::onRequestViewInRealSpace ( SampleItem  itemToView)
private

Show the item in the real space view.

If the real space view is not visible at the moment, it will be shown.

Definition at line 117 of file SampleView.cpp.

118 {
119  RealSpaceCanvas::ItemForRealSpace itemForRealSpace;
120  if (auto* p = itemToView.get_if<MultiLayerItem*>())
121  itemForRealSpace = p;
122  else if (auto* p = itemToView.get_if<LayerItem*>())
123  itemForRealSpace = p;
124  else if (auto* p = itemToView.get_if<ParticleLayoutItem*>())
125  itemForRealSpace = p;
126  else if (auto* p = itemToView.get_if<ItemWithParticles*>())
127  itemForRealSpace = p;
128  else
129  return;
130 
133  itemForRealSpace);
134 }
void setDockVisible(int id, bool visible=true)
void setCurrentItem(MultiLayerItem *containingMultiLayerItem, ItemForRealSpace item)
std::variant< MultiLayerItem *, LayerItem *, ParticleLayoutItem *, ItemWithParticles * > ItemForRealSpace
Defines the item types which can be the "current item".
T get_if()
Short version to get a contained pointer (the std::get_if would return pointer-to-pointer)
Definition: SampleItem.h:43
MultiLayerItem * currentSample()

References RealSpacePanel::canvas(), SampleListView::currentSample(), SampleItem::get_if(), m_docks, m_realSpacePanel, m_sampleSelectionView, REALSPACEPANEL, RealSpaceCanvas::setCurrentItem(), and DocksController::setDockVisible().

Referenced by SampleView().

Here is the call graph for this function:

◆ resetLayout()

void SampleView::resetLayout ( )
private

Definition at line 193 of file SampleView.cpp.

194 {
195  m_docks->resetLayout();
196 
198  m_docks->findDock(REALSPACEPANEL)->raise(); // makes first tab active
199 
200  m_docks->findDock(REALSPACEPANEL)->hide();
201  m_docks->findDock(PYTHONPANEL)->hide();
202 
203  if (auto* d = m_docks->findDock(SAMPLE_LIST)) {
205  d->hide();
206  else
207  d->show();
208  }
209 }
QDockWidget * findDock(int id)
bool singleSampleMode() const

References DocksController::findDock(), m_docks, m_document, PYTHONPANEL, REALSPACEPANEL, DocksController::resetLayout(), SAMPLE_LIST, and ProjectDocument::singleSampleMode().

Referenced by SampleView(), and fillViewMenu().

Here is the call graph for this function:

◆ showEvent()

void SampleView::showEvent ( QShowEvent *  )
overrideprotected

Definition at line 187 of file SampleView.cpp.

188 {
191 }
void selectFirstSample()
Select first sample, if any sample exists.

References SampleListView::currentSample(), m_sampleSelectionView, and SampleListView::selectFirstSample().

Here is the call graph for this function:

◆ toggleRealSpaceView()

void SampleView::toggleRealSpaceView ( )

Definition at line 170 of file SampleView.cpp.

171 {
173 }
void toggleDock(int id)

References m_docks, REALSPACEPANEL, and DocksController::toggleDock().

Here is the call graph for this function:

◆ updateSingleSampleMode()

void SampleView::updateSingleSampleMode ( )
private

Definition at line 112 of file SampleView.cpp.

References m_docks, m_document, SAMPLE_LIST, DocksController::setDockVisible(), and ProjectDocument::singleSampleMode().

Referenced by SampleView().

Here is the call graph for this function:

Member Data Documentation

◆ m_docks

DocksController* SampleView::m_docks = nullptr
private

◆ m_document

ProjectDocument* SampleView::m_document = nullptr
private

Definition at line 53 of file SampleView.h.

Referenced by SampleView(), resetLayout(), and updateSingleSampleMode().

◆ m_realSpacePanel

RealSpacePanel* SampleView::m_realSpacePanel = nullptr
private

Definition at line 54 of file SampleView.h.

Referenced by SampleView(), onAboutToRemoveItem(), and onRequestViewInRealSpace().

◆ m_sampleSelectionView

SampleListView* SampleView::m_sampleSelectionView = nullptr
private

Definition at line 55 of file SampleView.h.

Referenced by SampleView(), onRequestViewInRealSpace(), and showEvent().


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