mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-24 02:13:02 -07:00
Localized card names and texts can now be searched too, controlled by a 'Language used in card search' toggle (English, selected card language, or both) on the general settings page. Untranslated cards always keep matching in English. Removed the redundant local copy of the URL templates list in the localized picture loader while here.
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
/**
|
|
* @file card_search_model.h
|
|
* @ingroup CardDatabaseModels
|
|
*/
|
|
//! \todo Document this file.
|
|
|
|
#ifndef CARD_SEARCH_MODEL_H
|
|
#define CARD_SEARCH_MODEL_H
|
|
|
|
#include "../card_database_display_model.h"
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
class CardSearchModel : public QAbstractListModel
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
enum CardSearchRoles
|
|
{
|
|
CardInfoRole = Qt::UserRole + 1,
|
|
};
|
|
|
|
explicit CardSearchModel(CardDatabaseDisplayModel *sourceModel, QObject *parent = nullptr);
|
|
|
|
[[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
void updateSearchResults(const QString &query); // Update results based on input
|
|
|
|
void setSearchLanguage(const QString &searchLang, CardSearchLanguage mode)
|
|
{
|
|
if (searchLanguage == searchLang && searchLanguageMode == mode) {
|
|
return;
|
|
}
|
|
searchLanguage = searchLang;
|
|
searchLanguageMode = mode;
|
|
}
|
|
|
|
private:
|
|
struct SearchResult
|
|
{
|
|
CardInfoPtr card;
|
|
int distance;
|
|
};
|
|
|
|
CardDatabaseDisplayModel *sourceModel;
|
|
QList<SearchResult> searchResults;
|
|
QString searchLanguage;
|
|
CardSearchLanguage searchLanguageMode = CardSearchLanguage::English;
|
|
};
|
|
|
|
#endif // CARD_SEARCH_MODEL_H
|