Skip to content

Commit 6708c00

Browse files
committed
fix gaps in level list from Level.LevelID
1 parent 9e653ee commit 6708c00

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

.neovim.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ require('lint').linters_by_ft = {
8585
cpp = {'cppcheck', 'cpplint', 'flawfinder', 'clangtidy'},
8686
}
8787

88+
-- build cppcheck-2.6.3 or you are on you're own with new version
8889
-- .local/share/nvim/plugged/nvim-lint/lua/lint/linters/cppcheck.lua
8990
-- cppcheck <= 1.84 doesn't support {column} so the start_col group is ambiguous
9091
local pattern = [[([^:]*):(%d*):([^:]*): %[([^%]\]*)%] ([^:]*): (.*)]]

src/Data.cpp

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

14-
#include "Data.hpp"
14+
#include "../src/Data.hpp"
1515

1616
qint64 Data::getListRowCount() {
1717
QSqlQuery query(db);
@@ -37,48 +37,45 @@ qint64 Data::getListRowCount() {
3737
}
3838

3939
QVector<ListItemData> Data::getListItems() {
40-
QSqlQuery query(db);
4140
bool status = true;
41+
QSqlQuery query(db);
4242
QVector<ListItemData> items;
43-
qint64 rowCount = getListRowCount();
4443

4544
if (!query.prepare(
46-
"SELECT Info.title, Author.value, Info.type, "
45+
"SELECT Level.LevelID, Info.title, Author.value, Info.type, "
4746
"Info.class, Info.release, Info.difficulty, "
48-
"Info.duration, Picture.data FROM Level "
47+
"Info.duration, Picture.data "
48+
"FROM Level "
4949
"JOIN Info ON Level.infoID = Info.InfoID "
5050
"JOIN Screens ON Level.LevelID = Screens.levelID "
5151
"JOIN Picture ON Screens.pictureID = Picture.PictureID "
5252
"JOIN AuthorList ON Level.LevelID = AuthorList.levelID "
5353
"JOIN Author ON AuthorList.authorID = Author.AuthorID "
54-
"WHERE Level.LevelID = :id "
5554
"GROUP BY Level.LevelID "
5655
"ORDER BY MIN(Picture.PictureID) ASC")) {
5756
qDebug() << "Error preparing query:" << query.lastError().text();
5857
status = false;
5958
}
6059

6160
if (status) {
62-
for (qint64 i = 1; i <= rowCount; i++) {
63-
query.bindValue(":id", i); // Bind the current LevelID
64-
if (query.exec() == true) {
65-
while (query.next() == true) {
66-
items.append(ListItemData(
67-
query.value("Info.title").toString(),
68-
query.value("Author.value").toString(),
69-
query.value("Info.type").toInt(),
70-
query.value("Info.class").toInt(),
71-
query.value("Info.release").toString(),
72-
query.value("Info.difficulty").toInt(),
73-
query.value("Info.duration").toInt(),
74-
query.value("Picture.data").toByteArray()));
75-
}
76-
} else {
77-
qDebug() << "Error executing query for Level ID:" << i
78-
<< query.lastError().text();
61+
if (query.exec()) {
62+
while (query.next()) {
63+
items.append(ListItemData(
64+
query.value("Level.LevelID").toInt(),
65+
query.value("Info.title").toString(),
66+
query.value("Author.value").toString(),
67+
query.value("Info.type").toInt(),
68+
query.value("Info.class").toInt(),
69+
query.value("Info.release").toString(),
70+
query.value("Info.difficulty").toInt(),
71+
query.value("Info.duration").toInt(),
72+
query.value("Picture.data").toByteArray()));
7973
}
74+
} else {
75+
qDebug() << "Error executing query:" << query.lastError().text();
8076
}
8177
}
78+
8279
return items;
8380
}
8481

src/Data.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct ListItemData {
117117
* smooths out pixels using `Qt::SmoothTransformation`. The image is centered
118118
* within a transparent background if its aspect ratio does not perfectly match the target.
119119
*
120+
* @param id The database numeric ID.
120121
* @param title The TRLE title. Expected to contain a single name.
121122
* @param author The TRLE author(s). Can be a single name or multiple names separated by commas and spaces.
122123
* @param type The TRLE type, represented by a numeric ID.
@@ -127,10 +128,10 @@ struct ListItemData {
127128
* @param imageData The cover image as a `QByteArray`. Supported formats include JPEG, PNG, and WEBP.
128129
*/
129130
ListItemData(
130-
const QString& title, const QString& author, qint64 type,
131+
qint64 id, const QString& title, const QString& author, qint64 type,
131132
qint64 classInput, const QString& releaseDate, qint64 difficulty,
132133
qint64 duration, QByteArray imageData) :
133-
m_title(title), m_author(author), m_type(type),
134+
m_id(id), m_title(title), m_author(author), m_type(type),
134135
m_class(classInput), m_releaseDate(releaseDate),
135136
m_difficulty(difficulty), m_duration(duration) {
136137
// Load the image from the byte array
@@ -168,6 +169,7 @@ struct ListItemData {
168169
}
169170

170171
// Data members
172+
qint64 m_id; ///< The database level id.
171173
QString m_title; ///< The TRLE level title.
172174
QString m_author; ///< The TRLE author(s), as a string.
173175
qint64 m_type; ///< ID of the type of level.

src/Model.cpp

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

14-
#include "Model.hpp"
14+
#include "../src/Model.hpp"
1515

1616
Model::Model() {}
1717
Model::~Model() {}

src/TombRaiderLinuxLauncher.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
*/
1313

1414
#include <algorithm>
15-
#include "TombRaiderLinuxLauncher.hpp"
15+
#include "../src/TombRaiderLinuxLauncher.hpp"
1616
#include "ui_TombRaiderLinuxLauncher.h"
17-
#include "staticData.hpp"
17+
#include "../src/staticData.hpp"
1818
// #include "debug.hpp"
1919

2020
TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
@@ -181,7 +181,7 @@ void TombRaiderLinuxLauncher::generateList(const QList<int>& availableGames) {
181181
QListWidgetItem *wi =
182182
new QListWidgetItem(list[i].m_picture, tag);
183183

184-
wi->setData(Qt::UserRole, QVariant(i + 1));
184+
wi->setData(Qt::UserRole, QVariant(list[i].m_id));
185185
QVariantMap itemData;
186186
itemData["title"] = list[i].m_title;
187187
itemData["author"] = list[i].m_author;

0 commit comments

Comments
 (0)