Skip to content

Commit 194352a

Browse files
committed
GameList: Address review feedback - remove favorite column, show star in title columns
1 parent e929a55 commit 194352a

4 files changed

Lines changed: 27 additions & 26 deletions

File tree

pcsx2-qt/GameList/GameListModel.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <QtGui/QPainter>
1919

2020
static constexpr std::array<const char*, GameListModel::Column_Count> s_column_names = {
21-
{"Type", "Code", "Favorite", "Title", "File Title", "CRC", "Time Played", "Last Played", "Size", "Region", "Compatibility", "Cover"}};
21+
{"Type", "Code", "Title", "File Title", "CRC", "Time Played", "Last Played", "Size", "Region", "Compatibility", "Cover"}};
2222

2323
static constexpr int COVER_ART_WIDTH = 350;
2424
static constexpr int COVER_ART_HEIGHT = 512;
@@ -282,6 +282,11 @@ QVariant GameListModel::data(const QModelIndex& index, const int role) const
282282
{
283283
switch (index.column())
284284
{
285+
case Column_Title:
286+
case Column_FileTitle:
287+
if (ge->is_favorite)
288+
return m_favorite_pixmap;
289+
return QVariant();
285290
case Column_Type:
286291
return m_type_pixmaps[static_cast<u32>(ge->type)];
287292

@@ -305,11 +310,6 @@ QVariant GameListModel::data(const QModelIndex& index, const int role) const
305310
return *m_cover_pixmap_cache.Insert(ge->path, m_loading_pixmap);
306311
}
307312

308-
case Column_Favorite:
309-
if (ge->is_favorite)
310-
return m_favorite_pixmap;
311-
return QVariant();
312-
313313
default:
314314
return QVariant();
315315
}
@@ -411,8 +411,6 @@ bool GameListModel::lessThan(const QModelIndex& left_index, const QModelIndex& r
411411
}
412412

413413
// Favorite sort is always enabled
414-
case Column_Favorite:
415-
[[fallthrough]];
416414
case Column_Title:
417415
return titlesLessThan(left_row, right_row);
418416

@@ -538,7 +536,6 @@ void GameListModel::setColumnDisplayNames()
538536
m_column_display_names[Column_Size] = tr("Size");
539537
m_column_display_names[Column_Region] = tr("Region");
540538
m_column_display_names[Column_Compatibility] = tr("Compatibility");
541-
m_column_display_names[Column_Favorite] = tr("Favorite");
542539
}
543540

544541
#include "moc_GameListModel.cpp"

pcsx2-qt/GameList/GameListModel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class GameListModel final : public QAbstractTableModel
2424
{
2525
Column_Type,
2626
Column_Serial,
27-
Column_Favorite,
2827
Column_Title,
2928
Column_FileTitle,
3029
Column_CRC,

pcsx2-qt/GameList/GameListWidget.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static constexpr Qt::SortOrder DEFAULT_SORT_ORDER = Qt::AscendingOrder;
5252
static constexpr std::array<int, GameListModel::Column_Count> DEFAULT_COLUMN_WIDTHS = {{
5353
55, // type
5454
85, // code
55-
55, // favorite
5655
-1, // title
5756
-1, // file title
5857
75, // crc
@@ -119,6 +118,15 @@ class GameListSortModel final : public QSortFilterProxyModel
119118

120119
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override
121120
{
121+
const auto lock = GameList::GetLock();
122+
const GameList::Entry* left = GameList::GetEntryByIndex(source_left.row());
123+
const GameList::Entry* right = GameList::GetEntryByIndex(source_right.row());
124+
125+
// Favorites always sort to the top regardless of column or sort direction.
126+
127+
if (left && right && left->is_favorite != right->is_favorite)
128+
return sortOrder() == Qt::AscendingOrder ? left->is_favorite : right->is_favorite;
129+
122130
return m_model->lessThan(source_left, source_right, source_left.column());
123131
}
124132

@@ -135,12 +143,10 @@ namespace
135143
class GameListIconStyleDelegate final : public QStyledItemDelegate
136144
{
137145
public:
138-
static constexpr int STAR_SIZE = 22;
139146
static constexpr int STAR_MARGIN = 4;
140147

141-
GameListIconStyleDelegate(QWidget* parent, const GameListModel* model)
148+
GameListIconStyleDelegate(QWidget* parent)
142149
: QStyledItemDelegate(parent)
143-
, m_model(model)
144150
{
145151
}
146152
~GameListIconStyleDelegate() = default;
@@ -207,7 +213,9 @@ namespace
207213
index.data(GameListModel::NeedsFavoriteBadgeRole).toBool();
208214
if (is_favorite)
209215
{
210-
const QPixmap& star = m_model->getFavoritePixmap();
216+
const auto* sort_model = static_cast<const QSortFilterProxyModel*>(index.model());
217+
const auto* game_model = static_cast<const GameListModel*>(sort_model->sourceModel());
218+
const QPixmap& star = game_model->getFavoritePixmap();
211219
const QPoint icon_bottom_right = icon_top_left + QPoint(icon_width, icon_height);
212220
const QSizeF size = star.deviceIndependentSize();
213221
const QPoint star_pos = icon_bottom_right - QPoint(size.width() + STAR_MARGIN, size.height() + STAR_MARGIN);
@@ -219,7 +227,6 @@ namespace
219227
}
220228

221229
private:
222-
const GameListModel* m_model;
223230
};
224231
} // namespace
225232

@@ -293,10 +300,9 @@ void GameListWidget::initialize()
293300
m_table_view->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel);
294301

295302
// Custom painter to center-align DisplayRoles (icons)
296-
m_table_view->setItemDelegateForColumn(static_cast<int>(GameListModel::Column_Type), new GameListIconStyleDelegate(this, m_model));
297-
m_table_view->setItemDelegateForColumn(static_cast<int>(GameListModel::Column_Region), new GameListIconStyleDelegate(this, m_model));
298-
m_table_view->setItemDelegateForColumn(static_cast<int>(GameListModel::Column_Compatibility), new GameListIconStyleDelegate(this, m_model));
299-
m_table_view->setItemDelegateForColumn(static_cast<int>(GameListModel::Column_Favorite), new GameListIconStyleDelegate(this, m_model));
303+
m_table_view->setItemDelegateForColumn(static_cast<int>(GameListModel::Column_Type), new GameListIconStyleDelegate(this));
304+
m_table_view->setItemDelegateForColumn(static_cast<int>(GameListModel::Column_Region), new GameListIconStyleDelegate(this));
305+
m_table_view->setItemDelegateForColumn(static_cast<int>(GameListModel::Column_Compatibility), new GameListIconStyleDelegate(this));
300306

301307
connect(m_table_view->selectionModel(), &QItemSelectionModel::currentChanged, this,
302308
&GameListWidget::onSelectionModelCurrentChanged);
@@ -340,7 +346,7 @@ void GameListWidget::initialize()
340346
m_list_view = new GameListGridListView(m_ui.stack);
341347
m_list_view->setModel(m_sort_model);
342348
m_list_view->setModelColumn(GameListModel::Column_Cover);
343-
m_list_view->setItemDelegate(new GameListIconStyleDelegate(this, m_model));
349+
m_list_view->setItemDelegate(new GameListIconStyleDelegate(this));
344350
m_list_view->setSelectionMode(QAbstractItemView::SingleSelection);
345351
m_list_view->setViewMode(QListView::IconMode);
346352
m_list_view->setResizeMode(QListView::Adjust);
@@ -810,7 +816,6 @@ void GameListWidget::resizeTableViewColumnsToFit()
810816
QtUtils::ResizeColumnsForTableView(m_table_view, {
811817
DEFAULT_COLUMN_WIDTHS[GameListModel::Column_Type],
812818
DEFAULT_COLUMN_WIDTHS[GameListModel::Column_Serial],
813-
DEFAULT_COLUMN_WIDTHS[GameListModel::Column_Favorite],
814819
DEFAULT_COLUMN_WIDTHS[GameListModel::Column_Title],
815820
DEFAULT_COLUMN_WIDTHS[GameListModel::Column_FileTitle],
816821
DEFAULT_COLUMN_WIDTHS[GameListModel::Column_CRC],

pcsx2/GameList.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ bool GameList::AddFileFromCache(const std::string& path, std::time_t timestamp,
746746
entry.total_played_time = iter->second.total_played_time;
747747
}
748748

749-
entry.is_favorite = custom_attributes_ini.GetBoolValue(entry.path.c_str(), "Favorite", false);
749+
entry.is_favorite = custom_attributes_ini.GetBoolValue(entry.path.c_str(), "Favorited", false);
750750
s_entries.push_back(std::move(entry));
751751
return true;
752752
}
@@ -785,7 +785,7 @@ bool GameList::ScanFile(std::string path, std::time_t timestamp, std::unique_loc
785785
entry.total_played_time = iter->second.total_played_time;
786786
}
787787

788-
entry.is_favorite = custom_attributes_ini.GetBoolValue(entry.path.c_str(), "Favorite", false);
788+
entry.is_favorite = custom_attributes_ini.GetBoolValue(entry.path.c_str(), "Favorited", false);
789789

790790
auto custom_title = custom_attributes_ini.GetOptionalStringValue(entry.path.c_str(), "Title");
791791
if (custom_title)
@@ -1479,11 +1479,11 @@ void GameList::SetGameFavorite(const std::string& path, bool favorite)
14791479

14801480
if (favorite)
14811481
{
1482-
custom_attributes.SetBoolValue(path.c_str(), "Favorite", true);
1482+
custom_attributes.SetBoolValue(path.c_str(), "Favorited", true);
14831483
}
14841484
else
14851485
{
1486-
custom_attributes.DeleteValue(path.c_str(), "Favorite");
1486+
custom_attributes.DeleteValue(path.c_str(), "Favorited");
14871487
}
14881488

14891489
if (custom_attributes.Save())

0 commit comments

Comments
 (0)