BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialEditor Class Reference

Main widget of MaterialEditor. More...

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

Public Member Functions

 MaterialEditor (MaterialModel *materialModel, QWidget *parent=nullptr)
 
bool modelWasChanged () const
 
MaterialItemselectedMaterial ()
 
QItemSelectionModel * selectionModel ()
 
void setInitialMaterialProperty (const ExternalProperty &matProperty)
 Sets selection corresponding to initial material property. More...
 

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *event)
 Context menu reimplemented to supress default menu. More...
 

Private Slots

void onDataChanged (const QModelIndex &, const QModelIndex &, const QVector< int > &)
 
void onRowsInserted (const QModelIndex &, int, int)
 
void onRowsRemoved (const QModelIndex &, int, int)
 
void onSelectionChanged (const QItemSelection &selected, const QItemSelection &)
 

Private Member Functions

void init_views ()
 

Private Attributes

ComponentEditorm_componentEditor
 
QListView * m_listView
 
MaterialModelm_materialModel
 
bool m_model_was_modified
 
QSplitter * m_splitter
 
MaterialEditorToolBarm_toolBar
 

Detailed Description

Main widget of MaterialEditor.

Definition at line 32 of file MaterialEditor.h.

Constructor & Destructor Documentation

◆ MaterialEditor()

MaterialEditor::MaterialEditor ( MaterialModel materialModel,
QWidget *  parent = nullptr 
)

Definition at line 26 of file MaterialEditor.cpp.

27  : QWidget(parent)
28  , m_materialModel(materialModel)
29  , m_toolBar(new MaterialEditorToolBar(materialModel, this))
30  , m_splitter(new QSplitter)
31  , m_listView(new QListView)
33  , m_model_was_modified(false)
34 {
35  setWindowTitle("MaterialEditorWidget");
36  setMinimumSize(128, 128);
37  resize(512, 400);
38  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
39 
40  QVBoxLayout* layout = new QVBoxLayout;
41  layout->setContentsMargins(0, 0, 0, 0);
42 
43  m_splitter->addWidget(m_listView);
44  m_splitter->addWidget(m_componentEditor);
45  m_splitter->setCollapsible(0, false);
46  m_splitter->setCollapsible(1, false);
47 
48  layout->addWidget(m_toolBar);
49  layout->addWidget(m_splitter);
50 
51  setLayout(layout);
52 
53  init_views();
54 }
Component editor for SessionItem.
Toolbar for MaterialEditor.
MaterialModel * m_materialModel
MaterialEditorToolBar * m_toolBar
bool m_model_was_modified
QSplitter * m_splitter
ComponentEditor * m_componentEditor
QListView * m_listView

References init_views(), m_componentEditor, m_listView, m_splitter, and m_toolBar.

Here is the call graph for this function:

Member Function Documentation

◆ contextMenuEvent()

void MaterialEditor::contextMenuEvent ( QContextMenuEvent *  event)
protected

Context menu reimplemented to supress default menu.

Definition at line 113 of file MaterialEditor.cpp.

114 {
115  Q_UNUSED(event);
116 }

◆ init_views()

void MaterialEditor::init_views ( )
private

Definition at line 118 of file MaterialEditor.cpp.

119 {
120  connect(m_materialModel, &MaterialModel::dataChanged, this, &MaterialEditor::onDataChanged);
121  connect(m_materialModel, &MaterialModel::rowsInserted, this, &MaterialEditor::onRowsInserted);
122  connect(m_materialModel, &MaterialModel::rowsRemoved, this, &MaterialEditor::onRowsRemoved);
123 
124  m_listView->setContextMenuPolicy(Qt::CustomContextMenu);
126  m_listView->setMovement(QListView::Static);
127  m_listView->setMinimumWidth(50);
128  m_listView->setMaximumWidth(220);
129  m_listView->setSpacing(5);
130 
132 
133  connect(selectionModel(), &QItemSelectionModel::selectionChanged, this,
135 
136  // making first material selected
137  if (!selectionModel()->hasSelection()) {
138  QModelIndex itemIndex = m_materialModel->index(0, 0, QModelIndex());
139  selectionModel()->select(itemIndex, QItemSelectionModel::ClearAndSelect);
140  }
141 
142  connect(m_listView, &QListView::customContextMenuRequested, m_toolBar,
144 }
void setSelectionModel(QItemSelectionModel *selectionModel)
void onCustomContextMenuRequested(const QPoint &point)
void onDataChanged(const QModelIndex &, const QModelIndex &, const QVector< int > &)
void onRowsInserted(const QModelIndex &, int, int)
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &)
QItemSelectionModel * selectionModel()
void onRowsRemoved(const QModelIndex &, int, int)
Provides decorations (text color, icons, etc) for SessionModel in SessionModelView context.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const

References SessionModel::index(), m_listView, m_materialModel, m_toolBar, MaterialEditorToolBar::onCustomContextMenuRequested(), onDataChanged(), onRowsInserted(), onRowsRemoved(), onSelectionChanged(), selectionModel(), and MaterialEditorToolBar::setSelectionModel().

Referenced by MaterialEditor().

Here is the call graph for this function:

◆ modelWasChanged()

bool MaterialEditor::modelWasChanged ( ) const

Definition at line 80 of file MaterialEditor.cpp.

81 {
82  return m_model_was_modified;
83 }

References m_model_was_modified.

Referenced by MaterialEditorDialog::onOKButton().

◆ onDataChanged

void MaterialEditor::onDataChanged ( const QModelIndex &  ,
const QModelIndex &  ,
const QVector< int > &   
)
privateslot

Definition at line 97 of file MaterialEditor.cpp.

98 {
99  m_model_was_modified = true;
100 }

References m_model_was_modified.

Referenced by init_views().

◆ onRowsInserted

void MaterialEditor::onRowsInserted ( const QModelIndex &  ,
int  ,
int   
)
privateslot

Definition at line 102 of file MaterialEditor.cpp.

103 {
104  m_model_was_modified = true;
105 }

References m_model_was_modified.

Referenced by init_views().

◆ onRowsRemoved

void MaterialEditor::onRowsRemoved ( const QModelIndex &  ,
int  ,
int   
)
privateslot

Definition at line 107 of file MaterialEditor.cpp.

108 {
109  m_model_was_modified = true;
110 }

References m_model_was_modified.

Referenced by init_views().

◆ onSelectionChanged

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

Definition at line 85 of file MaterialEditor.cpp.

86 {
87  QModelIndexList indices = selected.indexes();
88 
89  if (indices.isEmpty()) {
90  m_componentEditor->setItem(nullptr);
91  } else {
92  if (SessionItem* item = m_materialModel->itemForIndex(indices.front()))
94  }
95 }
void setItem(SessionItem *item)
SessionItem * itemForIndex(const QModelIndex &index) const

References SessionModel::itemForIndex(), m_componentEditor, m_materialModel, and ComponentEditor::setItem().

Referenced by init_views().

Here is the call graph for this function:

◆ selectedMaterial()

MaterialItem * MaterialEditor::selectedMaterial ( )

Definition at line 62 of file MaterialEditor.cpp.

63 {
64  auto selected = selectionModel()->currentIndex();
65  return selected.isValid() ? m_materialModel->materialFromIndex(selected) : nullptr;
66 }
MaterialItem * materialFromIndex(const QModelIndex &index)

References m_materialModel, MaterialModel::materialFromIndex(), and selectionModel().

Referenced by MaterialEditorDialog::selectedMaterialProperty().

Here is the call graph for this function:

◆ selectionModel()

QItemSelectionModel * MaterialEditor::selectionModel ( )

Definition at line 56 of file MaterialEditor.cpp.

57 {
59  return m_listView->selectionModel();
60 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT, and m_listView.

Referenced by init_views(), selectedMaterial(), and setInitialMaterialProperty().

◆ setInitialMaterialProperty()

void MaterialEditor::setInitialMaterialProperty ( const ExternalProperty matProperty)

Sets selection corresponding to initial material property.

Definition at line 69 of file MaterialEditor.cpp.

70 {
72  selectionModel()->clearSelection();
73  selectionModel()->setCurrentIndex(m_materialModel->indexOfItem(mat),
74  QItemSelectionModel::ClearAndSelect);
76  QItemSelectionModel::ClearAndSelect);
77  }
78 }
QString identifier() const
MaterialItem * materialFromIdentifier(const QString &identifier)
QModelIndex indexOfItem(SessionItem *item) const

References ExternalProperty::identifier(), SessionModel::indexOfItem(), m_materialModel, MaterialModel::materialFromIdentifier(), and selectionModel().

Referenced by MaterialEditorDialog::setMaterialProperty().

Here is the call graph for this function:

Member Data Documentation

◆ m_componentEditor

ComponentEditor* MaterialEditor::m_componentEditor
private

Definition at line 62 of file MaterialEditor.h.

Referenced by MaterialEditor(), and onSelectionChanged().

◆ m_listView

QListView* MaterialEditor::m_listView
private

Definition at line 61 of file MaterialEditor.h.

Referenced by MaterialEditor(), init_views(), and selectionModel().

◆ m_materialModel

MaterialModel* MaterialEditor::m_materialModel
private

◆ m_model_was_modified

bool MaterialEditor::m_model_was_modified
private

Definition at line 63 of file MaterialEditor.h.

Referenced by modelWasChanged(), onDataChanged(), onRowsInserted(), and onRowsRemoved().

◆ m_splitter

QSplitter* MaterialEditor::m_splitter
private

Definition at line 60 of file MaterialEditor.h.

Referenced by MaterialEditor().

◆ m_toolBar

MaterialEditorToolBar* MaterialEditor::m_toolBar
private

Definition at line 59 of file MaterialEditor.h.

Referenced by MaterialEditor(), and init_views().


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