Skip to content

Commit e2096b6

Browse files
committed
change to QListView
its half way done but we save it at this point
1 parent e3196aa commit e2096b6

File tree

7 files changed

+422
-257
lines changed

7 files changed

+422
-257
lines changed

src/Data.cpp

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,73 @@ QVector<ListItemData> Data::getListItems() {
4141
QSqlQuery query(db);
4242
QVector<ListItemData> items;
4343

44-
if (!query.prepare(
45-
"SELECT Level.LevelID, Info.title, Author.value, Info.type, "
46-
"Info.class, Info.release, Info.difficulty, "
47-
"Info.duration, Picture.data "
44+
status = query.prepare(
45+
"SELECT Info.trleID, "
46+
"Info.title, "
47+
"GROUP_CONCAT(Author.value, ', ') AS authors, "
48+
"Info.type, "
49+
"Info.class, "
50+
"Info.release, "
51+
"Info.difficulty, "
52+
"Info.duration "
4853
"FROM Level "
4954
"JOIN Info ON Level.infoID = Info.InfoID "
50-
"JOIN Screens ON Level.LevelID = Screens.levelID "
51-
"JOIN Picture ON Screens.pictureID = Picture.PictureID "
5255
"JOIN AuthorList ON Level.LevelID = AuthorList.levelID "
5356
"JOIN Author ON AuthorList.authorID = Author.AuthorID "
54-
"GROUP BY Level.LevelID "
55-
"ORDER BY MIN(Picture.PictureID) ASC")) {
56-
qDebug() << "Error preparing query:" << query.lastError().text();
57-
status = false;
57+
"GROUP BY Info.trleID");
58+
if (!status) {
59+
qDebug() << "Error preparing query getListItems:" << query.lastError().text();
5860
}
5961

6062
if (status) {
6163
if (query.exec()) {
6264
while (query.next()) {
6365
items.append(ListItemData(
64-
query.value("Level.LevelID").toInt(),
66+
query.value("Info.trleID").toInt(),
6567
query.value("Info.title").toString(),
66-
query.value("Author.value").toString(),
68+
query.value("authors").toString().split(", "),
6769
query.value("Info.type").toInt(),
6870
query.value("Info.class").toInt(),
6971
query.value("Info.release").toString(),
7072
query.value("Info.difficulty").toInt(),
71-
query.value("Info.duration").toInt(),
72-
query.value("Picture.data").toByteArray()));
73+
query.value("Info.duration").toInt()));
7374
}
7475
} else {
75-
qDebug() << "Error executing query:" << query.lastError().text();
76+
qDebug() << "Error executing query getListItems:" << query.lastError().text();
77+
}
78+
}
79+
80+
return items;
81+
}
82+
83+
QVector<ListItemPicture> Data::getPictures(QList<qint64> trle_ids) {
84+
bool status = true;
85+
QSqlQuery query(db);
86+
QVector<ListItemPicture> items;
87+
88+
foreach(const qint64 &id, trle_ids) {
89+
status = query.prepare(
90+
"SELECT Info.trleID, Picture.data "
91+
"FROM Level "
92+
"JOIN Info ON Level.infoID = Info.InfoID "
93+
"JOIN Screens ON Level.LevelID = Screens.levelID "
94+
"JOIN Picture ON Screens.pictureID = Picture.PictureID "
95+
"WHERE Info.trleID = :id AND Screens.position = 0 ");
96+
query.bindValue(":id", id);
97+
if (!status) {
98+
qDebug() << "Error preparing query getPictures:" << query.lastError().text();
99+
}
100+
101+
if (status) {
102+
if (query.exec()) {
103+
if (query.next() == true) {
104+
items.append(ListItemPicture(
105+
query.value("Info.trleID").toInt(),
106+
query.value("Picture.data").toByteArray()));
107+
}
108+
} else {
109+
qDebug() << "Error executing query getPictures:" << query.lastError().text();
110+
}
76111
}
77112
}
78113

src/Data.hpp

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ struct ZipData {
9494

9595
/**
9696
* @struct ListItemData
97-
* @brief Represents a Tomb Raider Level Entry Card.
97+
* @brief Represents a Tomb Raider Level Entry Card Info.
9898
*
9999
* This struct is designed to store a single TRLE (Tomb Raider Level Editor) level record.
100100
* 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.
101+
* The struct includes properties to facilitate searching, filtering, and sorting without
102+
* the cover image.
102103
*/
103104
struct ListItemData {
104105
/**
@@ -111,29 +112,65 @@ struct ListItemData {
111112
/**
112113
* @brief Parameterized constructor for `ListItemData`.
113114
*
114-
* This constructor initializes a `ListItemData` object with metadata and a cover image.
115-
* The image is converted from raw `QByteArray` to a `QIcon` after scaling it to
116-
* fit within 640x480 dimensions. The scaling maintains the aspect ratio and
117-
* smooths out pixels using `Qt::SmoothTransformation`. The image is centered
118-
* within a transparent background if its aspect ratio does not perfectly match the target.
115+
* This constructor initializes a `ListItemData` object with metadata.
119116
*
120-
* @param id The database numeric ID.
117+
* @param id The TRLE numeric level ID.
121118
* @param title The TRLE title. Expected to contain a single name.
122-
* @param author The TRLE author(s). Can be a single name or multiple names separated by commas and spaces.
119+
* @param author The TRLE author(s). Can be a single name or multiple names.
123120
* @param type The TRLE type, represented by a numeric ID.
124121
* @param classInput The TRLE class, represented by a numeric ID.
125-
* @param releaseDate The release date in the format "DD-MMM-YYYY" (e.g., "01-Jan-2000").
122+
* @param releaseDate The release date in the format "YYYY-MM-DD" (e.g., "2000-01-01").
126123
* @param difficulty The TRLE difficulty, represented by a numeric ID.
127124
* @param duration The TRLE duration, represented by a numeric ID.
128-
* @param imageData The cover image as a `QByteArray`. Supported formats include JPEG, PNG, and WEBP.
129125
*/
130126
ListItemData(
131-
qint64 id, const QString& title, const QString& author, qint64 type,
127+
qint64 id, const QString& title, const QStringList& authors, qint64 type,
132128
qint64 classInput, const QString& releaseDate, qint64 difficulty,
133-
qint64 duration, QByteArray imageData) :
134-
m_id(id), m_title(title), m_author(author), m_type(type),
129+
qint64 duration) :
130+
m_trle_id(id), m_title(title), m_authors(authors), m_type(type),
135131
m_class(classInput), m_releaseDate(releaseDate),
136-
m_difficulty(difficulty), m_duration(duration) {
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+
145+
/**
146+
* @struct ListItemPicture
147+
* @brief Represents a Tomb Raider Level Entry Card Picture.
148+
*
149+
* This struct is designed to store a single TRLE (Tomb Raider Level Editor) level picture record.
150+
* Each record is a cover image displayed as a card in the application.
151+
*/
152+
struct ListItemPicture {
153+
/**
154+
* @brief Default constructor for `ListItemPicture`.
155+
*
156+
* Initializes an empty instance of `ListItemPicture`.
157+
*/
158+
ListItemPicture() {}
159+
160+
/**
161+
* @brief Parameterized constructor for `ListItemPicture`.
162+
*
163+
* This constructor initializes a `ListItemPicture` object with a cover image.
164+
* The image is converted from raw `QByteArray` to a `QIcon` after scaling it to
165+
* fit within 640x480 dimensions. The scaling maintains the aspect ratio and
166+
* smooths out pixels using `Qt::SmoothTransformation`. The image is centered
167+
* within a transparent background if its aspect ratio does not perfectly match the target.
168+
*
169+
* @param id The TRLE numeric level ID.
170+
* @param imageData The cover image as a `QByteArray`. Supported formats include JPEG, PNG, and WEBP.
171+
*/
172+
ListItemPicture(
173+
qint64 id, QByteArray imageData) : m_trle_id(id) {
137174
// Load the image from the byte array
138175
QPixmap pixmap;
139176
pixmap.loadFromData(imageData, "WEBP");
@@ -169,14 +206,7 @@ struct ListItemData {
169206
}
170207

171208
// Data members
172-
qint64 m_id; ///< The database level id.
173-
QString m_title; ///< The TRLE level title.
174-
QString m_author; ///< The TRLE author(s), as a string.
175-
qint64 m_type; ///< ID of the type of level.
176-
qint64 m_class; ///< ID of the class of the level.
177-
QString m_releaseDate; ///< The release date in "DD-MMM-YYYY" format.
178-
qint64 m_difficulty; ///< ID of the difficulty of the level.
179-
qint64 m_duration; ///< ID of the estimated duration of the level.
209+
qint64 m_trle_id; ///< The TRLE level id.
180210
QIcon m_picture; ///< The cover image.
181211
};
182212

@@ -264,6 +294,7 @@ class Data : public QObject {
264294

265295
qint64 getListRowCount();
266296
QVector<ListItemData> getListItems();
297+
QVector<ListItemPicture> getPictures(QList<qint64> trle_ids);
267298
InfoData getInfo(int id);
268299
QString getWalkthrough(int id);
269300
int getType(int id);

src/Model.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef SRC_MODEL_HPP_
1515
#define SRC_MODEL_HPP_
1616

17+
#include <QAbstractListModel>
1718
#include <QObject>
1819
#include <QMap>
1920
#include <QBitArray>
@@ -95,4 +96,7 @@ class Model : public QObject {
9596
Q_DISABLE_COPY(Model)
9697
};
9798

99+
100+
101+
98102
#endif // SRC_MODEL_HPP_

0 commit comments

Comments
 (0)