Skip to content

Commit 69c2bda

Browse files
committed
add loading 100 at a time
1 parent 98f8979 commit 69c2bda

File tree

4 files changed

+91
-55
lines changed

4 files changed

+91
-55
lines changed

src/Data.hpp

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -92,56 +92,6 @@ struct ZipData {
9292
QString release;
9393
};
9494

95-
/**
96-
* @struct ListItemData
97-
* @brief Represents a Tomb Raider Level Entry Card Info.
98-
*
99-
* This struct is designed to store a single TRLE (Tomb Raider Level Editor) level record.
100-
* Each record contains metadata and a cover image displayed as a card in the application.
101-
* The struct includes properties to facilitate searching, filtering, and sorting without
102-
* the cover image.
103-
*/
104-
struct ListItemData {
105-
/**
106-
* @brief Default constructor for `ListItemData`.
107-
*
108-
* Initializes an empty instance of `ListItemData`.
109-
*/
110-
ListItemData() {}
111-
112-
/**
113-
* @brief Parameterized constructor for `ListItemData`.
114-
*
115-
* This constructor initializes a `ListItemData` object with metadata.
116-
*
117-
* @param id The TRLE numeric level ID.
118-
* @param title The TRLE title. Expected to contain a single name.
119-
* @param author The TRLE author(s). Can be a single name or multiple names.
120-
* @param type The TRLE type, represented by a numeric ID.
121-
* @param classInput The TRLE class, represented by a numeric ID.
122-
* @param releaseDate The release date in the format "YYYY-MM-DD" (e.g., "2000-01-01").
123-
* @param difficulty The TRLE difficulty, represented by a numeric ID.
124-
* @param duration The TRLE duration, represented by a numeric ID.
125-
*/
126-
ListItemData(
127-
qint64 id, const QString& title, const QStringList& authors, qint64 type,
128-
qint64 classInput, const QString& releaseDate, qint64 difficulty,
129-
qint64 duration) :
130-
m_trle_id(id), m_title(title), m_authors(authors), m_type(type),
131-
m_class(classInput), m_releaseDate(releaseDate),
132-
m_difficulty(difficulty), m_duration(duration) {}
133-
134-
// Data members
135-
qint64 m_trle_id; ///< The TRLE level id.
136-
QString m_title; ///< The TRLE level title.
137-
QStringList m_authors; ///< The TRLE author(s), as a string list.
138-
qint64 m_type; ///< ID of the type of level.
139-
qint64 m_class; ///< ID of the class of the level.
140-
QString m_releaseDate; ///< The release date in "YYYY-MM-DD" format.
141-
qint64 m_difficulty; ///< ID of the difficulty of the level.
142-
qint64 m_duration; ///< ID of the estimated duration of the level.
143-
};
144-
14595
/**
14696
* @struct ListItemPicture
14797
* @brief Represents a Tomb Raider Level Entry Card Picture.
@@ -210,6 +160,60 @@ struct ListItemPicture {
210160
QIcon m_picture; ///< The cover image.
211161
};
212162

163+
/**
164+
* @struct ListItemData
165+
* @brief Represents a Tomb Raider Level Entry Card Info.
166+
*
167+
* This struct is designed to store a single TRLE (Tomb Raider Level Editor) level record.
168+
* Each record contains metadata and a cover image displayed as a card in the application.
169+
* The struct includes properties to facilitate searching, filtering, and sorting without
170+
* the cover image, just a pointer.
171+
*/
172+
struct ListItemData {
173+
/**
174+
* @brief Default constructor for `ListItemData`.
175+
*
176+
* Initializes an empty instance of `ListItemData`.
177+
*/
178+
ListItemData() {}
179+
180+
/**
181+
* @brief Parameterized constructor for `ListItemData`.
182+
*
183+
* This constructor initializes a `ListItemData` object with metadata.
184+
*
185+
* @param id The TRLE numeric level ID.
186+
* @param title The TRLE title. Expected to contain a single name.
187+
* @param author The TRLE author(s). Can be a single name or multiple names.
188+
* @param type The TRLE type, represented by a numeric ID.
189+
* @param classInput The TRLE class, represented by a numeric ID.
190+
* @param releaseDate The release date in the format "YYYY-MM-DD" (e.g., "2000-01-01").
191+
* @param difficulty The TRLE difficulty, represented by a numeric ID.
192+
* @param duration The TRLE duration, represented by a numeric ID.
193+
* @param m_cover The cover image as a `ListItemPicture*`.
194+
*/
195+
ListItemData(
196+
qint64 id, const QString& title, const QStringList& authors,
197+
qint64 type, qint64 classInput, const QString& releaseDate,
198+
qint64 difficulty, qint64 duration) :
199+
m_trle_id(id), m_title(title), m_authors(authors), m_type(type),
200+
m_class(classInput), m_releaseDate(releaseDate),
201+
m_difficulty(difficulty), m_duration(duration) {
202+
m_cover = nullptr;
203+
}
204+
205+
// Data members
206+
qint64 m_trle_id; ///< The TRLE level id.
207+
QString m_title; ///< The TRLE level title.
208+
QStringList m_authors; ///< The TRLE author(s), as a string list.
209+
qint64 m_type; ///< ID of the type of level.
210+
qint64 m_class; ///< ID of the class of the level.
211+
QString m_releaseDate; ///< The release date in "YYYY-MM-DD" format.
212+
qint64 m_difficulty; ///< ID of the difficulty of the level.
213+
qint64 m_duration; ///< ID of the estimated duration of the level.
214+
ListItemPicture* m_cover; ///< The TRLE cover image pointer.
215+
};
216+
213217
/**
214218
* @struct InfoData
215219
* @brief Store HTML data and a list of icons generated from image WEBP data.

src/TombRaiderLinuxLauncher.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
* GNU General Public License for more details.
1212
*/
1313

14-
#include <algorithm>
1514
#include "../src/TombRaiderLinuxLauncher.hpp"
1615
#include "ui_TombRaiderLinuxLauncher.h"
1716
#include "../src/staticData.hpp"
@@ -123,6 +122,9 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
123122
this,
124123
&TombRaiderLinuxLauncher::onCurrentItemChanged);
125124

125+
connect(ui->listViewLevels->verticalScrollBar(), &QScrollBar::valueChanged,
126+
this, &TombRaiderLinuxLauncher::loadMoreLevels);
127+
126128
// Read settings
127129
QString value = m_settings.value("setup").toString();
128130
if (value != "yes") {
@@ -136,6 +138,13 @@ void TombRaiderLinuxLauncher::generateList(const QList<int>& availableGames) {
136138
model->setLevels();
137139
}
138140

141+
void TombRaiderLinuxLauncher::loadMoreLevels(int value) {
142+
QScrollBar *bar = ui->listViewLevels->verticalScrollBar();
143+
if (value >= bar->maximum() - 5) {
144+
qDebug() << "loadMoreLevels";
145+
model->loadMoreLevels();
146+
}
147+
}
139148

140149
void TombRaiderLinuxLauncher::sortByTitle() {
141150
model->sortItems(model->compareTitles);

src/TombRaiderLinuxLauncher.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <QSettings>
1919
#include <QMessageBox>
2020
#include <QScrollArea>
21+
#include <QScrollBar>
2122
#include <QVBoxLayout>
2223
#include <QStringList>
2324
#include <QSet>
@@ -90,6 +91,7 @@ class TombRaiderLinuxLauncher : public QMainWindow {
9091
/**
9192
* Sorts the list by author.
9293
*/
94+
void loadMoreLevels(int value);
9395
void sortByAuthor();
9496
/**
9597
* Sorts the list by title.

src/levelViewList.hpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,26 @@ class LevelListModel : public QAbstractListModel {
3131
beginResetModel();
3232
infoList.clear();
3333
controller.getList(&infoList);
34+
if (infoList.count() > 100) {
35+
m_loadedRows = 100;
36+
m_stop = false;
37+
} else {
38+
m_loadedRows = infoList.count();
39+
m_stop = true;
40+
}
3441
endResetModel();
3542
}
3643

3744
int rowCount(const QModelIndex &parent = QModelIndex()) const override {
3845
Q_UNUSED(parent);
39-
return infoList.count();
46+
return m_loadedRows;
4047
}
4148

4249
QVariant data(const QModelIndex &index, int role) const override {
4350
QVariant result;
4451
int row = index.row();
4552

46-
if (index.isValid() && row < infoList.size()) {
53+
if (index.isValid() && row < infoList.count()) {
4754
const ListItemData &item = infoList.at(row);
4855
switch (role) {
4956
case Qt::DisplayRole:
@@ -73,8 +80,20 @@ class LevelListModel : public QAbstractListModel {
7380
return item.m_trle_id;
7481
}
7582

76-
ListItemData getListItemData(const qint64 &index) {
77-
return infoList.at(index);
83+
void loadMoreLevels() {
84+
if (!m_stop) {
85+
// we stop to prevent extra call while in here.
86+
m_stop = true;
87+
beginResetModel();
88+
if (infoList.count() > m_loadedRows + 100) {
89+
m_loadedRows = m_loadedRows + 100;
90+
m_stop = false; // we have more
91+
} else {
92+
m_loadedRows = infoList.count();
93+
m_stop = true; // we have less or equal
94+
}
95+
endResetModel();
96+
}
7897
}
7998

8099
void sortItems(
@@ -115,6 +134,8 @@ class LevelListModel : public QAbstractListModel {
115134
QVector<ListItemData> infoList;
116135
QVector<ListItemPicture> pictureList;
117136
// QVector<ListOriginalData> originalInfoList;
137+
bool m_stop = false;
138+
qint64 m_loadedRows = 0;
118139
Controller& controller = Controller::getInstance();
119140
};
120141

0 commit comments

Comments
 (0)