File indexing completed on 2024-04-28 05:48:39
0001 /* 0002 SPDX-FileCopyrightText: 2010 Marco Mentasti <marcomentasti@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #pragma once 0008 0009 #include <QContiguousCache> 0010 #include <QSqlQueryModel> 0011 #include <QSqlRecord> 0012 0013 class CachedSqlQueryModel : public QSqlQueryModel 0014 { 0015 Q_OBJECT 0016 public: 0017 explicit CachedSqlQueryModel(QObject *parent = nullptr, int cacheCapacity = 1000); 0018 0019 QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override; 0020 QSqlRecord record(int row) const; 0021 void clear() override; 0022 0023 int cacheCapacity() const; 0024 0025 public Q_SLOTS: 0026 void clearCache(); 0027 void setCacheCapacity(int); 0028 0029 protected: 0030 void queryChange() override; 0031 0032 private: 0033 void cacheRecords(int from, int to) const; 0034 0035 mutable QContiguousCache<QSqlRecord> cache; 0036 };