Warning, file /frameworks/kquickcharts/src/datasource/ModelHistorySource.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * This file is part of KQuickCharts
0003  * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  */
0007 
0008 #ifndef MODELHISTORYSOURCE_H
0009 #define MODELHISTORYSOURCE_H
0010 
0011 #include "ModelSource.h"
0012 #include "quickcharts_export.h"
0013 #include <QTimer>
0014 #include <memory>
0015 
0016 #if QUICKCHARTS_BUILD_DEPRECATED_SINCE(5, 78)
0017 
0018 /**
0019  * A data source that watches a QAbstractItemModel cell and provides the history of that cell as data.
0020  *
0021  * \deprecated Since 5.78, use HistoryProxySource instead with a ModelSource as
0022  * inner source.
0023  */
0024 class ModelHistorySource : public ModelSource
0025 {
0026     Q_OBJECT
0027     /**
0028      * The row to read data from.
0029      *
0030      * The items of this source will be the values of that row, using the column
0031      * and role from ModelSource.
0032      *
0033      * The default is 0.
0034      */
0035     Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged)
0036     /**
0037      * The maximum amount of history to keep.
0038      *
0039      * The default is 10.
0040      */
0041     Q_PROPERTY(int maximumHistory READ maximumHistory WRITE setMaximumHistory NOTIFY maximumHistoryChanged)
0042     /**
0043      * The interval, in milliseconds, with which to query the model.
0044      *
0045      * If not set or set to a value < 0, a new item will be added whenever the
0046      * underlying model changes. Otherwise, the source will sample the
0047      * underlying model every interval milliseconds and add a new item with
0048      * whatever value the model has at that point - even if it did not change.
0049      *
0050      * The default is 0.
0051      */
0052     Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
0053 
0054 public:
0055     explicit ModelHistorySource(QObject *parent = nullptr);
0056 
0057     virtual int itemCount() const override;
0058     virtual QVariant item(int index) const override;
0059     virtual QVariant minimum() const override;
0060     virtual QVariant maximum() const override;
0061 
0062     int row() const;
0063     void setRow(int row);
0064     Q_SIGNAL void rowChanged();
0065 
0066     int maximumHistory() const;
0067     void setMaximumHistory(int maximumHistory);
0068     Q_SIGNAL void maximumHistoryChanged();
0069 
0070     int interval() const;
0071     void setInterval(int newInterval);
0072     Q_SIGNAL void intervalChanged();
0073 
0074     Q_INVOKABLE void clear();
0075 
0076 private:
0077     void onModelChanged();
0078     void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
0079 
0080     int m_row = 0;
0081     int m_maximumHistory = 10;
0082     QVariantList m_history;
0083     std::unique_ptr<QTimer> m_updateTimer;
0084 };
0085 
0086 #endif // QUICKCHARTS_BUILD_DEPRECATED_SINCE
0087 
0088 #endif // MODELHISTORYSOURCE_H