plugins/shakecursor: Use std::deque to store history

It's more suitable for the task. The ShakeDetector constantly adds new
items at the end of the list and pops old items at the front.
This commit is contained in:
Vlad Zahorodnii 2024-01-17 22:00:30 +02:00
parent 597753047d
commit 74a193d383
2 changed files with 4 additions and 3 deletions

View file

@ -45,7 +45,7 @@ std::optional<qreal> ShakeDetector::update(QMouseEvent *event)
m_history.erase(m_history.begin(), it);
}
m_history.append(HistoryItem{
m_history.emplace_back(HistoryItem{
.position = event->localPos(),
.timestamp = event->timestamp(),
});
@ -56,7 +56,7 @@ std::optional<qreal> ShakeDetector::update(QMouseEvent *event)
qreal bottom = m_history[0].position.y();
qreal distance = 0;
for (int i = 1; i < m_history.size(); ++i) {
for (size_t i = 1; i < m_history.size(); ++i) {
// Compute the length of the mouse path.
const qreal deltaX = m_history.at(i).position.x() - m_history.at(i - 1).position.x();
const qreal deltaY = m_history.at(i).position.y() - m_history.at(i - 1).position.y();

View file

@ -8,6 +8,7 @@
#include <QMouseEvent>
#include <deque>
#include <optional>
/**
@ -37,7 +38,7 @@ private:
quint64 timestamp;
};
QList<HistoryItem> m_history;
std::deque<HistoryItem> m_history;
quint64 m_interval = 1000;
qreal m_sensitivity = 4;
};