Debian Codegraph @

Source/Core/DolphinQt/GameList/GameListModel.h

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