Skip to content

Commit b3f50c6

Browse files
committed
add ascending sort order, fix command line parser
1 parent 87bce56 commit b3f50c6

File tree

9 files changed

+160
-53
lines changed

9 files changed

+160
-53
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ set(SOURCES_MC
140140
src/gameFileTreeData.hpp
141141
src/globalTypes.hpp
142142
src/main.cpp
143-
src/staticData.hpp
143+
src/staticViewData.hpp
144144
)
145145

146146
set(SOURCES_VIEW

src/CommandLineParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ CommandLineParser::CommandLineParser(const QString& type) : m_processStatus(0) {
7171
QCommandLineOption filterByDifficultyOption(filterByDifficultyName);
7272
const QString filterByDifficultyDesc = QString("%1%2%3").arg(
7373
"Filter levels by difficulty. Allowed values:\n",
74-
m_type_options.join(", "),
74+
m_difficulty_options.join(", "),
7575
"\n");
7676
filterByDifficultyOption.setDescription(filterByDifficultyDesc);
7777
filterByDifficultyOption.setValueName("difficulty");
@@ -84,7 +84,7 @@ CommandLineParser::CommandLineParser(const QString& type) : m_processStatus(0) {
8484

8585
const QString filterByDurationDesc = QString("%1%2%3").arg(
8686
"Filter levels by duration. Allowed values:\n",
87-
m_type_options.join(", "),
87+
m_duration_options.join(", "),
8888
"\n");
8989
filterByDurationOption.setDescription(filterByDurationDesc);
9090
filterByDurationOption.setValueName("duration");

src/LevelViewList.cpp

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,91 @@
1414
#include "../src/LevelViewList.hpp"
1515

1616
#include <QDateTime>
17-
#include "../src/staticData.hpp"
17+
#include "../src/staticViewData.hpp"
1818

19+
20+
LevelViewList::LevelViewList(QWidget *parent)
21+
: QListView(parent)
22+
{
23+
}
24+
25+
void LevelViewList::scrollContentsBy(int dx, int dy)
26+
{
27+
// qDebug() << "LevelViewList::scrollContentsBy: " << "";
28+
QListView::scrollContentsBy(dx, dy);
29+
// updateVisibleItems();
30+
}
31+
32+
void LevelViewList::resizeEvent(QResizeEvent *event)
33+
{
34+
// qDebug() << "LevelViewList::resizeEvent: " << "";
35+
QListView::resizeEvent(event);
36+
// updateVisibleItems();
37+
}
38+
39+
void LevelViewList::paintEvent(QPaintEvent *event)
40+
{
41+
// qDebug() << "LevelViewList::paintEvent: " << "";
42+
QListView::paintEvent(event);
43+
// updateVisibleItems();
44+
}
45+
46+
QModelIndexList LevelViewList::visibleIndexes() const
47+
{
48+
QModelIndexList result;
49+
auto r = viewport()->rect();
50+
auto topLeft = indexAt(r.topLeft());
51+
auto bottomRight = indexAt(r.bottomRight());
52+
53+
if (!topLeft.isValid() || !bottomRight.isValid())
54+
return result;
55+
56+
int top = topLeft.row();
57+
int bottom = bottomRight.row();
58+
for (int row = top; row <= bottom; ++row) {
59+
auto idx = indexAt(QPoint(0, visualRect(model()->index(row, 0)).center().y()));
60+
if (idx.isValid())
61+
result << idx;
62+
}
63+
return result;
64+
}
65+
66+
void LevelViewList::updateVisibleItems()
67+
{
68+
QModelIndexList vis = visibleIndexes();
69+
for (auto &idx : vis) {
70+
if (!idx.isValid())
71+
continue;
72+
// Map proxy index to source index if model is a proxy
73+
QModelIndex sourceIdx = idx;
74+
// Try cast to QAbstractProxyModel to map
75+
if (auto proxy = qobject_cast<QAbstractProxyModel *>(model())) {
76+
sourceIdx = proxy->mapToSource(idx);
77+
}
78+
79+
// Now fetch LevelPtr from the source model, not the proxy (if available)
80+
QVariant varLvl;
81+
/*
82+
if (sourceIdx.isValid()) {
83+
// If we have proxy, get sourceModel, else fallback to model()
84+
if (auto proxy = qobject_cast<QAbstractProxyModel *>(model())) {
85+
varLvl = proxy->sourceModel()->data(sourceIdx, LevelModel::RoleLevel);
86+
} else {
87+
varLvl = model()->data(sourceIdx, LevelModel::RoleLevel);
88+
}
89+
} else {
90+
varLvl = model()->data(idx, LevelModel::RoleLevel);
91+
}
92+
auto lvl = varLvl.value<LevelPtr>();
93+
if (lvl) {
94+
// do update, e.g. preload something
95+
lvl->requestThumb();
96+
}
97+
*/
98+
}
99+
}
100+
101+
// The Model
19102
void LevelListModel::setLevels(
20103
const QVector<QSharedPointer<ListItemData>>& levels) {
21104
beginResetModel();
@@ -50,13 +133,15 @@ inline quint64 LevelListModel::indexInBounds(const quint64 index) const {
50133
return qMin(index, quint64(m_levels.size()));
51134
}
52135

53-
void LevelListModel::setScrollChange(const quint64 index) {
136+
void LevelListModel::setScrollChange() {
54137
if (!m_levels.empty()) {
55138
m_scrollCursorChanged = true;
56-
m_scroll_cursor_a = indexInBounds(index);;
57139
}
58140
}
59141

142+
void LevelListModel::addScrollItem(const quint64 index) {
143+
}
144+
60145
QVector<QSharedPointer<ListItemData>>
61146
LevelListModel::getChunk(const quint64 cursor, const quint64 items) {
62147
const quint64 len = indexInBounds(cursor + items) - cursor;
@@ -66,10 +151,9 @@ QVector<QSharedPointer<ListItemData>>
66151
QVector<QSharedPointer<ListItemData>>
67152
LevelListModel::getDataBuffer(quint64 items) {
68153
QVector<QSharedPointer<ListItemData>> chunk;
69-
if ((items > 0) && !m_levels.isEmpty()) {
154+
if (!m_levels.isEmpty()) {
70155
if (m_scrollCursorChanged == true) {
71-
m_scroll_cursor_b = indexInBounds(m_scroll_cursor_a + items);
72-
chunk = getChunk(m_scroll_cursor_a, items);
156+
// chunk = m_scrollBuffer;
73157
} else {
74158
m_cursor_b = indexInBounds(m_cursor_a + items);
75159
chunk = getChunk(m_cursor_a, items);
@@ -91,8 +175,9 @@ void LevelListModel::updateCovers(quint64 a, quint64 b) {
91175

92176
void LevelListModel::reset() {
93177
if (m_scrollCursorChanged == true) {
94-
updateCovers(m_scroll_cursor_a, m_scroll_cursor_b);
95-
m_scroll_cursor_a = m_scroll_cursor_b;
178+
QModelIndex index_b(index(0, 0));
179+
// updateCovers(m_scrollBuffer);
180+
// m_scrollBuffer.clear();
96181
m_scrollCursorChanged = false;
97182
} else {
98183
updateCovers(m_cursor_a, m_cursor_b);
@@ -168,9 +253,15 @@ void LevelListProxy::setInstalledFilter(bool on) {
168253
}
169254

170255
void LevelListProxy::setSortMode(SortMode mode) {
171-
m_sortMode = mode;
256+
Qt::SortOrder order;
257+
if (m_sortMode == mode){
258+
order = Qt::AscendingOrder;
259+
} else {
260+
m_sortMode = mode;
261+
order = Qt::DescendingOrder;
262+
}
172263
invalidate();
173-
this->sort(0, Qt::DescendingOrder);
264+
this->sort(0, order);
174265
}
175266

176267
bool LevelListProxy::lessThan(const QModelIndex &left,
@@ -182,7 +273,7 @@ bool LevelListProxy::lessThan(const QModelIndex &left,
182273
bool less = false;
183274
switch (m_sortMode) {
184275
case Title:
185-
less = l.toString().localeAwareCompare(r.toString()) < 0;
276+
less = l.toString().localeAwareCompare(r.toString().toUpper()) < 0;
186277
break;
187278
case ReleaseDate:
188279
less = l.toDateTime() < r.toDateTime();

src/LevelViewList.hpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@
2222

2323
#include "../src/Data.hpp"
2424

25+
class LevelViewList : public QListView {
26+
Q_OBJECT
27+
28+
public:
29+
explicit LevelViewList(QWidget *parent = nullptr);
30+
31+
QModelIndexList visibleIndexes() const;
32+
33+
protected:
34+
void scrollContentsBy(int dx, int dy) override;
35+
void resizeEvent(QResizeEvent *event) override;
36+
void paintEvent(QPaintEvent *event) override;
37+
38+
private:
39+
void updateVisibleItems();
40+
};
41+
2542

2643
class LevelListModel : public QAbstractListModel {
2744
Q_OBJECT
@@ -30,8 +47,6 @@ class LevelListModel : public QAbstractListModel {
3047
explicit LevelListModel(QObject *parent = nullptr)
3148
: QAbstractListModel(parent),
3249
m_scrollCursorChanged(false),
33-
m_scroll_cursor_a(0),
34-
m_scroll_cursor_b(0),
3550
m_cursor_a(0),
3651
m_cursor_b(0),
3752
m_roleTable({
@@ -54,7 +69,8 @@ class LevelListModel : public QAbstractListModel {
5469
const quint64 items);
5570
QVector<QSharedPointer<ListItemData>> getDataBuffer(const quint64 items);
5671
void setLevels(const QVector<QSharedPointer<ListItemData>>& levels);
57-
void setScrollChange(const quint64 index);
72+
void setScrollChange();
73+
void addScrollItem(const quint64 index);
5874
void setInstalled(const QModelIndex &index);
5975
quint64 indexInBounds(quint64 index) const;
6076
bool stop() const;
@@ -67,8 +83,6 @@ class LevelListModel : public QAbstractListModel {
6783
const QHash<int, std::function<QVariant(const ListItemData&)>> m_roleTable;
6884
QVector<QSharedPointer<ListItemData>> m_levels;
6985
bool m_scrollCursorChanged;
70-
quint64 m_scroll_cursor_a;
71-
quint64 m_scroll_cursor_b;
7286
quint64 m_cursor_a;
7387
quint64 m_cursor_b;
7488
};

src/TombRaiderLinuxLauncher.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
137137
this,
138138
&TombRaiderLinuxLauncher::onCurrentItemChanged);
139139

140-
connect(
141-
ui->listViewLevels->verticalScrollBar(),
142-
&QScrollBar::valueChanged,
143-
this,
144-
&TombRaiderLinuxLauncher::levelListScrolled);
145140

146141
connect(ui->checkBoxInstalled, &QCheckBox::toggled,
147142
levelListProxy, &LevelListProxy::setInstalledFilter);
@@ -241,36 +236,25 @@ InstalledStatus TombRaiderLinuxLauncher::getInstalled() {
241236
return list;
242237
}
243238

244-
bool TombRaiderLinuxLauncher::setStartupSetting(const StartupSetting settings) {
245-
bool status = false;
239+
void TombRaiderLinuxLauncher::setStartupSetting(const StartupSetting settings) {
246240
if (settings.installed == true) {
247241
ui->checkBoxInstalled->setChecked(true);
248-
status = true;
249242
}
250243
if (settings.original == true) {
251244
ui->checkBoxOriginal->setChecked(true);
252-
status = true;
253245
}
254246
if (settings.type_id != 0) {
255247
ui->comboBoxType->setCurrentIndex(settings.type_id);
256-
status = true;
257248
}
258249
if (settings.class_id != 0) {
259250
ui->comboBoxClass->setCurrentIndex(settings.class_id);
260-
status = true;
261251
}
262252
if (settings.difficulty_id != 0) {
263253
ui->comboBoxDifficulty->setCurrentIndex(settings.difficulty_id);
264-
status = true;
265254
}
266255
if (settings.duration_id != 0) {
267256
ui->comboBoxDuration->setCurrentIndex(settings.duration_id);
268-
status = true;
269-
}
270-
if (status == true) {
271-
levelListModel->setScrollChange(0);
272257
}
273-
return status;
274258
}
275259

276260
void TombRaiderLinuxLauncher::sortByTitle() {
@@ -641,6 +625,7 @@ void TombRaiderLinuxLauncher::loadMoreCovers() {
641625
}
642626
}
643627

628+
/*
644629
void TombRaiderLinuxLauncher::levelListScrolled(int value) {
645630
QModelIndex idx = ui->listViewLevels->model()->index(0, 0);
646631
QRect rect = ui->listViewLevels->visualRect(idx);
@@ -655,8 +640,9 @@ void TombRaiderLinuxLauncher::levelListScrolled(int value) {
655640
656641
// qDebug() << "Scroll position at item:" << pos;
657642
658-
levelListModel->setScrollChange(pos);
643+
//levelListModel->setScrollChange(pos);
659644
}
645+
*/
660646

661647
void TombRaiderLinuxLauncher::workTick() {
662648
int value = ui->progressBar->value();

0 commit comments

Comments
 (0)