Mantid
Loading...
Searching...
No Matches
QtTreeCursorNavigation.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
11
12QtTreeCursorNavigation::QtTreeCursorNavigation(QAbstractItemModel const *model) : m_model(model) {}
13
15 return std::make_pair(false, index);
16}
17
19 return std::make_pair(true, index);
20}
21
22std::pair<bool, QModelIndex> QtTreeCursorNavigation::moveCursorNext(QModelIndex const &currentIndex) const {
23 if (currentIndex.isValid()) {
24 if (isNotLastCellOnThisRow(currentIndex))
25 return withoutAppendedRow(nextCellOnThisRow(currentIndex));
26 else if (isNotLastRowInThisNode(currentIndex))
27 return withoutAppendedRow(firstCellOnNextRow(currentIndex));
28 else
29 return withAppendedRow(currentIndex);
30 } else
31 return withoutAppendedRow(QModelIndex());
32}
33
34QModelIndex QtTreeCursorNavigation::moveCursorPrevious(QModelIndex const &currentIndex) const {
35 if (currentIndex.isValid()) {
36 if (isNotFirstCellInThisRow(currentIndex))
37 return previousCellInThisRow(currentIndex);
38 else if (isNotFirstRowInThisNode(currentIndex))
39 return lastCellInPreviousRow(currentIndex);
40 else
41 return lastCellInParentRowElseNone(currentIndex);
42 } else
43 return QModelIndex();
44}
45
47
49
50QModelIndex QtTreeCursorNavigation::previousCellInThisRow(QModelIndex const &index) const { return leftOf(index); }
51
52QModelIndex QtTreeCursorNavigation::lastCellInPreviousRow(QModelIndex const &index) const {
53 return index.sibling(index.row() - 1, m_model->columnCount() - 1);
54}
55
56QModelIndex lastChildRowOf(QModelIndex const &parent, QAbstractItemModel const &model) {
57 return model.index(model.rowCount(parent) - 1, 0, parent);
58}
59
60QModelIndex QtTreeCursorNavigation::lastRowInThisNode(QModelIndex const &parent) const {
61 return lastChildRowOf(parent, *m_model);
62}
63
64QModelIndex QtTreeCursorNavigation::lastCellInParentRowElseNone(QModelIndex const &index) const {
65 auto parent = m_model->parent(index);
66 if (parent.isValid())
67 return parent.sibling(parent.row(), m_model->columnCount() - 1);
68 else
69 return QModelIndex();
70}
71
72QModelIndex QtTreeCursorNavigation::firstCellOnNextRow(QModelIndex const &index) const {
73 return index.sibling(index.row() + 1, 0);
74}
75
76QModelIndex QtTreeCursorNavigation::nextCellOnThisRow(QModelIndex const &index) const { return rightOf(index); }
77
79
80bool QtTreeCursorNavigation::isNotLastRowInThisNode(QModelIndex const &index) const { return hasRowBelow(index); }
81} // namespace MantidQt::MantidWidgets::Batch
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
QModelIndex lastCellInParentRowElseNone(QModelIndex const &index) const
bool isNotFirstRowInThisNode(QModelIndex const &index) const
QModelIndex nextCellOnThisRow(QModelIndex const &index) const
QtTreeCursorNavigationResult moveCursorNext(QModelIndex const &currentIndex) const
bool isNotFirstCellInThisRow(QModelIndex const &index) const
QModelIndex lastRowInThisNode(QModelIndex const &index) const
QModelIndex previousCellInThisRow(QModelIndex const &index) const
QModelIndex moveCursorPrevious(QModelIndex const &currentIndex) const
QtTreeCursorNavigationResult withAppendedRow(QModelIndex const &index) const
QtTreeCursorNavigationResult withoutAppendedRow(QModelIndex const &index) const
QModelIndex firstCellOnNextRow(QModelIndex const &rowAbove) const
QModelIndex lastCellInPreviousRow(QModelIndex const &index) const
bool hasCellOnTheLeft(QModelIndex const &index)
std::pair< bool, QModelIndex > QtTreeCursorNavigationResult
bool hasRowAbove(QModelIndex const &index)
QModelIndex lastChildRowOf(QModelIndex const &index, QAbstractItemModel const &model)
QModelIndex leftOf(QModelIndex const &index)
QModelIndex rightOf(QModelIndex const &index)
bool hasRowBelow(QModelIndex const &index)
bool hasCellOnTheRight(QModelIndex const &index)