##// END OF EJS Templates
Creates iterator for QCPColorMap...
Alexandre Leroux -
r1017:d684e1205d9a
parent child
Show More
@@ -0,0 +1,40
1 #ifndef SCIQLOP_QCPCOLORMAPITERATOR_H
2 #define SCIQLOP_QCPCOLORMAPITERATOR_H
3
4 #include <iterator>
5
6 class QCPColorMapData;
7
8 /**
9 * Forward iterator for @sa QCPColorMap
10 */
11 class QCPColorMapIterator {
12 public:
13 using iterator_category = std::forward_iterator_tag;
14 using value_type = double;
15 using difference_type = std::ptrdiff_t;
16 using pointer = const value_type *;
17 using reference = value_type;
18
19 explicit QCPColorMapIterator(QCPColorMapData *data, bool begin);
20 virtual ~QCPColorMapIterator() noexcept = default;
21
22 QCPColorMapIterator &operator++();
23 QCPColorMapIterator operator++(int);
24
25 pointer operator->() const;
26 reference operator*() const;
27
28 bool operator==(const QCPColorMapIterator &other);
29 bool operator!=(const QCPColorMapIterator &other);
30
31 private:
32 void updateValue();
33
34 QCPColorMapData *m_Data; ///< Data iterated
35 int m_KeyIndex; ///< Current iteration key index
36 int m_ValueIndex; ///< Current iteration value index
37 double m_Value; ///< Current iteration value
38 };
39
40 #endif // SCIQLOP_QCPCOLORMAPITERATOR_H
@@ -0,0 +1,58
1 #include "Visualization/QCPColorMapIterator.h"
2
3 #include <Visualization/qcustomplot.h>
4
5 QCPColorMapIterator::QCPColorMapIterator(QCPColorMapData *data, bool begin)
6 : m_Data{data}, m_KeyIndex{begin ? 0 : data->keySize()}, m_ValueIndex{0}
7 {
8 updateValue();
9 }
10
11 QCPColorMapIterator &QCPColorMapIterator::operator++()
12 {
13 // Increments indexes
14 ++m_ValueIndex;
15 if (m_ValueIndex == m_Data->valueSize()) {
16 ++m_KeyIndex;
17 m_ValueIndex = 0;
18 }
19
20 // Updates value
21 updateValue();
22
23 return *this;
24 }
25
26 QCPColorMapIterator QCPColorMapIterator::operator++(int)
27 {
28 auto result = *this;
29 this->operator++();
30 return result;
31 }
32
33 QCPColorMapIterator::pointer QCPColorMapIterator::operator->() const
34 {
35 return &m_Value;
36 }
37
38 QCPColorMapIterator::reference QCPColorMapIterator::operator*() const
39 {
40 return m_Value;
41 }
42
43 bool QCPColorMapIterator::operator==(const QCPColorMapIterator &other)
44 {
45 return std::tie(m_Data, m_KeyIndex, m_ValueIndex)
46 == std::tie(other.m_Data, other.m_KeyIndex, other.m_ValueIndex);
47 }
48
49 bool QCPColorMapIterator::operator!=(const QCPColorMapIterator &other)
50 {
51 return !(*this == other);
52 }
53
54 void QCPColorMapIterator::updateValue()
55 {
56 m_Value = m_KeyIndex != m_Data->keySize() ? m_Data->cell(m_KeyIndex, m_ValueIndex)
57 : std::numeric_limits<double>::quiet_NaN();
58 }
@@ -81,7 +81,8 gui_sources = [
81 81 'src/Visualization/MacScrollBarStyle.cpp',
82 82 'src/Visualization/VisualizationCursorItem.cpp',
83 83 'src/Visualization/ColorScaleEditor.cpp',
84 'src/Visualization/SqpColorScale.cpp'
84 'src/Visualization/SqpColorScale.cpp',
85 'src/Visualization/QCPColorMapIterator.cpp'
85 86 ]
86 87
87 88 gui_inc = include_directories(['include'])
@@ -6,4 +6,17 qcustomplot\.cpp:\d+:.IPSIS
6 6 SqpApplication\.h:\d+:.IPSIS_S03.*found: sqpApp
7 7 SqpApplication\.h:\d+:.IPSIS_S04_VARIABLE.*found: sqpApp
8 8
9 # Ignore false positive relative to iterators
10 QCPColorMapIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (forward_iterator_tag)
11 QCPColorMapIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (ptrdiff_t)
12 QCPColorMapIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (value_type)
13 QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (iterator_category)
14 QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (forward_iterator_tag)
15 QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (value_type)
16 QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (difference_type)
17 QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (ptrdiff_t)
18 QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (pointer)
19 QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (reference)
20 QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (value_type)
21
9 22
General Comments 0
You need to be logged in to leave comments. Login now