Skip to content

Commit e7a061e

Browse files
committed
update to QT6
1 parent c43a943 commit e7a061e

File tree

4 files changed

+66
-55
lines changed

4 files changed

+66
-55
lines changed

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ else()
1414
set(CMAKE_BUILD_TYPE Release)
1515
endif()
1616

17-
find_package(Qt5 COMPONENTS Core Gui Test Widgets WebEngineWidgets Sql REQUIRED)
17+
find_package(Qt6 COMPONENTS Core Gui Test Widgets WebEngineWidgets Sql REQUIRED)
1818

1919
find_package(CURL REQUIRED)
2020

@@ -146,18 +146,18 @@ set(SOURCES_VIEW
146146
)
147147

148148
set(LINK_COMMON
149-
Qt5::Core
150-
Qt5::Widgets
151-
Qt5::WebEngineWidgets
152-
Qt5::Sql
149+
Qt6::Core
150+
Qt6::Widgets
151+
Qt6::WebEngineWidgets
152+
Qt6::Sql
153153
miniz
154154
LIEF::LIEF
155155
${CURL_LIBRARY}
156156
"${CMAKE_SOURCE_DIR}/libs/libbacktrace/.libs/libbacktrace.a"
157157
)
158158

159159
set(LINK_GUI
160-
Qt5::Gui
160+
Qt6::Gui
161161
)
162162

163163
set(INCLUDE_DIR
@@ -176,7 +176,7 @@ if(TEST)
176176
set(SOURCES ${SOURCES_MC} ${SOURCES_TESTS})
177177
add_executable(${PROJECT_NAME}Test ${SOURCES})
178178
add_test(NAME ${PROJECT_NAME}Test COMMAND ${PROJECT_NAME}Test)
179-
target_link_libraries(${PROJECT_NAME}Test PUBLIC ${LINK_COMMON} Qt5::Test)
179+
target_link_libraries(${PROJECT_NAME}Test PUBLIC ${LINK_COMMON} Qt6::Test)
180180
target_include_directories(${PROJECT_NAME}Test PRIVATE ${INCLUDE_DIR} test)
181181
target_compile_definitions(${PROJECT_NAME}Test PRIVATE TEST)
182182
set_target_properties(${PROJECT_NAME}Test PROPERTIES

src/LevelViewList.cpp

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,60 +45,65 @@ QVariant LevelListModel::data(const QModelIndex &index, int role) const {
4545
return result;
4646
}
4747

48+
inline quint64 LevelListModel::indexInBounds(const quint64 index) const {
49+
return qMin(index, quint64(m_levels.size()));
50+
}
51+
4852
void LevelListModel::setScrollChange(const quint64 index) {
4953
if (!m_levels.empty()) {
5054
m_scrollCursorChanged = true;
51-
m_seq_cursor_a = m_cursor_a.row();
52-
53-
quint64 size = m_levels.size();
54-
quint64 i = qMin(index, size);
55-
m_cursor_a = this->index(i, 0);
55+
m_scroll_cursor_a = indexInBounds(index);;
5656
}
5757
}
5858

59-
QVector<QSharedPointer<ListItemData>> LevelListModel::getDataBuffer(quint64 items) {
60-
QVector<QSharedPointer<ListItemData>> buffer;
59+
QVector<QSharedPointer<ListItemData>>
60+
LevelListModel::getChunk(const quint64 cursor, const quint64 items) {
61+
const quint64 len = indexInBounds(cursor + items) - cursor;
62+
return m_levels.mid(cursor, len);
63+
}
6164

65+
QVector<QSharedPointer<ListItemData>>
66+
LevelListModel::getDataBuffer(quint64 items) {
67+
QVector<QSharedPointer<ListItemData>> chunk;
6268
if ((items > 0) && !m_levels.isEmpty()) {
63-
quint64 size = m_levels.size();
64-
// m_cursor_a starts on -1
65-
// there is no way to inialize it
66-
quint64 a = m_cursor_a.row() + 1;
67-
quint64 b = qMin(a + items, size);
68-
69-
m_cursor_b = this->index(b, 0);
70-
71-
buffer.reserve(b - a);
72-
for (quint64 i = a; i < b; ++i) {
73-
buffer.append(m_levels[i]);
69+
if (m_scrollCursorChanged == true) {
70+
m_scroll_cursor_b = indexInBounds(m_scroll_cursor_a + items);
71+
chunk = getChunk(m_scroll_cursor_a, items);
72+
} else {
73+
m_cursor_b = indexInBounds(m_cursor_a + items);
74+
chunk = getChunk(m_cursor_a, items);
7475
}
7576
}
7677

77-
return buffer;
78+
return chunk;
7879
}
7980

80-
void LevelListModel::reset() {
81-
if (m_cursor_a.isValid() && m_cursor_b.isValid()) {
82-
emit dataChanged(m_cursor_a, m_cursor_b);
81+
void LevelListModel::updateCovers(quint64 a, quint64 b) {
82+
QModelIndex index_a(index(a, 0));
83+
QModelIndex index_b(index(b, 0));
84+
if (index_a.isValid() && index_b.isValid()) {
85+
qDebug() << "LevelListModel updated covers "
86+
<< index_a.row() << " to " << index_b.row();
87+
emit dataChanged(index_a, index_b);
8388
}
89+
}
8490

91+
void LevelListModel::reset() {
8592
if (m_scrollCursorChanged == true) {
86-
m_cursor_a = this->index(m_seq_cursor_a, 0);
93+
updateCovers(m_scroll_cursor_a, m_scroll_cursor_b);
94+
m_scroll_cursor_a = m_scroll_cursor_b;
8795
m_scrollCursorChanged = false;
8896
} else {
89-
m_cursor_a = this->index(m_cursor_b.row(), 0);
97+
updateCovers(m_cursor_a, m_cursor_b);
98+
m_cursor_a = m_cursor_b;
9099
}
91100
}
92101

93-
bool LevelListModel::stop() {
94-
bool status = false;
95-
if (m_scrollCursorChanged == false) {
96-
status = (m_cursor_b.row() >= m_levels.size());
97-
}
98-
return status;
102+
bool LevelListModel::stop() const {
103+
return !m_scrollCursorChanged && (m_cursor_b >= m_levels.size());
99104
}
100105

101-
quint64 LevelListProxy::getLid(const QModelIndex &i) {
106+
quint64 LevelListProxy::getLid(const QModelIndex &i) const {
102107
quint64 id = sourceModel()->data(i, Qt::UserRole+1).toInt();
103108
if (id == 0) {
104109
id = sourceModel()->data(i, Qt::UserRole+10).toInt();
@@ -107,11 +112,11 @@ quint64 LevelListProxy::getLid(const QModelIndex &i) {
107112
return id;
108113
}
109114

110-
bool LevelListProxy::getItemType(const QModelIndex &i) {
115+
bool LevelListProxy::getItemType(const QModelIndex &i) const {
111116
return sourceModel()->data(i, Qt::UserRole+1).toBool();
112117
}
113118

114-
bool LevelListProxy::getInstalled(const QModelIndex &i) {
119+
bool LevelListProxy::getInstalled(const QModelIndex &i) const {
115120
return sourceModel()->data(i, Qt::UserRole+11).toBool();
116121
}
117122

src/LevelViewList.hpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class LevelListModel : public QAbstractListModel {
3030
explicit LevelListModel(QObject *parent = nullptr)
3131
: QAbstractListModel(parent),
3232
m_scrollCursorChanged(false),
33-
m_seq_cursor_a(0),
33+
m_scroll_cursor_a(0),
34+
m_scroll_cursor_b(0),
35+
m_cursor_a(0),
36+
m_cursor_b(0),
3437
m_roleTable({
3538
{ Qt::DisplayRole, [](const ListItemData &i){ return i.m_title; }},
3639
{ Qt::UserRole+1, [](const ListItemData &i){ return i.m_game_id; }},
@@ -47,11 +50,15 @@ class LevelListModel : public QAbstractListModel {
4750
})
4851
{}
4952

53+
QVector<QSharedPointer<ListItemData>> getChunk(const quint64 cursor,
54+
const quint64 items);
5055
QVector<QSharedPointer<ListItemData>> getDataBuffer(const quint64 items);
5156
void setLevels(const QVector<QSharedPointer<ListItemData>>& levels);
5257
void setScrollChange(const quint64 index);
5358
void setInstalled(const QModelIndex &index);
54-
bool stop();
59+
quint64 indexInBounds(quint64 index) const;
60+
bool stop() const;
61+
void updateCovers(quint64 a, quint64 b);
5562
void reset();
5663
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
5764
QVariant data(const QModelIndex &index, int role) const override;
@@ -60,9 +67,10 @@ class LevelListModel : public QAbstractListModel {
6067
const QHash<int, std::function<QVariant(const ListItemData&)>> m_roleTable;
6168
QVector<QSharedPointer<ListItemData>> m_levels;
6269
bool m_scrollCursorChanged;
63-
quint64 m_seq_cursor_a;
64-
QModelIndex m_cursor_a;
65-
QModelIndex m_cursor_b;
70+
quint64 m_scroll_cursor_a;
71+
quint64 m_scroll_cursor_b;
72+
quint64 m_cursor_a;
73+
quint64 m_cursor_b;
6674
};
6775

6876

@@ -81,9 +89,9 @@ class LevelListProxy : public QSortFilterProxyModel {
8189
m_sortMode(ReleaseDate)
8290
{}
8391

84-
quint64 getLid(const QModelIndex &i);
85-
bool getItemType(const QModelIndex &i);
86-
bool getInstalled(const QModelIndex &i);
92+
quint64 getLid(const QModelIndex &i) const;
93+
bool getItemType(const QModelIndex &i) const;
94+
bool getInstalled(const QModelIndex &i) const;
8795

8896
void setClassFilter(const QString &c);
8997
void setTypeFilter(const QString &t);

src/TombRaiderLinuxLauncher.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ InstalledStatus TombRaiderLinuxLauncher::getInstalled() {
216216
for (const auto &key : std::as_const(keys)) {
217217
if (key.startsWith("installed/game")) {
218218
quint64 id =
219-
key.midRef(QString("installed/game").length()).toUInt();
219+
key.mid(QString("installed/game").length()).toUInt();
220220
list.game.insert(id, settings.value(key).toBool());
221221
} else if (key.startsWith("installed/level")) {
222222
quint64 id =
223-
key.midRef(QString("installed/level").length()).toUInt();
223+
key.mid(QString("installed/level").length()).toUInt();
224224
list.trle.insert(id, settings.value(key).toBool());
225225
}
226226
}
@@ -602,18 +602,16 @@ void TombRaiderLinuxLauncher::backClicked() {
602602

603603
void TombRaiderLinuxLauncher::loadMoreCovers() {
604604
static bool firstTime = true;
605-
if (firstTime) {
606-
firstTime = false;
607-
} else {
605+
if (!firstTime) {
608606
levelListModel->reset();
607+
} else {
608+
firstTime = false;
609609
}
610610
if (!levelListModel->stop()) {
611611
QVector<QSharedPointer<ListItemData>> buffer =
612612
levelListModel->getDataBuffer(100);
613613
if (!buffer.isEmpty()) {
614614
controller.getCoverList(buffer);
615-
} else {
616-
levelListModel->reset();
617615
}
618616
}
619617
}

0 commit comments

Comments
 (0)