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

Defines actions for MaskEditor which are related to selected MaskItem (toggle mask value, lower/rize mask in the stack, delete mask). More...

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

Public Slots

void onDeleteMaskAction ()
 
void onItemContextMenuRequest (const QPoint &point)
 Constructs MaskItem context menu following the request from MaskGraphicsScene or MaskEditorInfoPanel. More...
 

Signals

void propertyPanelRequest ()
 
void resetViewRequest ()
 
void savePlotRequest ()
 

Public Member Functions

 MaskEditorActions (QWidget *parent)
 
QAction * bringToFrontAction ()
 
QAction * sendToBackAction ()
 
void setModel (SessionModel *maskModel, const QModelIndex &rootIndex)
 
void setSelectionModel (QItemSelectionModel *selectionModel)
 
QList< QAction * > topToolBarActions ()
 

Private Slots

void onBringToFrontAction ()
 
void onSendToBackAction ()
 
void onToggleMaskValueAction ()
 Performs switch of mask value for all selected items (true -> false, false -> true) More...
 

Private Member Functions

void changeMaskStackingOrder (MaskEditorFlags::Stacking value)
 Lower mask one level down or rise one level up in the masks stack. More...
 
void initItemContextMenu (QMenu &menu)
 Init external context menu with currently defined actions. More...
 
bool isBringToFrontPossible () const
 Returns true if at least one of MaskItems in the selection can be moved one level up (Naturally, it is always true, if selection contains more than one item. More...
 
bool isSendToBackPossible () const
 Returns true if at least one of MaskItems in the selection can be moved one level down. More...
 
void setAllActionsEnabled (bool value)
 

Private Attributes

QAction * m_bringToFrontAction
 
QAction * m_deleteMaskAction
 
SessionModelm_maskModel
 
QAction * m_resetViewAction
 
QModelIndex m_rootIndex
 
QAction * m_savePlotAction
 
QItemSelectionModel * m_selectionModel
 Index in the model corresponding to IntensityDataItem. More...
 
QAction * m_sendToBackAction
 
QAction * m_toggleMaskValueAction
 
QAction * m_togglePanelAction
 

Detailed Description

Defines actions for MaskEditor which are related to selected MaskItem (toggle mask value, lower/rize mask in the stack, delete mask).

If more than one MaskItem is selected, action will be applied to the whole selection, if possible.

Definition at line 33 of file MaskEditorActions.h.

Constructor & Destructor Documentation

◆ MaskEditorActions()

MaskEditorActions::MaskEditorActions ( QWidget *  parent)

Definition at line 22 of file MaskEditorActions.cpp.

23  : QObject(parent)
24  , m_toggleMaskValueAction(new QAction("Toggle mask value", parent))
25  , m_bringToFrontAction(new QAction("Rise mask up", parent))
26  , m_sendToBackAction(new QAction("Lower mask down", parent))
27  , m_deleteMaskAction(new QAction("Remove mask", parent))
28  , m_resetViewAction(new QAction(this))
29  , m_savePlotAction(new QAction(this))
30  , m_togglePanelAction(new QAction(this))
31  , m_maskModel(nullptr)
32  , m_selectionModel(nullptr)
33 
34 {
35  connect(m_toggleMaskValueAction, &QAction::triggered, this,
37 
38  m_bringToFrontAction->setIcon(QIcon(":/MaskWidgets/images/maskeditor_bringtofront.svg"));
39  m_bringToFrontAction->setToolTip("Rise selected mask one level up (PgUp)");
40  m_bringToFrontAction->setShortcuts(QKeySequence::MoveToPreviousPage);
41  connect(m_bringToFrontAction, &QAction::triggered, this,
43 
44  m_sendToBackAction->setIcon(QIcon(":/MaskWidgets/images/maskeditor_sendtoback.svg"));
45  m_sendToBackAction->setToolTip("Lower selected mask one level down (PgDown)");
46  m_sendToBackAction->setShortcuts(QKeySequence::MoveToNextPage);
47  connect(m_sendToBackAction, &QAction::triggered, this, &MaskEditorActions::onSendToBackAction);
48 
49  m_deleteMaskAction->setToolTip("Remove selected mask (Del)");
50  m_deleteMaskAction->setShortcuts(QKeySequence::Delete);
51  parent->addAction(m_deleteMaskAction);
52  connect(m_deleteMaskAction, &QAction::triggered, this, &MaskEditorActions::onDeleteMaskAction);
53 
54  // Actions for top toolbar
55  m_resetViewAction->setText("Center view");
56  m_resetViewAction->setIcon(QIcon(":/images/camera-metering-center.svg"));
57  m_resetViewAction->setToolTip("Center View");
58  connect(m_resetViewAction, &QAction::triggered, this, &MaskEditorActions::resetViewRequest);
59 
60  m_savePlotAction->setText("Save");
61  m_savePlotAction->setIcon(QIcon(":/images/content-save-outline.svg"));
62  m_savePlotAction->setToolTip("Save Plot");
63  connect(m_savePlotAction, &QAction::triggered, this, &MaskEditorActions::savePlotRequest);
64 
65  m_togglePanelAction->setText("Properties");
66  m_togglePanelAction->setIcon(QIcon(":/images/dock-right.svg"));
67  m_togglePanelAction->setToolTip("Toggle Property Panel");
68  connect(m_togglePanelAction, &QAction::triggered, this,
70 }
QItemSelectionModel * m_selectionModel
Index in the model corresponding to IntensityDataItem.
QAction * m_toggleMaskValueAction
void propertyPanelRequest()
QAction * m_togglePanelAction
void onToggleMaskValueAction()
Performs switch of mask value for all selected items (true -> false, false -> true)
QAction * m_bringToFrontAction
QAction * m_sendToBackAction
QAction * m_deleteMaskAction
QAction * m_savePlotAction
SessionModel * m_maskModel
QAction * m_resetViewAction

References m_bringToFrontAction, m_deleteMaskAction, m_resetViewAction, m_savePlotAction, m_sendToBackAction, m_toggleMaskValueAction, m_togglePanelAction, onBringToFrontAction(), onDeleteMaskAction(), onSendToBackAction(), onToggleMaskValueAction(), propertyPanelRequest(), resetViewRequest(), and savePlotRequest().

Here is the call graph for this function:

Member Function Documentation

◆ bringToFrontAction()

QAction * MaskEditorActions::bringToFrontAction ( )

Definition at line 88 of file MaskEditorActions.cpp.

89 {
90  return m_bringToFrontAction;
91 }

References m_bringToFrontAction.

Referenced by MaskEditorToolBar::setup_maskmodify_group().

◆ changeMaskStackingOrder()

void MaskEditorActions::changeMaskStackingOrder ( MaskEditorFlags::Stacking  value)
private

Lower mask one level down or rise one level up in the masks stack.

Definition at line 144 of file MaskEditorActions.cpp.

145 {
146  if (!m_maskModel || !m_selectionModel)
147  return;
148 
149  int change_in_row(0);
150  if (value == MaskEditorFlags::BRING_TO_FRONT)
151  change_in_row = -1;
152  if (value == MaskEditorFlags::SEND_TO_BACK)
153  change_in_row = 2;
154 
155  QModelIndexList indexes = m_selectionModel->selectedIndexes();
156 
157  for (auto itemIndex : indexes) {
158  if (SessionItem* item = m_maskModel->itemForIndex(itemIndex)) {
159  int new_row = itemIndex.row() + change_in_row;
160  if (new_row >= 0 && new_row <= m_maskModel->rowCount(m_rootIndex)) {
161  SessionItem* newItem =
163  m_selectionModel->select(m_maskModel->indexOfItem(newItem),
164  QItemSelectionModel::Select);
165  }
166  }
167  }
168 }
QModelIndex m_rootIndex
SessionItem * itemForIndex(const QModelIndex &index) const
SessionItem * moveItem(SessionItem *item, SessionItem *new_parent=0, int row=-1, const QString &tag="")
Move given parameterized item to the new_parent at given row.
QModelIndex indexOfItem(SessionItem *item) const

References MaskEditorFlags::BRING_TO_FRONT, SessionModel::indexOfItem(), SessionModel::itemForIndex(), m_maskModel, m_rootIndex, m_selectionModel, SessionModel::moveItem(), and MaskEditorFlags::SEND_TO_BACK.

Referenced by onBringToFrontAction(), and onSendToBackAction().

Here is the call graph for this function:

◆ initItemContextMenu()

void MaskEditorActions::initItemContextMenu ( QMenu &  menu)
private

Init external context menu with currently defined actions.

Triggered from MaskGraphicsScene of MaskEditorInfoPanel (QListView)

Definition at line 206 of file MaskEditorActions.cpp.

207 {
208  if (!m_rootIndex.isValid())
209  return;
210 
213 
214  if (m_selectionModel->selectedIndexes().isEmpty())
215  setAllActionsEnabled(false);
216 
219 
220  menu.addAction(m_toggleMaskValueAction);
221  menu.addAction(m_bringToFrontAction);
222  menu.addAction(m_sendToBackAction);
223  menu.addSeparator();
224  menu.addAction(m_deleteMaskAction);
225 }
#define ASSERT(condition)
Definition: Assert.h:31
bool isSendToBackPossible() const
Returns true if at least one of MaskItems in the selection can be moved one level down.
void setAllActionsEnabled(bool value)
bool isBringToFrontPossible() const
Returns true if at least one of MaskItems in the selection can be moved one level up (Naturally,...

References ASSERT, isBringToFrontPossible(), isSendToBackPossible(), m_bringToFrontAction, m_deleteMaskAction, m_maskModel, m_rootIndex, m_selectionModel, m_sendToBackAction, m_toggleMaskValueAction, and setAllActionsEnabled().

Referenced by onItemContextMenuRequest().

Here is the call graph for this function:

◆ isBringToFrontPossible()

bool MaskEditorActions::isBringToFrontPossible ( ) const
private

Returns true if at least one of MaskItems in the selection can be moved one level up (Naturally, it is always true, if selection contains more than one item.

If selection contains only one item, the result will depend on position of item on the stack. Top item can't be moved up. Used to disable corresponding context menu line.)

Definition at line 174 of file MaskEditorActions.cpp.

175 {
176  bool result(false);
177  QModelIndexList indexes = m_selectionModel->selectedIndexes();
178  if (indexes.size() == 1 && indexes.front().row() != 0)
179  result = true;
180  return result;
181 }

References m_selectionModel.

Referenced by initItemContextMenu().

◆ isSendToBackPossible()

bool MaskEditorActions::isSendToBackPossible ( ) const
private

Returns true if at least one of MaskItems in the selection can be moved one level down.

Definition at line 184 of file MaskEditorActions.cpp.

185 {
186  bool result(false);
187  QModelIndexList indexes = m_selectionModel->selectedIndexes();
188  if (indexes.size() == 1) {
189  SessionItem* item = m_maskModel->itemForIndex(indexes.front());
190  if (indexes.front().row() != item->parent()->numberOfChildren() - 1)
191  result = true;
192  }
193  return result;
194 }
int numberOfChildren() const
Returns total number of children.
Definition: SessionItem.cpp:94
SessionItem * parent() const
Returns parent of this item.
Definition: SessionItem.cpp:73

References SessionModel::itemForIndex(), m_maskModel, m_selectionModel, SessionItem::numberOfChildren(), and SessionItem::parent().

Referenced by initItemContextMenu().

Here is the call graph for this function:

◆ onBringToFrontAction

void MaskEditorActions::onBringToFrontAction ( )
privateslot

Definition at line 133 of file MaskEditorActions.cpp.

134 {
136 }
void changeMaskStackingOrder(MaskEditorFlags::Stacking value)
Lower mask one level down or rise one level up in the masks stack.

References MaskEditorFlags::BRING_TO_FRONT, and changeMaskStackingOrder().

Referenced by MaskEditorActions().

Here is the call graph for this function:

◆ onDeleteMaskAction

void MaskEditorActions::onDeleteMaskAction ( )
slot

Definition at line 108 of file MaskEditorActions.cpp.

109 {
112 
113  QModelIndexList indexes = m_selectionModel->selectedIndexes();
114  while (indexes.size()) {
115  m_maskModel->removeRows(indexes.back().row(), 1, indexes.back().parent());
116  indexes = m_selectionModel->selectedIndexes();
117  }
118 }
virtual bool removeRows(int row, int count, const QModelIndex &parent)

References ASSERT, m_maskModel, m_selectionModel, and SessionModel::removeRows().

Referenced by MaskEditorActions(), and MaskEditor::setup_connections().

Here is the call graph for this function:

◆ onItemContextMenuRequest

void MaskEditorActions::onItemContextMenuRequest ( const QPoint &  point)
slot

Constructs MaskItem context menu following the request from MaskGraphicsScene or MaskEditorInfoPanel.

Definition at line 100 of file MaskEditorActions.cpp.

101 {
102  QMenu menu;
103  initItemContextMenu(menu);
104  menu.exec(point);
105  setAllActionsEnabled(true);
106 }
void initItemContextMenu(QMenu &menu)
Init external context menu with currently defined actions.

References initItemContextMenu(), and setAllActionsEnabled().

Referenced by MaskEditor::setup_connections().

Here is the call graph for this function:

◆ onSendToBackAction

void MaskEditorActions::onSendToBackAction ( )
privateslot

Definition at line 138 of file MaskEditorActions.cpp.

References changeMaskStackingOrder(), and MaskEditorFlags::SEND_TO_BACK.

Referenced by MaskEditorActions().

Here is the call graph for this function:

◆ onToggleMaskValueAction

void MaskEditorActions::onToggleMaskValueAction ( )
privateslot

Performs switch of mask value for all selected items (true -> false, false -> true)

Definition at line 121 of file MaskEditorActions.cpp.

122 {
125  for (auto itemIndex : m_selectionModel->selectedIndexes()) {
126  if (SessionItem* item = m_maskModel->itemForIndex(itemIndex)) {
127  bool old_value = item->getItemValue(MaskItem::P_MASK_VALUE).toBool();
128  item->setItemValue(MaskItem::P_MASK_VALUE, !old_value);
129  }
130  }
131 }
static const QString P_MASK_VALUE
Definition: MaskItems.h:33

References ASSERT, SessionModel::itemForIndex(), m_maskModel, m_selectionModel, and MaskItem::P_MASK_VALUE.

Referenced by MaskEditorActions().

Here is the call graph for this function:

◆ propertyPanelRequest

void MaskEditorActions::propertyPanelRequest ( )
signal

◆ resetViewRequest

void MaskEditorActions::resetViewRequest ( )
signal

◆ savePlotRequest

void MaskEditorActions::savePlotRequest ( )
signal

◆ sendToBackAction()

QAction * MaskEditorActions::sendToBackAction ( )

Definition at line 83 of file MaskEditorActions.cpp.

84 {
85  return m_sendToBackAction;
86 }

References m_sendToBackAction.

Referenced by MaskEditorToolBar::setup_maskmodify_group().

◆ setAllActionsEnabled()

void MaskEditorActions::setAllActionsEnabled ( bool  value)
private

Definition at line 196 of file MaskEditorActions.cpp.

197 {
198  m_sendToBackAction->setEnabled(value);
199  m_bringToFrontAction->setEnabled(value);
200  m_toggleMaskValueAction->setEnabled(value);
201  m_deleteMaskAction->setEnabled(value);
202 }

References m_bringToFrontAction, m_deleteMaskAction, m_sendToBackAction, and m_toggleMaskValueAction.

Referenced by initItemContextMenu(), and onItemContextMenuRequest().

◆ setModel()

void MaskEditorActions::setModel ( SessionModel maskModel,
const QModelIndex &  rootIndex 
)

Definition at line 72 of file MaskEditorActions.cpp.

73 {
74  m_maskModel = maskModel;
75  m_rootIndex = rootIndex;
76 }

References m_maskModel, and m_rootIndex.

Referenced by MaskEditor::setMaskContext().

◆ setSelectionModel()

void MaskEditorActions::setSelectionModel ( QItemSelectionModel *  selectionModel)

Definition at line 78 of file MaskEditorActions.cpp.

79 {
80  m_selectionModel = selectionModel;
81 }

References m_selectionModel.

Referenced by MaskEditor::setMaskContext().

◆ topToolBarActions()

QList< QAction * > MaskEditorActions::topToolBarActions ( )

Definition at line 93 of file MaskEditorActions.cpp.

94 {
95  return QList<QAction*>() << m_resetViewAction << m_togglePanelAction;
96 }

References m_resetViewAction, and m_togglePanelAction.

Referenced by MaskEditor::topToolBarActions().

Member Data Documentation

◆ m_bringToFrontAction

QAction* MaskEditorActions::m_bringToFrontAction
private

◆ m_deleteMaskAction

QAction* MaskEditorActions::m_deleteMaskAction
private

◆ m_maskModel

◆ m_resetViewAction

QAction* MaskEditorActions::m_resetViewAction
private

Definition at line 72 of file MaskEditorActions.h.

Referenced by MaskEditorActions(), and topToolBarActions().

◆ m_rootIndex

QModelIndex MaskEditorActions::m_rootIndex
private

Definition at line 77 of file MaskEditorActions.h.

Referenced by changeMaskStackingOrder(), initItemContextMenu(), and setModel().

◆ m_savePlotAction

QAction* MaskEditorActions::m_savePlotAction
private

Definition at line 73 of file MaskEditorActions.h.

Referenced by MaskEditorActions().

◆ m_selectionModel

QItemSelectionModel* MaskEditorActions::m_selectionModel
private

◆ m_sendToBackAction

QAction* MaskEditorActions::m_sendToBackAction
private

◆ m_toggleMaskValueAction

QAction* MaskEditorActions::m_toggleMaskValueAction
private

◆ m_togglePanelAction

QAction* MaskEditorActions::m_togglePanelAction
private

Definition at line 74 of file MaskEditorActions.h.

Referenced by MaskEditorActions(), and topToolBarActions().


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