00001 #ifndef CACHEDPLOTCURVEDATAMODEL_H 00002 #define CACHEDPLOTCURVEDATAMODEL_H 00003 00007 struct DataPoint 00008 { 00009 DataPoint() : time_t(0), data(0){} 00010 DataPoint(int time_t, float data){ 00011 this->time_t = time_t; 00012 this->data = data; 00013 } 00014 unsigned int time_t; 00015 float data; //conversion from float to double is implicit and very fast (<15ms for 1M conversions) 00016 }; 00017 00018 #include "basequerymodel.h" 00019 00020 #include <qwt_data.h> 00021 #include <QObject> 00022 #include <QPointer> 00023 00027 class CachedPlotCurveDataModel : public QObject, public QwtData 00028 { 00029 Q_OBJECT 00030 public: 00031 CachedPlotCurveDataModel(QAbstractItemModel *model, int xColumn, int yColumn); 00032 size_t size() const; 00033 double x(size_t i) const; 00034 double y(size_t i) const; 00035 QwtData *copy() const; 00036 00037 private: 00038 void setModel(QAbstractItemModel *model, int xColumn, int yColumn); 00039 QAbstractItemModel *model() const; 00040 DataPoint updateCache(size_t i) const; 00041 const DataPoint previousNotNull(size_t i) const; 00042 void updateRowsSkip(); 00043 00044 private slots: 00045 void resetCache(); 00046 00047 signals: 00048 void signal_dataChanged(); 00049 00050 private: 00051 mutable QHash<unsigned int, DataPoint> cache; 00052 QPointer<QAbstractItemModel> sourceModel; 00053 int xColumn; 00054 int yColumn; 00055 size_t m_size; 00056 }; 00057 00058 #endif // CACHEDPLOTCURVEDATAMODEL_H