diff --git a/gui/include/Visualization/QCPColorMapIterator.h b/gui/include/Visualization/QCPColorMapIterator.h new file mode 100644 index 0000000..a2b2454 --- /dev/null +++ b/gui/include/Visualization/QCPColorMapIterator.h @@ -0,0 +1,40 @@ +#ifndef SCIQLOP_QCPCOLORMAPITERATOR_H +#define SCIQLOP_QCPCOLORMAPITERATOR_H + +#include + +class QCPColorMapData; + +/** + * Forward iterator for @sa QCPColorMap + */ +class QCPColorMapIterator { +public: + using iterator_category = std::forward_iterator_tag; + using value_type = double; + using difference_type = std::ptrdiff_t; + using pointer = const value_type *; + using reference = value_type; + + explicit QCPColorMapIterator(QCPColorMapData *data, bool begin); + virtual ~QCPColorMapIterator() noexcept = default; + + QCPColorMapIterator &operator++(); + QCPColorMapIterator operator++(int); + + pointer operator->() const; + reference operator*() const; + + bool operator==(const QCPColorMapIterator &other); + bool operator!=(const QCPColorMapIterator &other); + +private: + void updateValue(); + + QCPColorMapData *m_Data; ///< Data iterated + int m_KeyIndex; ///< Current iteration key index + int m_ValueIndex; ///< Current iteration value index + double m_Value; ///< Current iteration value +}; + +#endif // SCIQLOP_QCPCOLORMAPITERATOR_H diff --git a/gui/meson.build b/gui/meson.build index 8b59a21..8d3e873 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -81,7 +81,8 @@ gui_sources = [ 'src/Visualization/MacScrollBarStyle.cpp', 'src/Visualization/VisualizationCursorItem.cpp', 'src/Visualization/ColorScaleEditor.cpp', - 'src/Visualization/SqpColorScale.cpp' + 'src/Visualization/SqpColorScale.cpp', + 'src/Visualization/QCPColorMapIterator.cpp' ] gui_inc = include_directories(['include']) diff --git a/gui/src/Visualization/QCPColorMapIterator.cpp b/gui/src/Visualization/QCPColorMapIterator.cpp new file mode 100644 index 0000000..e543ef7 --- /dev/null +++ b/gui/src/Visualization/QCPColorMapIterator.cpp @@ -0,0 +1,58 @@ +#include "Visualization/QCPColorMapIterator.h" + +#include + +QCPColorMapIterator::QCPColorMapIterator(QCPColorMapData *data, bool begin) + : m_Data{data}, m_KeyIndex{begin ? 0 : data->keySize()}, m_ValueIndex{0} +{ + updateValue(); +} + +QCPColorMapIterator &QCPColorMapIterator::operator++() +{ + // Increments indexes + ++m_ValueIndex; + if (m_ValueIndex == m_Data->valueSize()) { + ++m_KeyIndex; + m_ValueIndex = 0; + } + + // Updates value + updateValue(); + + return *this; +} + +QCPColorMapIterator QCPColorMapIterator::operator++(int) +{ + auto result = *this; + this->operator++(); + return result; +} + +QCPColorMapIterator::pointer QCPColorMapIterator::operator->() const +{ + return &m_Value; +} + +QCPColorMapIterator::reference QCPColorMapIterator::operator*() const +{ + return m_Value; +} + +bool QCPColorMapIterator::operator==(const QCPColorMapIterator &other) +{ + return std::tie(m_Data, m_KeyIndex, m_ValueIndex) + == std::tie(other.m_Data, other.m_KeyIndex, other.m_ValueIndex); +} + +bool QCPColorMapIterator::operator!=(const QCPColorMapIterator &other) +{ + return !(*this == other); +} + +void QCPColorMapIterator::updateValue() +{ + m_Value = m_KeyIndex != m_Data->keySize() ? m_Data->cell(m_KeyIndex, m_ValueIndex) + : std::numeric_limits::quiet_NaN(); +} diff --git a/gui/vera-exclusions/exclusions.txt b/gui/vera-exclusions/exclusions.txt index a868d40..be6d94f 100644 --- a/gui/vera-exclusions/exclusions.txt +++ b/gui/vera-exclusions/exclusions.txt @@ -6,4 +6,17 @@ qcustomplot\.cpp:\d+:.IPSIS SqpApplication\.h:\d+:.IPSIS_S03.*found: sqpApp SqpApplication\.h:\d+:.IPSIS_S04_VARIABLE.*found: sqpApp +# Ignore false positive relative to iterators +QCPColorMapIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (forward_iterator_tag) +QCPColorMapIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (ptrdiff_t) +QCPColorMapIterator\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (value_type) +QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (iterator_category) +QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (forward_iterator_tag) +QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (value_type) +QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (difference_type) +QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (ptrdiff_t) +QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (pointer) +QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (reference) +QCPColorMapIterator\.h:\d+:.*IPSIS_S06.*found: (value_type) +