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

Description

Sample editor with layer oriented presentation of a sample.

Definition at line 31 of file LayerOrientedSampleEditor.h.

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

Signals

void aboutToRemoveItem (SampleItem item)
 
void modified ()
 
void requestCreateNewSample ()
 
void requestViewInRealSpace (SampleItem itemToShow)
 

Public Member Functions

 LayerOrientedSampleEditor (QWidget *parent, ProjectDocument *document)
 
 ~LayerOrientedSampleEditor () override
 
void setCurrentSample (MultiLayerItem *sampleItem)
 

Private Member Functions

QWidget * createEmptyWidget ()
 Create empty widget with a button for sample creation. More...
 
void createLayerColors ()
 
void onShowInlineEditButtonsToggled (bool checked)
 
void onUnitActionToggled ()
 
void updateActionEnabling ()
 

Private Attributes

QAction * m_asAngstromAction
 
MultiLayerItemm_currentMultiLayerItem = nullptr
 
MultiLayerFormm_currentMultiLayerWidget
 
ProjectDocumentm_document
 
QMap< MultiLayerItem *, SampleEditorController * > m_editControllers
 
QAction * m_redoAction
 
QScrollArea * m_scrollArea
 
QAction * m_showInlineEditButtonsAction
 
QToolBar * m_toolbar
 
QAction * m_undoAction
 

Constructor & Destructor Documentation

◆ LayerOrientedSampleEditor()

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

Definition at line 28 of file LayerOrientedSampleEditor.cpp.

29  : QWidget(parent)
30  , m_currentMultiLayerWidget(nullptr)
31  , m_undoAction(nullptr)
32  , m_redoAction(nullptr)
34  , m_asAngstromAction(nullptr)
35  , m_currentMultiLayerItem(nullptr)
36  , m_document(document)
37 {
38  setAttribute(Qt::WA_StyledBackground, true);
39  setProperty("stylable", true); // for stylesheet addressing
40 
41  m_scrollArea = new QScrollArea(this);
42  m_scrollArea->setWidgetResizable(true);
43  m_scrollArea->setWidget(createEmptyWidget());
44 
45  m_toolbar = new StyledToolbar(this);
46  m_toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
47 
48  auto* mainLayout = new QVBoxLayout(this);
49  mainLayout->setContentsMargins(0, 0, 0, 0);
50  mainLayout->setSpacing(0);
51  mainLayout->addWidget(m_toolbar);
52  mainLayout->addWidget(m_scrollArea);
53 
54  m_showInlineEditButtonsAction = new QAction(QIcon(":/images/edit.svg"), "Edit structure", this);
55  connect(m_showInlineEditButtonsAction, &QAction::toggled, this,
57  m_showInlineEditButtonsAction->setCheckable(true);
58  m_showInlineEditButtonsAction->setChecked(true);
60 
61  m_asAngstromAction = new QAction(this);
62  m_asAngstromAction->setIcon(QIcon(":/images/unit_angstrom.svg"));
63  m_asAngstromAction->setToolTip(u8"Use \u00c5ngstrom as unit (where applicable)");
64  connect(m_asAngstromAction, &QAction::toggled, this,
66  m_asAngstromAction->setCheckable(true);
67 
68  auto* asNanometerAction = new QAction(this);
69  asNanometerAction->setIcon(QIcon(":/images/unit_nm.svg"));
70  asNanometerAction->setToolTip("Use nanometer as unit (where applicable)");
71  connect(asNanometerAction, &QAction::toggled, this,
73  asNanometerAction->setCheckable(true);
74 
75  auto* ag = new QActionGroup(this);
76  ag->addAction(asNanometerAction);
77  ag->addAction(m_asAngstromAction);
79  m_asAngstromAction->setChecked(true);
80  else
81  asNanometerAction->setChecked(true);
82 
83  m_toolbar->addActions(ag->actions());
84 }
ApplicationSettings * appSettings
global pointer to the instance
bool defaultUnitIsAngstrom() const
void onShowInlineEditButtonsToggled(bool checked)
QWidget * createEmptyWidget()
Create empty widget with a button for sample creation.
The StyledToolbar class represents our standard narrow toolbar with the height 24 pixels.
Definition: StyledToolbar.h:22

References appSettings, createEmptyWidget(), ApplicationSettings::defaultUnitIsAngstrom(), m_asAngstromAction, m_scrollArea, m_showInlineEditButtonsAction, m_toolbar, onShowInlineEditButtonsToggled(), and onUnitActionToggled().

Here is the call graph for this function:

◆ ~LayerOrientedSampleEditor()

LayerOrientedSampleEditor::~LayerOrientedSampleEditor ( )
override

Definition at line 86 of file LayerOrientedSampleEditor.cpp.

87 {
88  qDeleteAll(m_editControllers.values());
89 }
QMap< MultiLayerItem *, SampleEditorController * > m_editControllers

References m_editControllers.

Member Function Documentation

◆ aboutToRemoveItem

void LayerOrientedSampleEditor::aboutToRemoveItem ( SampleItem  item)
signal

◆ createEmptyWidget()

QWidget * LayerOrientedSampleEditor::createEmptyWidget ( )
private

Create empty widget with a button for sample creation.

Definition at line 180 of file LayerOrientedSampleEditor.cpp.

181 {
182  auto* emptyWidget = new QWidget(this);
183  emptyWidget->setProperty("stylable", true); // for stylesheet addressing
184 
185  auto* btn = new QPushButton("Create sample", emptyWidget);
186  connect(btn, &QPushButton::clicked, this, &LayerOrientedSampleEditor::requestCreateNewSample);
187 
188  auto* layout = new QHBoxLayout(emptyWidget);
189  layout->setContentsMargins(10, 20, 10, 20);
190  layout->addStretch();
191  layout->addWidget(btn);
192  layout->addStretch();
193  layout->setAlignment(Qt::AlignTop);
194 
195  return emptyWidget;
196 }

References requestCreateNewSample().

Referenced by LayerOrientedSampleEditor(), and setCurrentSample().

◆ createLayerColors()

void LayerOrientedSampleEditor::createLayerColors ( )
private

Definition at line 163 of file LayerOrientedSampleEditor.cpp.

164 {
166  return;
167 
168  int col = 0;
169  for (auto* l : m_currentMultiLayerItem->layers()) {
170  if (l->color().isValid())
171  continue;
172 
173  l->setColor(LayerEditorUtils::predefinedLayerColors()[col]);
174  col++;
175  if (col == LayerEditorUtils::predefinedLayerColors().size())
176  col = 0;
177  }
178 }
QVector< LayerItem * > layers() const
QList< QColor > predefinedLayerColors()

References MultiLayerItem::layers(), m_currentMultiLayerItem, and LayerEditorUtils::predefinedLayerColors().

Referenced by setCurrentSample().

Here is the call graph for this function:

◆ modified

void LayerOrientedSampleEditor::modified ( )
signal

◆ onShowInlineEditButtonsToggled()

void LayerOrientedSampleEditor::onShowInlineEditButtonsToggled ( bool  checked)
private

Definition at line 151 of file LayerOrientedSampleEditor.cpp.

152 {
155 }
void showInlineEditButtons(bool b)
Show or hide all buttons related to structure editing (like "add layer", "remove particle")

References m_currentMultiLayerWidget, and MultiLayerForm::showInlineEditButtons().

Referenced by LayerOrientedSampleEditor().

Here is the call graph for this function:

◆ onUnitActionToggled()

void LayerOrientedSampleEditor::onUnitActionToggled ( )
private

Definition at line 157 of file LayerOrientedSampleEditor.cpp.

158 {
161 }
void setUseAngstrom(bool angstrom)
Show values in Angstrom or nanometers.

References m_asAngstromAction, m_currentMultiLayerWidget, and MultiLayerForm::setUseAngstrom().

Referenced by LayerOrientedSampleEditor().

Here is the call graph for this function:

◆ requestCreateNewSample

void LayerOrientedSampleEditor::requestCreateNewSample ( )
signal

◆ requestViewInRealSpace

void LayerOrientedSampleEditor::requestViewInRealSpace ( SampleItem  itemToShow)
signal

◆ setCurrentSample()

void LayerOrientedSampleEditor::setCurrentSample ( MultiLayerItem sampleItem)

Definition at line 91 of file LayerOrientedSampleEditor.cpp.

92 {
93  if (m_currentMultiLayerItem != nullptr)
94  m_editControllers[m_currentMultiLayerItem]->setMultiLayerForm(nullptr);
95 
96  m_currentMultiLayerWidget = nullptr;
97  delete m_scrollArea->takeWidget();
98 
99  // use the correct toolbar buttons (from correct undo stack)
100  delete m_undoAction;
101  m_undoAction = nullptr;
102  delete m_redoAction;
103  m_redoAction = nullptr;
104 
105  m_currentMultiLayerItem = sampleItem;
106  if (m_currentMultiLayerItem == nullptr) {
107  m_scrollArea->setWidget(createEmptyWidget());
109  return;
110  }
111 
121 
122  m_undoAction = ec->undoStack()->createUndoAction(this);
123  m_redoAction = ec->undoStack()->createRedoAction(this);
124  m_undoAction->setIcon(QIcon(":/images/undo-variant.svg"));
125  m_redoAction->setIcon(QIcon(":/images/redo.svg"));
126 
127  m_toolbar->addAction(m_undoAction);
128  m_toolbar->addAction(m_redoAction);
129 
131 
133  ec->setMultiLayerForm(m_currentMultiLayerWidget);
134  m_currentMultiLayerWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
138 
140 }
void aboutToRemoveItem(SampleItem item)
void requestViewInRealSpace(SampleItem itemToShow)
Form to present/edit a MultiLayer (sample)
Class to modify a sample from the layer oriented sample editor.
void requestViewInRealSpace(SampleItem item)
void aboutToRemoveItem(SampleItem item)

References aboutToRemoveItem(), SampleEditorController::aboutToRemoveItem(), createEmptyWidget(), createLayerColors(), m_asAngstromAction, m_currentMultiLayerItem, m_currentMultiLayerWidget, m_document, m_editControllers, m_redoAction, m_scrollArea, m_showInlineEditButtonsAction, m_toolbar, m_undoAction, modified(), SampleEditorController::modified(), SampleEditorController::requestViewInRealSpace(), requestViewInRealSpace(), MultiLayerForm::setUseAngstrom(), MultiLayerForm::showInlineEditButtons(), and updateActionEnabling().

Referenced by SampleView::SampleView().

Here is the call graph for this function:

◆ updateActionEnabling()

void LayerOrientedSampleEditor::updateActionEnabling ( )
private

Definition at line 142 of file LayerOrientedSampleEditor.cpp.

143 {
144  // Undo/Redo is not complete => hide the related buttons/actions
145  if (m_undoAction)
146  m_undoAction->setVisible(false);
147  if (m_redoAction)
148  m_redoAction->setVisible(false);
149 }

References m_redoAction, and m_undoAction.

Referenced by setCurrentSample().

Member Data Documentation

◆ m_asAngstromAction

QAction* LayerOrientedSampleEditor::m_asAngstromAction
private

◆ m_currentMultiLayerItem

MultiLayerItem* LayerOrientedSampleEditor::m_currentMultiLayerItem = nullptr
private

Definition at line 63 of file LayerOrientedSampleEditor.h.

Referenced by createLayerColors(), and setCurrentSample().

◆ m_currentMultiLayerWidget

MultiLayerForm* LayerOrientedSampleEditor::m_currentMultiLayerWidget
private

◆ m_document

ProjectDocument* LayerOrientedSampleEditor::m_document
private

Definition at line 65 of file LayerOrientedSampleEditor.h.

Referenced by setCurrentSample().

◆ m_editControllers

QMap<MultiLayerItem*, SampleEditorController*> LayerOrientedSampleEditor::m_editControllers
private

Definition at line 64 of file LayerOrientedSampleEditor.h.

Referenced by ~LayerOrientedSampleEditor(), and setCurrentSample().

◆ m_redoAction

QAction* LayerOrientedSampleEditor::m_redoAction
private

Definition at line 60 of file LayerOrientedSampleEditor.h.

Referenced by setCurrentSample(), and updateActionEnabling().

◆ m_scrollArea

QScrollArea* LayerOrientedSampleEditor::m_scrollArea
private

Definition at line 57 of file LayerOrientedSampleEditor.h.

Referenced by LayerOrientedSampleEditor(), and setCurrentSample().

◆ m_showInlineEditButtonsAction

QAction* LayerOrientedSampleEditor::m_showInlineEditButtonsAction
private

Definition at line 61 of file LayerOrientedSampleEditor.h.

Referenced by LayerOrientedSampleEditor(), and setCurrentSample().

◆ m_toolbar

QToolBar* LayerOrientedSampleEditor::m_toolbar
private

Definition at line 58 of file LayerOrientedSampleEditor.h.

Referenced by LayerOrientedSampleEditor(), and setCurrentSample().

◆ m_undoAction

QAction* LayerOrientedSampleEditor::m_undoAction
private

Definition at line 59 of file LayerOrientedSampleEditor.h.

Referenced by setCurrentSample(), and updateActionEnabling().


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