mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-25 02:43:02 -07:00
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, SearchLanguageMode 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;
|
|
SearchLanguageMode searchLanguageMode = SearchLanguageMode::English;
|
|
};
|
|
|
|
#endif // CARD_SEARCH_MODEL_H
|