1 // Copyright 2015 Dolphin Emulator Project 2 // Licensed under GPLv2+ 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include <memory> 8 #include <string> 9 10 #include <QAbstractTableModel> 11 #include <QMap> 12 #include <QString> 13 #include <QStringList> 14 #include <QVariant> 15 16 #include "Core/TitleDatabase.h" 17 18 #include "DolphinQt/GameList/GameTracker.h" 19 20 namespace UICommon 21 { 22 class GameFile; 23 } 24 25 class GameListModel final : public QAbstractTableModel 26 { 27 Q_OBJECT 28 29 public: 30 explicit GameListModel(QObject* parent = nullptr); 31 32 // Qt's Model/View stuff uses these overrides. 33 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 34 QVariant headerData(int section, Qt::Orientation orientation, 35 int role = Qt::DisplayRole) const override; 36 int rowCount(const QModelIndex& parent) const override; 37 int columnCount(const QModelIndex& parent) const override; 38 39 std::shared_ptr<const UICommon::GameFile> GetGameFile(int index) const; 40 std::string GetNetPlayName(const UICommon::GameFile& game) const; 41 bool ShouldDisplayGameListItem(int index) const; 42 void SetSearchTerm(const QString& term); 43 44 // Using a custom sort role as it sometimes differs slightly from the default Qt::DisplayRole. 45 static constexpr int SORT_ROLE = Qt::UserRole; 46 47 enum 48 { 49 COL_PLATFORM = 0, 50 COL_BANNER, 51 COL_TITLE, 52 COL_DESCRIPTION, 53 COL_MAKER, 54 COL_ID, 55 COL_COUNTRY, 56 COL_SIZE, 57 COL_FILE_NAME, 58 COL_FILE_PATH, 59 COL_FILE_FORMAT, 60 COL_BLOCK_SIZE, 61 COL_COMPRESSION, 62 COL_TAGS, 63 NUM_COLS 64 }; 65 66 void AddGame(const std::shared_ptr<const UICommon::GameFile>& game); 67 void UpdateGame(const std::shared_ptr<const UICommon::GameFile>& game); 68 void RemoveGame(const std::string& path); 69 70 std::shared_ptr<const UICommon::GameFile> FindGame(const std::string& path) const; 71 std::shared_ptr<const UICommon::GameFile> FindSecondDisc(const UICommon::GameFile& game) const; 72 73 void SetScale(float scale); 74 float GetScale() const; 75 76 const QStringList& GetAllTags() const; 77 const QStringList GetGameTags(const std::string& path) const; 78 79 void AddGameTag(const std::string& path, const QString& name); 80 void RemoveGameTag(const std::string& path, const QString& name); 81 82 void NewTag(const QString& name); 83 void DeleteTag(const QString& name); 84 85 void PurgeCache(); 86 87 private: 88 // Index in m_games, or -1 if it isn't found 89 int FindGameIndex(const std::string& path) const; 90 91 QStringList m_tag_list; 92 QMap<QString, QVariant> m_game_tags; 93 94 GameTracker m_tracker; 95 QList<std::shared_ptr<const UICommon::GameFile>> m_games; 96 Core::TitleDatabase m_title_database; 97 QString m_term; 98 float m_scale = 1.0; 99 }; 100