Mantid
Loading...
Searching...
No Matches
StrictQModelIndices.h
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 +
11#pragma once
14#include <QModelIndex>
15
16namespace MantidQt {
17namespace MantidWidgets {
18namespace Batch {
19
20template <typename Derived> class StrictQModelIndex {
21public:
22 explicit StrictQModelIndex(QModelIndex const &index);
23 StrictQModelIndex() = default;
24
25 QModelIndex untyped() const;
26 int row() const;
27 int column() const;
28 bool isValid() const;
29
30 Derived parent() const;
31 Derived sibling(int row, int column) const;
32
33private:
34 QModelIndex m_untypedIndex;
35};
36
37template <typename Derived>
38StrictQModelIndex<Derived>::StrictQModelIndex(QModelIndex const &index) : m_untypedIndex(index) {}
39
40template <typename Derived> QModelIndex StrictQModelIndex<Derived>::untyped() const { return m_untypedIndex; }
41
42template <typename Derived>
44 return lhs.untyped() == rhs.untyped();
45}
46
47template <typename Derived> int StrictQModelIndex<Derived>::row() const { return m_untypedIndex.row(); }
48
49template <typename Derived> int StrictQModelIndex<Derived>::column() const { return m_untypedIndex.column(); }
50
51template <typename Derived> bool StrictQModelIndex<Derived>::isValid() const { return m_untypedIndex.isValid(); }
52
53template <typename Derived> Derived StrictQModelIndex<Derived>::parent() const {
54 return Derived(m_untypedIndex.parent());
55}
56
57template <typename Derived> Derived StrictQModelIndex<Derived>::sibling(int row, int column) const {
58 return Derived(m_untypedIndex.sibling(row, column));
59}
60
62 using StrictQModelIndex<QModelIndexForFilteredModel>::StrictQModelIndex;
63};
64
65inline QModelIndexForFilteredModel fromFilteredModel(QModelIndex const &filteredModelIndex,
66 QAbstractItemModel const &model) {
67 assertOrThrow(filteredModelIndex.model() == nullptr || filteredModelIndex.model() == &model,
68 "assertFromFilteredModel: Index model assertion was not true.");
69 return QModelIndexForFilteredModel(filteredModelIndex);
70}
71
73 using StrictQModelIndex<QModelIndexForMainModel>::StrictQModelIndex;
74};
75
76inline QModelIndexForMainModel fromMainModel(QModelIndex const &mainModelIndex, QAbstractItemModel const &model) {
77 assertOrThrow(mainModelIndex.model() == nullptr || mainModelIndex.model() == &model,
78 "assertFromMainModel: Index model assertion was not true.");
79 return QModelIndexForMainModel(mainModelIndex);
80}
81} // namespace Batch
82} // namespace MantidWidgets
83} // namespace MantidQt
void assertOrThrow(bool condition, std::string const &message)
See the developer documentation for Batch Widget at developer.mantidproject.org/BatchWidget/index....
Definition: AssertOrThrow.h:15
const std::vector< double > & rhs
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
QModelIndexForMainModel fromMainModel(QModelIndex const &mainModelIndex, QAbstractItemModel const &model)
EXPORT_OPT_MANTIDQT_COMMON bool operator==(Cell const &lhs, Cell const &rhs)
Definition: Cell.cpp:88
QModelIndexForFilteredModel fromFilteredModel(QModelIndex const &filteredModelIndex, QAbstractItemModel const &model)
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...