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.
wilder/Plasma/6.2
Vlad Zahorodnii 2 years ago
parent 597753047d
commit 74a193d383
  1. 4
      src/plugins/shakecursor/shakedetector.cpp
  2. 3
      src/plugins/shakecursor/shakedetector.h

@ -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();

@ -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;
};

Loading…
Cancel
Save