8#include "HistoryProxySource.h"
12HistoryProxySource::HistoryProxySource(
QObject *parent)
17int HistoryProxySource::itemCount()
const
20 return m_history.
size();
22 return m_maximumHistory;
28 if (index < 0 || !m_dataSource || m_dataSource->itemCount() == 0) {
41 auto actualIndex = index - (m_maximumHistory - m_history.
count());
42 if (actualIndex < 0 || actualIndex >= m_history.
size()) {
45 return m_history.
at(actualIndex);
49 if (index < m_history.
count()) {
50 return m_history.
at(index);
56QVariant HistoryProxySource::minimum()
const
58 if (m_history.
isEmpty() || !m_dataSource) {
66 auto minProperty = model->property(
"minimum");
67 auto maxProperty = model->property(
"maximum");
68 if (minProperty.isValid() && minProperty != maxProperty) {
73 return *std::min_element(m_history.
begin(), m_history.
end(), variantCompare);
76QVariant HistoryProxySource::maximum()
const
78 if (m_history.
isEmpty() || !m_dataSource) {
84 auto minProperty = model->property(
"minimum");
85 auto maxProperty = model->property(
"maximum");
86 if (maxProperty.isValid() && maxProperty != minProperty) {
91 return *std::max_element(m_history.
begin(), m_history.
end(), variantCompare);
94QVariant HistoryProxySource::first()
const
97 return m_history.
first();
109 if (newSource == m_dataSource) {
117 m_dataSource = newSource;
120 connect(m_dataSource, &ChartDataSource::dataChanged,
this, [
this]() {
121 if (!m_updateTimer) {
134void HistoryProxySource::setItem(
int newItem)
136 if (newItem == m_item) {
147 return m_maximumHistory;
150void HistoryProxySource::setMaximumHistory(
int newMaximumHistory)
152 if (newMaximumHistory == m_maximumHistory) {
156 m_maximumHistory = newMaximumHistory;
157 while (m_history.
size() > 0 && m_history.
size() > m_maximumHistory) {
161 Q_EMIT maximumHistoryChanged();
166 return m_updateTimer ? m_updateTimer->interval() : -1;
169void HistoryProxySource::setInterval(
int newInterval)
171 if (m_updateTimer && newInterval == m_updateTimer->interval()) {
175 if (newInterval > 0) {
176 if (!m_updateTimer) {
177 m_updateTimer = std::make_unique<QTimer>();
184 m_updateTimer->setInterval(newInterval);
185 m_updateTimer->start();
187 m_updateTimer.reset();
198void HistoryProxySource::setFillMode(FillMode newFillMode)
200 if (newFillMode == m_fillMode) {
204 m_fillMode = newFillMode;
215void HistoryProxySource::update()
221 m_history.
prepend(m_dataSource->item(m_item));
222 while (m_history.
size() > 0 && m_history.
size() > m_maximumHistory) {
229#include "moc_HistoryProxySource.cpp"
Abstract base class for data sources.
ChartDataSource * source
The data source to read data from.
FillMode
The different fill modes.
@ DoNotFill
Do not fill with any items.
@ FillFromEnd
Fill with empty values, placing partial history at the end.
@ FillFromStart
Fill with empty values, starting at 0.
int item
The item of the data source to read data from.
int interval
The interval, in milliseconds, with which to query the data source.
FillMode fillMode
The fill mode.
int maximumHistory
The maximum amount of history to keep.
Q_INVOKABLE void clear()
Clear the entire history of this source.
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
void prepend(parameter_type value)
qsizetype size() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QVariant property(const char *name) const const
int userType() const const