Skip to content

Commit 54ab2ed

Browse files
committed
add basic search
1 parent 0a7c614 commit 54ab2ed

File tree

3 files changed

+68
-31
lines changed

3 files changed

+68
-31
lines changed

src/TombRaiderLinuxLauncher.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
121121
connect(ui->comboBoxDuration, &QComboBox::currentTextChanged,
122122
this, &TombRaiderLinuxLauncher::filterByDuration);
123123

124-
model = new LevelListModel(this);
125-
ui->listViewLevels->setModel(model);
124+
levelListModel = new LevelListModel(this);
125+
ui->listViewLevels->setModel(levelListModel);
126126
CardItemDelegate* delegate = new CardItemDelegate(ui->listViewLevels);
127127
ui->listViewLevels->setItemDelegate(delegate);
128128
ui->listViewLevels->setSpacing(8);
@@ -132,6 +132,13 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
132132
this,
133133
&TombRaiderLinuxLauncher::onCurrentItemChanged);
134134

135+
136+
connect(ui->commandLinkButton, &QCommandLinkButton::clicked, this, [=]() {
137+
QString searchText = ui->lineEditSearch->text();
138+
qDebug() << "You searched for:" << searchText;
139+
levelListModel->filterSearch(searchText);
140+
});
141+
135142
// Read settings
136143
QString value = m_settings.value("setup").toString();
137144
if (value != "yes") {
@@ -142,47 +149,47 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
142149
}
143150

144151
void TombRaiderLinuxLauncher::generateList(const QList<int>& availableGames) {
145-
model->setLevels();
152+
levelListModel->setLevels();
146153
}
147154

148155
void TombRaiderLinuxLauncher::sortByTitle() {
149-
model->sortItems(model->compareTitles);
156+
levelListModel->sortItems(levelListModel->compareTitles);
150157
}
151158

152159
void TombRaiderLinuxLauncher::sortByDifficulty() {
153-
model->sortItems(model->compareDifficulties);
160+
levelListModel->sortItems(levelListModel->compareDifficulties);
154161
}
155162

156163
void TombRaiderLinuxLauncher::sortByDuration() {
157-
model->sortItems(model->compareDurations);
164+
levelListModel->sortItems(levelListModel->compareDurations);
158165
}
159166

160167
void TombRaiderLinuxLauncher::sortByClass() {
161-
model->sortItems(model->compareClasses);
168+
levelListModel->sortItems(levelListModel->compareClasses);
162169
}
163170

164171
void TombRaiderLinuxLauncher::sortByType() {
165-
model->sortItems(model->compareTypes);
172+
levelListModel->sortItems(levelListModel->compareTypes);
166173
}
167174

168175
void TombRaiderLinuxLauncher::sortByReleaseDate() {
169-
model->sortItems(model->compareReleaseDates);
176+
levelListModel->sortItems(levelListModel->compareReleaseDates);
170177
}
171178

172179
void TombRaiderLinuxLauncher::filterByClass(const QString& class_) {
173-
model->filterClass(class_);
180+
levelListModel->filterClass(class_);
174181
}
175182

176183
void TombRaiderLinuxLauncher::filterByType(const QString& type) {
177-
model->filterType(type);
184+
levelListModel->filterType(type);
178185
}
179186

180187
void TombRaiderLinuxLauncher::filterByDifficulty(const QString& difficulty) {
181-
model->filterDifficulty(difficulty);
188+
levelListModel->filterDifficulty(difficulty);
182189
}
183190

184191
void TombRaiderLinuxLauncher::filterByDuration(const QString& duration) {
185-
model->filterDuration(duration);
192+
levelListModel->filterDuration(duration);
186193
}
187194

188195
void TombRaiderLinuxLauncher::readSavedSettings() {
@@ -263,7 +270,7 @@ void TombRaiderLinuxLauncher::levelDirSelected(qint64 id) {
263270
void TombRaiderLinuxLauncher::onCurrentItemChanged(
264271
const QModelIndex &current, const QModelIndex &previous) {
265272
if (current.isValid()) {
266-
qint64 id = model->getLid(current);
273+
qint64 id = levelListModel->getLid(current);
267274
if (id < 0) { // its the original game
268275
originalSelected(id);
269276
} else {
@@ -311,7 +318,7 @@ void TombRaiderLinuxLauncher::setOptionsClicked() {
311318
void TombRaiderLinuxLauncher::linkClicked() {
312319
QModelIndex current = ui->listViewLevels->currentIndex();
313320
if (current.isValid()) {
314-
qint64 id = model->getLid(current);
321+
qint64 id = levelListModel->getLid(current);
315322
if (id != 0) {
316323
if (m_settings.value(QString("level%1/RunnerType").arg(id)) == 2) {
317324
Model::getInstance().runWine(id);
@@ -328,7 +335,7 @@ void TombRaiderLinuxLauncher::linkClicked() {
328335
void TombRaiderLinuxLauncher::downloadClicked() {
329336
QModelIndex current = ui->listViewLevels->currentIndex();
330337
if (current.isValid()) {
331-
qint64 id = model->getLid(current);
338+
qint64 id = levelListModel->getLid(current);
332339
if (id < 0) {
333340
ui->listViewLevels->setEnabled(false);
334341
ui->progressBar->setValue(0);
@@ -349,7 +356,7 @@ void TombRaiderLinuxLauncher::downloadClicked() {
349356
void TombRaiderLinuxLauncher::infoClicked() {
350357
QModelIndex current = ui->listViewLevels->currentIndex();
351358
if (current.isValid()) {
352-
qint64 id = model->getLid(current);
359+
qint64 id = levelListModel->getLid(current);
353360
if (id != 0) {
354361
InfoData info = controller.getInfo(id);
355362
ui->infoWebEngineView->setHtml(info.m_body);
@@ -395,7 +402,7 @@ void TombRaiderLinuxLauncher::infoClicked() {
395402
void TombRaiderLinuxLauncher::walkthroughClicked() {
396403
QModelIndex current = ui->listViewLevels->currentIndex();
397404
if (current.isValid()) {
398-
qint64 id = model->getLid(current);
405+
qint64 id = levelListModel->getLid(current);
399406
if (id != 0) {
400407
QWebEngineView* w = ui->walkthroughWebEngineView;
401408
w->setHtml(controller.getWalkthrough(id));
@@ -421,7 +428,7 @@ void TombRaiderLinuxLauncher::backClicked() {
421428
}
422429

423430
void TombRaiderLinuxLauncher::loadMoreCovers() {
424-
model->loadMoreCovers();
431+
levelListModel->loadMoreCovers();
425432
}
426433

427434
void TombRaiderLinuxLauncher::workTick() {
@@ -431,7 +438,7 @@ void TombRaiderLinuxLauncher::workTick() {
431438
if (ui->progressBar->value() >= 100) {
432439
QModelIndex current = ui->listViewLevels->currentIndex();
433440
if (current.isValid()) {
434-
qint64 id = model->getLid(current);
441+
qint64 id = levelListModel->getLid(current);
435442
if (id < 0) { // its the original game
436443
ui->pushButtonLink->setEnabled(true);
437444
ui->pushButtonInfo->setEnabled(false);
@@ -494,7 +501,7 @@ void TombRaiderLinuxLauncher::GlobalResetClicked() {
494501
void TombRaiderLinuxLauncher::LevelSaveClicked() {
495502
QModelIndex current = ui->listViewLevels->currentIndex();
496503
if (current.isValid()) {
497-
qint64 id = model->getLid(current);
504+
qint64 id = levelListModel->getLid(current);
498505

499506
m_settings.setValue(QString("level%1/CustomCommand")
500507
.arg(id), ui->lineEditCustomCommand->text());

src/TombRaiderLinuxLauncher.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class TombRaiderLinuxLauncher : public QMainWindow {
162162

163163
QSet<QListWidgetItem*> originalGamesSet_m;
164164
QList<QListWidgetItem*> originalGamesList_m;
165-
LevelListModel *model;
165+
LevelListModel *levelListModel;
166166
Controller& controller = Controller::getInstance();
167167
QSettings m_settings;
168168
Ui::TombRaiderLinuxLauncher *ui;

src/levelViewList.hpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class LevelListModel : public QAbstractListModel {
4242
getMoreCovers();
4343
}
4444

45-
int rowCount(const QModelIndex &parent = QModelIndex()) const override {
46-
Q_UNUSED(parent);
45+
int rowCount(const QModelIndex&) const override {
4746
return m_filterList.count();
4847
}
4948

@@ -195,6 +194,18 @@ class LevelListModel : public QAbstractListModel {
195194
reFilter();
196195
}
197196

197+
void filterSearch(const QString& search) {
198+
qDebug() << "filterSearch " << search;
199+
if (search == "") {
200+
m_search.clear();
201+
qDebug() << "reset search";
202+
} else {
203+
m_search.clear();
204+
m_search = search;
205+
}
206+
reFilter();
207+
}
208+
198209
void reFilter() {
199210
qDebug() << "reFilter";
200211
beginResetModel();
@@ -231,6 +242,15 @@ class LevelListModel : public QAbstractListModel {
231242
keep = false;
232243
}
233244

245+
if (!m_search.isEmpty()) {
246+
QRegularExpression regex(
247+
QRegularExpression::escape(m_search),
248+
QRegularExpression::CaseInsensitiveOption);
249+
if (!regex.match(item->m_title).hasMatch()) {
250+
keep = false;
251+
}
252+
}
253+
234254
if (keep)
235255
m_filterList.append(item);
236256
}
@@ -321,13 +341,23 @@ class CardItemDelegate : public QStyledItemDelegate {
321341
normalFont.setPointSizeF(option.font.pointSizeF() - 1);
322342
painter->setFont(normalFont);
323343

324-
painter->drawText(QPoint(textX, textY + 35), "By: " + authors);
325-
painter->drawText(QPoint(textX, textY + 50), "Type: " + type);
326-
painter->drawText(QPoint(textX, textY + 65), "Released: " + release);
327-
painter->drawText(QPoint(textX, textY + 80), "class: " + class_);
328-
painter->drawText(QPoint(textX, textY + 95), "Duration: " + duration);
329-
painter->drawText(
330-
QPoint(textX, textY + 110), "Difficulty: " + difficulty);
344+
QString authorsText = QString("By: %1").arg(authors);
345+
painter->drawText(QPoint(textX, textY + 35), authorsText);
346+
347+
QString typeText = QString("Type: %1").arg(type);
348+
painter->drawText(QPoint(textX, textY + 50), typeText);
349+
350+
QString releaseText = QString("Released: %1").arg(release);
351+
painter->drawText(QPoint(textX, textY + 65), releaseText);
352+
353+
QString classText = QString("class: %1").arg(class_);
354+
painter->drawText(QPoint(textX, textY + 80), classText);
355+
356+
QString durationText = QString("Duration: %1").arg(duration);
357+
painter->drawText(QPoint(textX, textY + 95), durationText);
358+
359+
QString difficultyText = QString("Difficulty: %1").arg(difficulty);
360+
painter->drawText(QPoint(textX, textY + 110), difficultyText);
331361

332362
painter->restore();
333363
}

0 commit comments

Comments
 (0)