summaryrefslogtreecommitdiffstats
path: root/examples/corelib/tools/contiguouscache
diff options
context:
space:
mode:
authorAmanda Hamblin-Trué <amanda.hamblin-true@qt.io>2023-06-29 10:01:28 +0200
committerAmanda Hamblin-Trué <amanda.hamblin-true@qt.io>2023-06-30 12:55:01 +0200
commit15a7e108aae34cde280aa6b9c2449723a689ec0d (patch)
treefce424f0f21e93c5b4e2215009985a9421036cb8 /examples/corelib/tools/contiguouscache
parentf1db0ca2518bc4e3e4740f46a41c37715db14b4f (diff)
Contiguous cache example: minor cleanup
Modernised contiguous cache example. Change-Id: I88d67b03ed95a61484873149da16f0d814b26cd8 Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'examples/corelib/tools/contiguouscache')
-rw-r--r--examples/corelib/tools/contiguouscache/randomlistmodel.cpp20
-rw-r--r--examples/corelib/tools/contiguouscache/randomlistmodel.h1
2 files changed, 8 insertions, 13 deletions
diff --git a/examples/corelib/tools/contiguouscache/randomlistmodel.cpp b/examples/corelib/tools/contiguouscache/randomlistmodel.cpp
index 3997be2198..4832f0ae24 100644
--- a/examples/corelib/tools/contiguouscache/randomlistmodel.cpp
+++ b/examples/corelib/tools/contiguouscache/randomlistmodel.cpp
@@ -3,16 +3,12 @@
#include "randomlistmodel.h"
#include <QRandomGenerator>
-static const int bufferSize(500);
-static const int lookAhead(100);
-static const int halfLookAhead(lookAhead/2);
+static constexpr int bufferSize(500);
+static constexpr int lookAhead(100);
+static constexpr int halfLookAhead(lookAhead / 2);
RandomListModel::RandomListModel(QObject *parent)
-: QAbstractListModel(parent), m_rows(bufferSize), m_count(10000)
-{
-}
-
-RandomListModel::~RandomListModel()
+ : QAbstractListModel(parent), m_rows(bufferSize), m_count(10000)
{
}
@@ -31,14 +27,14 @@ QVariant RandomListModel::data(const QModelIndex &index, int role) const
if (row > m_rows.lastIndex()) {
if (row - m_rows.lastIndex() > lookAhead)
- cacheRows(row-halfLookAhead, qMin(m_count, row+halfLookAhead));
+ cacheRows(row - halfLookAhead, qMin(m_count, row + halfLookAhead));
else while (row > m_rows.lastIndex())
- m_rows.append(fetchRow(m_rows.lastIndex()+1));
+ m_rows.append(fetchRow(m_rows.lastIndex() + 1));
} else if (row < m_rows.firstIndex()) {
if (m_rows.firstIndex() - row > lookAhead)
- cacheRows(qMax(0, row-halfLookAhead), row+halfLookAhead);
+ cacheRows(qMax(0, row - halfLookAhead), row + halfLookAhead);
else while (row < m_rows.firstIndex())
- m_rows.prepend(fetchRow(m_rows.firstIndex()-1));
+ m_rows.prepend(fetchRow(m_rows.firstIndex() - 1));
}
return m_rows.at(row);
diff --git a/examples/corelib/tools/contiguouscache/randomlistmodel.h b/examples/corelib/tools/contiguouscache/randomlistmodel.h
index 72a6e05f7c..b95acdf3f9 100644
--- a/examples/corelib/tools/contiguouscache/randomlistmodel.h
+++ b/examples/corelib/tools/contiguouscache/randomlistmodel.h
@@ -13,7 +13,6 @@ class RandomListModel : public QAbstractListModel
Q_OBJECT
public:
RandomListModel(QObject *parent = nullptr);
- ~RandomListModel();
int rowCount(const QModelIndex & = QModelIndex()) const override;
QVariant data(const QModelIndex &, int) const override;