some work on the new game list viewer

This commit is contained in:
georgemoralis 2023-03-07 19:04:34 +02:00
parent 9ba1ad6c93
commit 380fb710b7
4 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,17 @@
#pragma once
#include <string>
struct GameInfo
{
std::string path; //root path of game directory (normaly directory that contains eboot.bin)
std::string icon_path;//path of icon0.png
//variables extracted from param.sfo
std::string name = "Unknown";
std::string serial = "Unknown";
std::string app_ver = "Unknown";
std::string version = "Unknown";
std::string category = "Unknown";
std::string fw = "Unknown";
};

View File

@ -0,0 +1,70 @@
#include "custom_table_widget_item.h"
#include <QDateTime>
custom_table_widget_item::custom_table_widget_item(const std::string& text, int sort_role, const QVariant& sort_value)
: QTableWidgetItem(QString::fromStdString(text).simplified()) // simplified() forces single line text
{
if (sort_role != Qt::DisplayRole)
{
setData(sort_role, sort_value, true);
}
}
custom_table_widget_item::custom_table_widget_item(const QString& text, int sort_role, const QVariant& sort_value)
: QTableWidgetItem(text.simplified()) // simplified() forces single line text
{
if (sort_role != Qt::DisplayRole)
{
setData(sort_role, sort_value, true);
}
}
bool custom_table_widget_item::operator<(const QTableWidgetItem& other) const
{
if (m_sort_role == Qt::DisplayRole)
{
return QTableWidgetItem::operator<(other);
}
const QVariant data_l = data(m_sort_role);
const QVariant data_r = other.data(m_sort_role);
const QVariant::Type type_l = data_l.type();
const QVariant::Type type_r = data_r.type();
switch (type_l)
{
case QVariant::Type::Bool:
case QVariant::Type::Int:
return data_l.toInt() < data_r.toInt();
case QVariant::Type::UInt:
return data_l.toUInt() < data_r.toUInt();
case QVariant::Type::LongLong:
return data_l.toLongLong() < data_r.toLongLong();
case QVariant::Type::ULongLong:
return data_l.toULongLong() < data_r.toULongLong();
case QVariant::Type::Double:
return data_l.toDouble() < data_r.toDouble();
case QVariant::Type::Date:
return data_l.toDate() < data_r.toDate();
case QVariant::Type::Time:
return data_l.toTime() < data_r.toTime();
case QVariant::Type::DateTime:
return data_l.toDateTime() < data_r.toDateTime();
case QVariant::Type::Char:
case QVariant::Type::String:
return data_l.toString() < data_r.toString();
default:
throw std::runtime_error("unsupported type");
}
}
void custom_table_widget_item::setData(int role, const QVariant& value, bool assign_sort_role)
{
if (assign_sort_role)
{
m_sort_role = role;
}
QTableWidgetItem::setData(role, value);
}

View File

@ -0,0 +1,19 @@
#pragma once
#include <QTableWidgetItem>
class custom_table_widget_item : public QTableWidgetItem
{
private:
int m_sort_role = Qt::DisplayRole;
public:
using QTableWidgetItem::setData;
custom_table_widget_item() = default;
custom_table_widget_item(const std::string& text, int sort_role = Qt::DisplayRole, const QVariant& sort_value = 0);
custom_table_widget_item(const QString& text, int sort_role = Qt::DisplayRole, const QVariant& sort_value = 0);
bool operator<(const QTableWidgetItem& other) const override;
void setData(int role, const QVariant& value, bool assign_sort_role);
};

View File

@ -15,6 +15,7 @@
<ClCompile Include="emulator\fileFormat\PKG.cpp" /> <ClCompile Include="emulator\fileFormat\PKG.cpp" />
<ClCompile Include="emulator\fileFormat\PSF.cpp" /> <ClCompile Include="emulator\fileFormat\PSF.cpp" />
<ClCompile Include="emulator\Loader.cpp" /> <ClCompile Include="emulator\Loader.cpp" />
<ClCompile Include="gui\custom_table_widget_item.cpp" />
<ClCompile Include="gui\GameListViewer.cpp" /> <ClCompile Include="gui\GameListViewer.cpp" />
<ClCompile Include="gui\gui_settings.cpp" /> <ClCompile Include="gui\gui_settings.cpp" />
<ClCompile Include="gui\shadps4gui.cpp" /> <ClCompile Include="gui\shadps4gui.cpp" />
@ -33,7 +34,9 @@
<ClInclude Include="core\FsFile.h" /> <ClInclude Include="core\FsFile.h" />
<ClInclude Include="emulator\fileFormat\PKG.h" /> <ClInclude Include="emulator\fileFormat\PKG.h" />
<ClInclude Include="emulator\fileFormat\PSF.h" /> <ClInclude Include="emulator\fileFormat\PSF.h" />
<ClInclude Include="emulator\gameInfo.h" />
<ClInclude Include="emulator\Loader.h" /> <ClInclude Include="emulator\Loader.h" />
<ClInclude Include="gui\custom_table_widget_item.h" />
<ClInclude Include="gui\gui_settings.h" /> <ClInclude Include="gui\gui_settings.h" />
<ClInclude Include="Types.h" /> <ClInclude Include="Types.h" />
</ItemGroup> </ItemGroup>