diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 22:51:07 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 22:51:07 +1100 |
| commit | 27cb290423ba5c30c1856427609938c230fa9f32 (patch) | |
| tree | 037e5ede085be567b0dec680eb7a10cb423682bd /plugin/src/Caelestia/Internal/circularbuffer.hpp | |
| parent | notifs: skip markdown parsing for plain text bodies (diff) | |
| download | caelestia-shell-27cb290423ba5c30c1856427609938c230fa9f32.tar.gz caelestia-shell-27cb290423ba5c30c1856427609938c230fa9f32.tar.bz2 caelestia-shell-27cb290423ba5c30c1856427609938c230fa9f32.zip | |
feat: replace canvas -> c++ component
Also add c++ ring buffer
Diffstat (limited to 'plugin/src/Caelestia/Internal/circularbuffer.hpp')
| -rw-r--r-- | plugin/src/Caelestia/Internal/circularbuffer.hpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/plugin/src/Caelestia/Internal/circularbuffer.hpp b/plugin/src/Caelestia/Internal/circularbuffer.hpp new file mode 100644 index 0000000..ab2dba5 --- /dev/null +++ b/plugin/src/Caelestia/Internal/circularbuffer.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include <qobject.h> +#include <qqmlintegration.h> +#include <qvector.h> + +namespace caelestia::internal { + +class CircularBuffer : public QObject { + Q_OBJECT + QML_ELEMENT + + Q_PROPERTY(int capacity READ capacity WRITE setCapacity NOTIFY capacityChanged) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QList<qreal> values READ values NOTIFY valuesChanged) + Q_PROPERTY(qreal maximum READ maximum NOTIFY valuesChanged) + +public: + explicit CircularBuffer(QObject* parent = nullptr); + + [[nodiscard]] int capacity() const; + void setCapacity(int capacity); + + [[nodiscard]] int count() const; + [[nodiscard]] QList<qreal> values() const; + [[nodiscard]] qreal maximum() const; + + Q_INVOKABLE void push(qreal value); + Q_INVOKABLE void clear(); + Q_INVOKABLE [[nodiscard]] qreal at(int index) const; + +signals: + void capacityChanged(); + void countChanged(); + void valuesChanged(); + +private: + QVector<qreal> m_data; + int m_head = 0; + int m_count = 0; + int m_capacity = 0; +}; + +} // namespace caelestia::internal |