Skip to content
Snippets Groups Projects
Commit d87f5138 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Standard code beautification in MaskEditorActions.

parent 95c3f1df
No related branches found
No related tags found
No related merge requests found
...@@ -21,87 +21,94 @@ ...@@ -21,87 +21,94 @@
#include <QItemSelectionModel> #include <QItemSelectionModel>
#include <QMenu> #include <QMenu>
MaskEditorActions::MaskEditorActions(QWidget *parent) MaskEditorActions::MaskEditorActions(QWidget* parent)
: QObject(parent) : QObject(parent)
, m_maskModel(0) , m_toggleMaskValueAction(new QAction("Toggle mask value", parent))
, m_selectionModel(0) , m_bringToFrontAction(new QAction("Rise mask up", parent))
, m_sendToBackAction(new QAction("Lower mask down", parent))
, m_deleteMaskAction(new QAction("Remove mask", parent))
, m_resetViewAction(new QAction(this))
, m_savePlotAction(new QAction(this))
, m_togglePanelAction(new QAction(this))
, m_rotateDataAction(new QAction(this))
, m_maskModel(nullptr)
, m_selectionModel(nullptr)
{ {
m_toggleMaskValueAction = new QAction(QStringLiteral("Toggle mask value"), parent); connect(m_toggleMaskValueAction, &QAction::triggered,
connect(m_toggleMaskValueAction, SIGNAL(triggered()), this, SLOT(onToggleMaskValueAction())); this, &MaskEditorActions::onToggleMaskValueAction);
m_bringToFrontAction = new QAction(QStringLiteral("Rise mask up"), parent);
m_bringToFrontAction->setIcon(QIcon(":/MaskWidgets/images/maskeditor_bringtofront.svg")); m_bringToFrontAction->setIcon(QIcon(":/MaskWidgets/images/maskeditor_bringtofront.svg"));
m_bringToFrontAction->setToolTip("Rise selected mask one level up (PgUp)"); m_bringToFrontAction->setToolTip("Rise selected mask one level up (PgUp)");
m_bringToFrontAction->setShortcuts(QKeySequence::MoveToPreviousPage); m_bringToFrontAction->setShortcuts(QKeySequence::MoveToPreviousPage);
connect(m_bringToFrontAction, SIGNAL(triggered()), this, SLOT(onBringToFrontAction())); connect(m_bringToFrontAction, &QAction::triggered,
this, &MaskEditorActions::onBringToFrontAction);
m_sendToBackAction = new QAction(QStringLiteral("Lower mask down"), parent);
m_sendToBackAction->setIcon(QIcon(":/MaskWidgets/images/maskeditor_sendtoback.svg")); m_sendToBackAction->setIcon(QIcon(":/MaskWidgets/images/maskeditor_sendtoback.svg"));
m_sendToBackAction->setToolTip("Lower selected mask one level down (PgDown)"); m_sendToBackAction->setToolTip("Lower selected mask one level down (PgDown)");
m_sendToBackAction->setShortcuts(QKeySequence::MoveToNextPage); m_sendToBackAction->setShortcuts(QKeySequence::MoveToNextPage);
connect(m_sendToBackAction, SIGNAL(triggered()), this, SLOT(onSendToBackAction())); connect(m_sendToBackAction, &QAction::triggered,
this, &MaskEditorActions::onSendToBackAction);
m_deleteMaskAction = new QAction(QStringLiteral("Remove mask"), parent);
m_deleteMaskAction->setToolTip("Remove selected mask (Del)"); m_deleteMaskAction->setToolTip("Remove selected mask (Del)");
m_deleteMaskAction->setShortcuts(QKeySequence::Delete); m_deleteMaskAction->setShortcuts(QKeySequence::Delete);
parent->addAction(m_deleteMaskAction); parent->addAction(m_deleteMaskAction);
connect(m_deleteMaskAction, SIGNAL(triggered()), this, SLOT(onDeleteMaskAction())); connect(m_deleteMaskAction, &QAction::triggered, this, &MaskEditorActions::onDeleteMaskAction);
// Actions for top toolbar // Actions for top toolbar
m_resetViewAction = new QAction(this);
m_resetViewAction->setText("Reset"); m_resetViewAction->setText("Reset");
m_resetViewAction->setIcon(QIcon(":/images/toolbar16light_refresh.svg")); m_resetViewAction->setIcon(QIcon(":/images/toolbar16light_refresh.svg"));
m_resetViewAction->setToolTip("Reset View"); m_resetViewAction->setToolTip("Reset View");
connect(m_resetViewAction, SIGNAL(triggered()), this, SIGNAL(resetViewRequest())); connect(m_resetViewAction, &QAction::triggered, this, &MaskEditorActions::resetViewRequest);
m_savePlotAction = new QAction(this);
m_savePlotAction->setText("Save"); m_savePlotAction->setText("Save");
m_savePlotAction->setIcon(QIcon(":/images/toolbar16light_save.svg")); m_savePlotAction->setIcon(QIcon(":/images/toolbar16light_save.svg"));
m_savePlotAction->setToolTip("Save Plot"); m_savePlotAction->setToolTip("Save Plot");
connect(m_savePlotAction, SIGNAL(triggered()), this, SIGNAL(savePlotRequest())); connect(m_savePlotAction, &QAction::triggered, this, &MaskEditorActions::savePlotRequest);
m_togglePanelAction = new QAction(this);
m_togglePanelAction->setText("Properties"); m_togglePanelAction->setText("Properties");
m_togglePanelAction->setIcon(QIcon(":/images/toolbar16light_propertypanel.svg")); m_togglePanelAction->setIcon(QIcon(":/images/toolbar16light_propertypanel.svg"));
m_togglePanelAction->setToolTip("Toggle Property Panel"); m_togglePanelAction->setToolTip("Toggle Property Panel");
connect(m_togglePanelAction, SIGNAL(triggered()), this, SIGNAL(propertyPanelRequest())); connect(m_togglePanelAction, &QAction::triggered,
this, &MaskEditorActions::propertyPanelRequest);
m_rotateDataAction = new QAction(this);
m_rotateDataAction->setText("Rotate"); m_rotateDataAction->setText("Rotate");
m_rotateDataAction->setIcon(QIcon(":/images/toolbar16light_rotate.svg")); m_rotateDataAction->setIcon(QIcon(":/images/toolbar16light_rotate.svg"));
m_rotateDataAction->setToolTip("Rotate intensity data by 90 deg counterclockwise"); m_rotateDataAction->setToolTip("Rotate intensity data by 90 deg counterclockwise");
connect(m_rotateDataAction, SIGNAL(triggered()), this, SIGNAL(rotateDataRequest())); connect(m_rotateDataAction, &QAction::triggered,
this, &MaskEditorActions::rotateDataRequest);
} }
void MaskEditorActions::setModel(SessionModel *maskModel, const QModelIndex &rootIndex) void MaskEditorActions::setModel(SessionModel* maskModel, const QModelIndex& rootIndex)
{ {
m_maskModel = maskModel; m_maskModel = maskModel;
m_rootIndex = rootIndex; m_rootIndex = rootIndex;
} }
void MaskEditorActions::setSelectionModel(QItemSelectionModel *selectionModel) void MaskEditorActions::setSelectionModel(QItemSelectionModel* selectionModel)
{ {
m_selectionModel = selectionModel; m_selectionModel = selectionModel;
} }
QAction *MaskEditorActions::sendToBackAction() QAction* MaskEditorActions::sendToBackAction()
{ {
return m_sendToBackAction; return m_sendToBackAction;
} }
QAction *MaskEditorActions::bringToFrontAction() QAction* MaskEditorActions::bringToFrontAction()
{ {
return m_bringToFrontAction; return m_bringToFrontAction;
} }
QList<QAction *> MaskEditorActions::topToolBarActions() QList<QAction*> MaskEditorActions::topToolBarActions()
{ {
return QList<QAction*>() << m_resetViewAction << m_savePlotAction << m_togglePanelAction << m_rotateDataAction; return QList<QAction*>() << m_resetViewAction << m_savePlotAction << m_togglePanelAction
<< m_rotateDataAction;
} }
//! Constructs MaskItem context menu following the request from MaskGraphicsScene //! Constructs MaskItem context menu following the request from MaskGraphicsScene
//! or MaskEditorInfoPanel //! or MaskEditorInfoPanel
void MaskEditorActions::onItemContextMenuRequest(const QPoint &point) void MaskEditorActions::onItemContextMenuRequest(const QPoint& point)
{ {
QMenu menu; QMenu menu;
initItemContextMenu(menu); initItemContextMenu(menu);
...@@ -126,8 +133,8 @@ void MaskEditorActions::onToggleMaskValueAction() ...@@ -126,8 +133,8 @@ void MaskEditorActions::onToggleMaskValueAction()
{ {
Q_ASSERT(m_maskModel); Q_ASSERT(m_maskModel);
Q_ASSERT(m_selectionModel); Q_ASSERT(m_selectionModel);
foreach(QModelIndex itemIndex, m_selectionModel->selectedIndexes()) { foreach (QModelIndex itemIndex, m_selectionModel->selectedIndexes()) {
if(SessionItem *item = m_maskModel->itemForIndex(itemIndex)) { if (SessionItem* item = m_maskModel->itemForIndex(itemIndex)) {
bool old_value = item->getItemValue(MaskItem::P_MASK_VALUE).toBool(); bool old_value = item->getItemValue(MaskItem::P_MASK_VALUE).toBool();
item->setItemValue(MaskItem::P_MASK_VALUE, !old_value); item->setItemValue(MaskItem::P_MASK_VALUE, !old_value);
} }
...@@ -147,20 +154,23 @@ void MaskEditorActions::onSendToBackAction() ...@@ -147,20 +154,23 @@ void MaskEditorActions::onSendToBackAction()
//! Lower mask one level down or rise one level up in the masks stack //! Lower mask one level down or rise one level up in the masks stack
void MaskEditorActions::changeMaskStackingOrder(MaskEditorFlags::Stacking value) void MaskEditorActions::changeMaskStackingOrder(MaskEditorFlags::Stacking value)
{ {
if(!m_maskModel || !m_selectionModel) return; if (!m_maskModel || !m_selectionModel)
return;
int change_in_row(0); int change_in_row(0);
if(value == MaskEditorFlags::BRING_TO_FRONT) change_in_row = -1; if (value == MaskEditorFlags::BRING_TO_FRONT)
if(value == MaskEditorFlags::SEND_TO_BACK) change_in_row = 2; change_in_row = -1;
if (value == MaskEditorFlags::SEND_TO_BACK)
change_in_row = 2;
QModelIndexList indexes = m_selectionModel->selectedIndexes(); QModelIndexList indexes = m_selectionModel->selectedIndexes();
foreach(QModelIndex itemIndex, indexes) { foreach (QModelIndex itemIndex, indexes) {
if(SessionItem *item = m_maskModel->itemForIndex(itemIndex)) { if (SessionItem* item = m_maskModel->itemForIndex(itemIndex)) {
int new_row = itemIndex.row() + change_in_row; int new_row = itemIndex.row() + change_in_row;
if(new_row >= 0 && new_row <= m_maskModel->rowCount(m_rootIndex)) { if (new_row >= 0 && new_row <= m_maskModel->rowCount(m_rootIndex)) {
SessionItem *newItem = m_maskModel->moveParameterizedItem( SessionItem* newItem = m_maskModel->moveParameterizedItem(
item,m_maskModel->itemForIndex(m_rootIndex), new_row); item, m_maskModel->itemForIndex(m_rootIndex), new_row);
m_selectionModel->select(m_maskModel->indexOfItem(newItem), m_selectionModel->select(m_maskModel->indexOfItem(newItem),
QItemSelectionModel::Select); QItemSelectionModel::Select);
} }
...@@ -176,7 +186,8 @@ bool MaskEditorActions::isBringToFrontPossible() const ...@@ -176,7 +186,8 @@ bool MaskEditorActions::isBringToFrontPossible() const
{ {
bool result(false); bool result(false);
QModelIndexList indexes = m_selectionModel->selectedIndexes(); QModelIndexList indexes = m_selectionModel->selectedIndexes();
if(indexes.size() == 1 && indexes.front().row() != 0) result=true; if (indexes.size() == 1 && indexes.front().row() != 0)
result = true;
return result; return result;
} }
...@@ -185,9 +196,10 @@ bool MaskEditorActions::isSendToBackPossible() const ...@@ -185,9 +196,10 @@ bool MaskEditorActions::isSendToBackPossible() const
{ {
bool result(false); bool result(false);
QModelIndexList indexes = m_selectionModel->selectedIndexes(); QModelIndexList indexes = m_selectionModel->selectedIndexes();
if(indexes.size() == 1) { if (indexes.size() == 1) {
SessionItem *item = m_maskModel->itemForIndex(indexes.front()); SessionItem* item = m_maskModel->itemForIndex(indexes.front());
if(indexes.front().row() != item->parent()->rowCount() -1) result = true; if (indexes.front().row() != item->parent()->rowCount() - 1)
result = true;
} }
return result; return result;
} }
...@@ -202,16 +214,17 @@ void MaskEditorActions::setAllActionsEnabled(bool value) ...@@ -202,16 +214,17 @@ void MaskEditorActions::setAllActionsEnabled(bool value)
//! Init external context menu with currently defined actions. //! Init external context menu with currently defined actions.
//! Triggered from MaskGraphicsScene of MaskEditorInfoPanel (QListView) //! Triggered from MaskGraphicsScene of MaskEditorInfoPanel (QListView)
void MaskEditorActions::initItemContextMenu(QMenu &menu) void MaskEditorActions::initItemContextMenu(QMenu& menu)
{ {
if(!m_rootIndex.isValid()) return; if (!m_rootIndex.isValid())
return;
Q_ASSERT(m_maskModel); Q_ASSERT(m_maskModel);
Q_ASSERT(m_selectionModel); Q_ASSERT(m_selectionModel);
if(m_selectionModel->selectedIndexes().isEmpty()) { if (m_selectionModel->selectedIndexes().isEmpty())
setAllActionsEnabled(false); setAllActionsEnabled(false);
}
m_sendToBackAction->setEnabled(isSendToBackPossible()); m_sendToBackAction->setEnabled(isSendToBackPossible());
m_bringToFrontAction->setEnabled(isBringToFrontPossible()); m_bringToFrontAction->setEnabled(isBringToFrontPossible());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment