QVariant GameListModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); const UICommon::GameFile& game = *m_games[index.row()]; switch (index.column()) { case COL_PLATFORM: if (role == Qt::DecorationRole) return Resources::GetPlatform(static_cast<int>(game.GetPlatform())); if (role == Qt::InitialSortOrderRole) return static_cast<int>(game.GetPlatform()); break; case COL_COUNTRY: if (role == Qt::DecorationRole) return Resources::GetCountry(static_cast<int>(game.GetCountry())); if (role == Qt::InitialSortOrderRole) return static_cast<int>(game.GetCountry()); break; case COL_BANNER: if (role == Qt::DecorationRole) { // GameCube banners are 96x32, but Wii banners are 192x64. QPixmap banner = ToQPixmap(game.GetBannerImage()); if (banner.isNull()) banner = Resources::GetMisc(Resources::BANNER_MISSING); banner.setDevicePixelRatio( std::max(static_cast<qreal>(banner.width()) / GAMECUBE_BANNER_SIZE.width(), static_cast<qreal>(banner.height()) / GAMECUBE_BANNER_SIZE.height())); return banner; } break; case COL_TITLE: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return QString::fromStdString(game.GetName()); break; case COL_ID: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return QString::fromStdString(game.GetGameID()); break; case COL_DESCRIPTION: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return QString::fromStdString(game.GetDescription()); break; case COL_MAKER: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return QString::fromStdString(game.GetMaker()); break; case COL_FILE_NAME: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return QString::fromStdString(game.GetFileName()); break; case COL_SIZE: if (role == Qt::DisplayRole) return QString::fromStdString(UICommon::FormatSize(game.GetFileSize())); if (role == Qt::InitialSortOrderRole) return static_cast<quint64>(game.GetFileSize()); break; } return QVariant(); }
QVariant GameListModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); const UICommon::GameFile& game = *m_games[index.row()]; switch (index.column()) { case COL_PLATFORM: if (role == Qt::DecorationRole) return Resources::GetPlatform(game.GetPlatform()); if (role == Qt::InitialSortOrderRole) return static_cast<int>(game.GetPlatform()); break; case COL_COUNTRY: if (role == Qt::DecorationRole) return Resources::GetCountry(game.GetCountry()); if (role == Qt::InitialSortOrderRole) return static_cast<int>(game.GetCountry()); break; case COL_BANNER: if (role == Qt::DecorationRole) { // GameCube banners are 96x32, but Wii banners are 192x64. QPixmap banner = ToQPixmap(game.GetBannerImage()); if (banner.isNull()) banner = Resources::GetMisc(Resources::MiscID::BannerMissing); banner.setDevicePixelRatio( std::max(static_cast<qreal>(banner.width()) / GAMECUBE_BANNER_SIZE.width(), static_cast<qreal>(banner.height()) / GAMECUBE_BANNER_SIZE.height())); return banner; } break; case COL_TITLE: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) { QString name = QString::fromStdString(game.GetName(m_title_database)); const int disc_nr = game.GetDiscNumber() + 1; if (disc_nr > 1) { if (!name.contains(QRegExp(QStringLiteral("disc ?%1").arg(disc_nr), Qt::CaseInsensitive))) { name.append(tr(" (Disc %1)").arg(disc_nr)); } } return name; } break; case COL_ID: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return QString::fromStdString(game.GetGameID()); break; case COL_DESCRIPTION: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return QString::fromStdString(game.GetDescription()); break; case COL_MAKER: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return QString::fromStdString(game.GetMaker()); break; case COL_FILE_NAME: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return QString::fromStdString(game.GetFileName()); break; case COL_SIZE: if (role == Qt::DisplayRole) return QString::fromStdString(UICommon::FormatSize(game.GetFileSize())); if (role == Qt::InitialSortOrderRole) return static_cast<quint64>(game.GetFileSize()); break; case COL_TAGS: if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) { auto tags = GetGameTags(game.GetFilePath()); tags.sort(); return tags.join(QStringLiteral(", ")); } } return QVariant(); }