From d87f51382ee56393d093ad62d0b65aba0d5c4425 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Thu, 2 Nov 2017 15:54:58 +0100 Subject: [PATCH] Standard code beautification in MaskEditorActions. --- .../Views/MaskWidgets/MaskEditorActions.cpp | 101 ++++++++++-------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/GUI/coregui/Views/MaskWidgets/MaskEditorActions.cpp b/GUI/coregui/Views/MaskWidgets/MaskEditorActions.cpp index 0996a87e8fb..b85673124ae 100644 --- a/GUI/coregui/Views/MaskWidgets/MaskEditorActions.cpp +++ b/GUI/coregui/Views/MaskWidgets/MaskEditorActions.cpp @@ -21,87 +21,94 @@ #include <QItemSelectionModel> #include <QMenu> -MaskEditorActions::MaskEditorActions(QWidget *parent) +MaskEditorActions::MaskEditorActions(QWidget* parent) : QObject(parent) - , m_maskModel(0) - , m_selectionModel(0) + , m_toggleMaskValueAction(new QAction("Toggle mask value", parent)) + , 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, SIGNAL(triggered()), this, SLOT(onToggleMaskValueAction())); + connect(m_toggleMaskValueAction, &QAction::triggered, + this, &MaskEditorActions::onToggleMaskValueAction); - m_bringToFrontAction = new QAction(QStringLiteral("Rise mask up"), parent); m_bringToFrontAction->setIcon(QIcon(":/MaskWidgets/images/maskeditor_bringtofront.svg")); m_bringToFrontAction->setToolTip("Rise selected mask one level up (PgUp)"); 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->setToolTip("Lower selected mask one level down (PgDown)"); 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->setShortcuts(QKeySequence::Delete); parent->addAction(m_deleteMaskAction); - connect(m_deleteMaskAction, SIGNAL(triggered()), this, SLOT(onDeleteMaskAction())); + connect(m_deleteMaskAction, &QAction::triggered, this, &MaskEditorActions::onDeleteMaskAction); // Actions for top toolbar - m_resetViewAction = new QAction(this); m_resetViewAction->setText("Reset"); m_resetViewAction->setIcon(QIcon(":/images/toolbar16light_refresh.svg")); 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->setIcon(QIcon(":/images/toolbar16light_save.svg")); 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->setIcon(QIcon(":/images/toolbar16light_propertypanel.svg")); 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->setIcon(QIcon(":/images/toolbar16light_rotate.svg")); 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_rootIndex = rootIndex; } -void MaskEditorActions::setSelectionModel(QItemSelectionModel *selectionModel) +void MaskEditorActions::setSelectionModel(QItemSelectionModel* selectionModel) { m_selectionModel = selectionModel; } -QAction *MaskEditorActions::sendToBackAction() +QAction* MaskEditorActions::sendToBackAction() { return m_sendToBackAction; } -QAction *MaskEditorActions::bringToFrontAction() +QAction* MaskEditorActions::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 //! or MaskEditorInfoPanel -void MaskEditorActions::onItemContextMenuRequest(const QPoint &point) +void MaskEditorActions::onItemContextMenuRequest(const QPoint& point) { QMenu menu; initItemContextMenu(menu); @@ -126,8 +133,8 @@ void MaskEditorActions::onToggleMaskValueAction() { Q_ASSERT(m_maskModel); Q_ASSERT(m_selectionModel); - foreach(QModelIndex itemIndex, m_selectionModel->selectedIndexes()) { - if(SessionItem *item = m_maskModel->itemForIndex(itemIndex)) { + foreach (QModelIndex itemIndex, m_selectionModel->selectedIndexes()) { + if (SessionItem* item = m_maskModel->itemForIndex(itemIndex)) { bool old_value = item->getItemValue(MaskItem::P_MASK_VALUE).toBool(); item->setItemValue(MaskItem::P_MASK_VALUE, !old_value); } @@ -147,20 +154,23 @@ void MaskEditorActions::onSendToBackAction() //! Lower mask one level down or rise one level up in the masks stack void MaskEditorActions::changeMaskStackingOrder(MaskEditorFlags::Stacking value) { - if(!m_maskModel || !m_selectionModel) return; + if (!m_maskModel || !m_selectionModel) + return; int change_in_row(0); - if(value == MaskEditorFlags::BRING_TO_FRONT) change_in_row = -1; - if(value == MaskEditorFlags::SEND_TO_BACK) change_in_row = 2; + if (value == MaskEditorFlags::BRING_TO_FRONT) + change_in_row = -1; + if (value == MaskEditorFlags::SEND_TO_BACK) + change_in_row = 2; QModelIndexList indexes = m_selectionModel->selectedIndexes(); - foreach(QModelIndex itemIndex, indexes) { - if(SessionItem *item = m_maskModel->itemForIndex(itemIndex)) { + foreach (QModelIndex itemIndex, indexes) { + if (SessionItem* item = m_maskModel->itemForIndex(itemIndex)) { int new_row = itemIndex.row() + change_in_row; - if(new_row >= 0 && new_row <= m_maskModel->rowCount(m_rootIndex)) { - SessionItem *newItem = m_maskModel->moveParameterizedItem( - item,m_maskModel->itemForIndex(m_rootIndex), new_row); + if (new_row >= 0 && new_row <= m_maskModel->rowCount(m_rootIndex)) { + SessionItem* newItem = m_maskModel->moveParameterizedItem( + item, m_maskModel->itemForIndex(m_rootIndex), new_row); m_selectionModel->select(m_maskModel->indexOfItem(newItem), QItemSelectionModel::Select); } @@ -176,7 +186,8 @@ bool MaskEditorActions::isBringToFrontPossible() const { bool result(false); 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; } @@ -185,9 +196,10 @@ bool MaskEditorActions::isSendToBackPossible() const { bool result(false); QModelIndexList indexes = m_selectionModel->selectedIndexes(); - if(indexes.size() == 1) { - SessionItem *item = m_maskModel->itemForIndex(indexes.front()); - if(indexes.front().row() != item->parent()->rowCount() -1) result = true; + if (indexes.size() == 1) { + SessionItem* item = m_maskModel->itemForIndex(indexes.front()); + if (indexes.front().row() != item->parent()->rowCount() - 1) + result = true; } return result; } @@ -202,16 +214,17 @@ void MaskEditorActions::setAllActionsEnabled(bool value) //! Init external context menu with currently defined actions. //! 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_selectionModel); - if(m_selectionModel->selectedIndexes().isEmpty()) { + if (m_selectionModel->selectedIndexes().isEmpty()) setAllActionsEnabled(false); - } + m_sendToBackAction->setEnabled(isSendToBackPossible()); m_bringToFrontAction->setEnabled(isBringToFrontPossible()); -- GitLab