Qt: fix gamelist sorting for playtimes

This commit is contained in:
Megamouse 2020-02-03 11:24:36 +01:00
parent c4a01875d0
commit 1759d6d90a
5 changed files with 15 additions and 10 deletions

View file

@ -373,10 +373,8 @@ QString game_list_frame::GetLastPlayedBySerial(const QString& serial)
return m_persistent_settings->GetLastPlayed(serial);
}
QString game_list_frame::GetPlayTimeBySerial(const QString& serial)
QString game_list_frame::GetPlayTimeByMs(int elapsed_ms)
{
const qint64 elapsed_ms = m_persistent_settings->GetPlaytime(serial);
if (elapsed_ms <= 0)
{
return "";
@ -1983,6 +1981,10 @@ int game_list_frame::PopulateGameList()
app_version = tr("%0 (Update available: %1)").arg(app_version, game->compat.version);
}
// Playtimes
const qint64 elapsed_ms = m_persistent_settings->GetPlaytime(serial);
const QString last_played = GetLastPlayedBySerial(serial);
m_gameList->setItem(row, gui::column_icon, icon_item);
m_gameList->setItem(row, gui::column_name, title_item);
m_gameList->setItem(row, gui::column_serial, serial_item);
@ -1994,8 +1996,8 @@ int game_list_frame::PopulateGameList()
m_gameList->setItem(row, gui::column_resolution, new custom_table_widget_item(GetStringFromU32(game->info.resolution, resolution::mode, true)));
m_gameList->setItem(row, gui::column_sound, new custom_table_widget_item(GetStringFromU32(game->info.sound_format, sound::format, true)));
m_gameList->setItem(row, gui::column_parental, new custom_table_widget_item(GetStringFromU32(game->info.parental_lvl, parental::level), Qt::UserRole, game->info.parental_lvl));
m_gameList->setItem(row, gui::column_last_play, new custom_table_widget_item(GetLastPlayedBySerial(serial)));
m_gameList->setItem(row, gui::column_playtime, new custom_table_widget_item(GetPlayTimeBySerial(serial)));
m_gameList->setItem(row, gui::column_last_play, new custom_table_widget_item(last_played, Qt::UserRole, QDate::fromString(last_played, gui::persistent::last_played_date_format)));
m_gameList->setItem(row, gui::column_playtime, new custom_table_widget_item(GetPlayTimeByMs(elapsed_ms), Qt::UserRole, elapsed_ms));
m_gameList->setItem(row, gui::column_compat, compat_item);
if (selected_item == game->info.icon_path)