Skip to content

Commit a959461

Browse files
committed
improve InfoData struct
1 parent af0c5f6 commit a959461

File tree

4 files changed

+68
-32
lines changed

4 files changed

+68
-32
lines changed

src/Data.hpp

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
#ifndef SRC_DATA_HPP_
1515
#define SRC_DATA_HPP_
1616

17-
#include <QObject>
18-
#include <QSqlDatabase>
19-
#include <QSqlQuery>
2017
#include <QDebug>
21-
#include <QSqlError>
18+
#include <QFileInfo>
2219
#include <QIcon>
20+
#include <QObject>
2321
#include <QPixmap>
22+
#include <QSqlDatabase>
23+
#include <QSqlError>
24+
#include <QSqlQuery>
2425

2526
/**
2627
* @struct FolderNames
@@ -112,25 +113,48 @@ struct ListItemData {
112113
QIcon picture;
113114
};
114115

116+
/**
117+
* @struct InfoData
118+
* @brief Store HTML data and a list of icons generated from image WEBP data.
119+
*
120+
* This struct is designed to store a body of HTML and convert a list of image data
121+
* (provided as `QByteArray`) into `QIcon` objects. The `QIcon` objects can then
122+
* be used in Qt-based applications with QtWebEngine and QIcons in a split view manner.
123+
*/
115124
struct InfoData {
116125
/**
117-
* @struct InfoData
118-
* @brief
119-
* @param
120-
* @details
126+
* @brief Default constructor for `InfoData`.
127+
*
128+
* Initializes an empty body and an empty list of icons.
121129
*/
122130
InfoData() {}
123-
InfoData(QString body, QVector<QByteArray> imageList) : body(body) {
124-
for (const QByteArray &image : imageList) {
131+
132+
/**
133+
* @brief Constructs an `InfoData` object with the given body and image list.
134+
*
135+
* Converts each image in the provided `QVector<QByteArray>` to a `QIcon` object
136+
* using the "WEBP" format and stores them in the icon list.
137+
*
138+
* @param body A string representing the main textual content.
139+
* @param imageList A vector of image data in `QByteArray` format.
140+
*/
141+
InfoData(const QString& body, const QVector<QByteArray>& imageList)
142+
: m_body(body) {
143+
for (const QByteArray& image : imageList) {
125144
QPixmap pixmap;
126-
QIcon final;
127-
pixmap.loadFromData(image, "WEBP");
128-
final.addPixmap(pixmap);
129-
this->imageList.push_back(final);
145+
QIcon finalIcon;
146+
147+
// Load image data into a QPixmap and convert it to a QIcon
148+
if (pixmap.loadFromData(image, "WEBP")) {
149+
finalIcon.addPixmap(pixmap);
150+
}
151+
152+
m_imageList.push_back(finalIcon);
130153
}
131154
}
132-
QString body;
133-
QVector<QIcon> imageList;
155+
156+
QString m_body; ///< The textual content associated with this object.
157+
QVector<QIcon> m_imageList; ///< A list of icons generated from image data.
134158
};
135159

136160
class Data : public QObject {
@@ -142,17 +166,28 @@ class Data : public QObject {
142166
return instance;
143167
}
144168

145-
bool initializeDatabase(QString path) {
146-
db = QSqlDatabase::addDatabase("QSQLITE");
147-
db.setDatabaseName(path + "/tombll.db");
148-
db.setConnectOptions("QSQLITE_OPEN_READONLY");
169+
bool initializeDatabase(const QString& path) {
170+
bool status = false;
171+
const QString filePath = path + "/tombll.db";
172+
QFileInfo fileInfo(filePath);
149173

150-
if (db.open()) {
151-
return true;
174+
// Open the file
175+
if (!fileInfo.exists() || !fileInfo.isFile()) {
176+
qCritical()
177+
<< "Error: The database path is not a regular file: " << path;
178+
status = false;
152179
} else {
153-
qDebug() << "Error opening database:" << db.lastError().text();
154-
return false;
180+
db = QSqlDatabase::addDatabase("QSQLITE");
181+
db.setDatabaseName(path + "/tombll.db");
182+
db.setConnectOptions("QSQLITE_OPEN_READONLY");
183+
if (db.open()) { // flawfinder: ignore
184+
status = true;
185+
} else {
186+
qDebug() << "Error opening database:" << db.lastError().text();
187+
status = false;
188+
}
155189
}
190+
return status;
156191
}
157192

158193
void releaseDatabase() {

src/TombRaiderLinuxLauncher.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ void TombRaiderLinuxLauncher::infoClicked() {
449449
int id = selectedItem->data(Qt::UserRole).toInt();
450450
if (id) {
451451
InfoData info = controller.getInfo(id);
452-
ui->infoWebEngineView->setHtml(info.body);
452+
ui->infoWebEngineView->setHtml(info.m_body);
453453
ui->infoListWidget->setViewMode(QListView::IconMode);
454454
ui->infoListWidget->setIconSize(QSize(502, 377));
455455
ui->infoListWidget->setDragEnabled(false);
@@ -458,8 +458,8 @@ void TombRaiderLinuxLauncher::infoClicked() {
458458
ui->infoListWidget->setDefaultDropAction(Qt::IgnoreAction);
459459
ui->infoListWidget->setSelectionMode(QAbstractItemView::NoSelection);
460460
ui->infoListWidget->clear();
461-
for (int i = 0; i < info.imageList.size(); ++i) {
462-
const QIcon &icon = info.imageList.at(i);
461+
for (int i = 0; i < info.m_imageList.size(); ++i) {
462+
const QIcon &icon = info.m_imageList.at(i);
463463
QListWidgetItem *item = new QListWidgetItem(icon, "");
464464
ui->infoListWidget->addItem(item);
465465
}

src/binary.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ qint64 findReplacePattern(QFile* const file) {
7070
* @return error qint64.
7171
*/
7272
qint64 widescreen_set(const QString& path) {
73-
qint64 status = 0; // Initialize the status variable
73+
qint64 status = 0;
7474
QFileInfo fileInfo(path);
7575
QFile file(path);
7676

7777
// Open the file
7878
if (!fileInfo.exists() || !fileInfo.isFile()) {
7979
qCritical() << "Error: The exe path is not a regular file: " << path;
80-
return 1; // Invalid file path
80+
status = 1; // Invalid file path
8181
} else if (!file.open(QIODevice::ReadOnly)) { // flawfinder: ignore
8282
qCritical() << "Error opening file for reading!";
83-
return 2; // File open error
83+
status = 2; // File open error
8484
} else {
8585
// Perform the pattern replacement and propagate the status
8686
status = findReplacePattern(&file);

src/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#ifdef TEST
2626
/**
27-
*
27+
* The main function used for console tests
2828
*/
2929
int main(int argc, char *argv[]) {
3030
QCoreApplication app(argc, argv);
@@ -56,7 +56,8 @@ int main(int argc, char *argv[]) {
5656
}
5757
#else
5858
/**
59-
*
59+
* The main function used for the regular qt app.
60+
* Takes care of command line arguments and create the window.
6061
*/
6162
int main(int argc, char *argv[]) {
6263
QApplication a(argc, argv);

0 commit comments

Comments
 (0)