1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-26 04:32:35 +01:00

Simplify numbered_widget_item

This commit is contained in:
Megamouse 2021-01-12 13:15:14 +01:00
parent 46dc40f3f1
commit dd41ee68de
4 changed files with 70 additions and 44 deletions

View File

@ -2429,6 +2429,7 @@
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug - LLVM|x64'">.\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug - LLVM|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_WINEXTRAS_LIB -DQT_CONCURRENT_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\flatbuffers\include" "-I.\..\3rdparty\wolfssl" "-I.\..\3rdparty\curl\include" "-I.\..\3rdparty\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\XAudio2Redist\include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtCore" "-I.\debug" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" "-I$(QTDIR)\include\QtConcurrent"</Command>
</CustomBuild>
<ClInclude Include="rpcs3qt\numbered_widget_item.h" />
<ClInclude Include="rpcs3qt\stylesheets.h" />
<CustomBuild Include="rpcs3qt\skylander_dialog.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release - LLVM|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
@ -3044,6 +3045,12 @@
<Command Condition="'$(Configuration)|$(Platform)'=='Debug - LLVM|x64'">"$(QTDIR)\bin\uic.exe" -o ".\QTGeneratedFiles\ui_%(Filename).h" "%(FullPath)"</Command>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<None Include="QTGeneratedFiles\Debug - LLVM\pkg_install_dialog.moc" />
<None Include="QTGeneratedFiles\Debug\pkg_install_dialog.moc" />
<None Include="QTGeneratedFiles\Release - LLVM\pkg_install_dialog.moc" />
<None Include="QTGeneratedFiles\Release\pkg_install_dialog.moc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<ProjectExtensions>

View File

@ -137,6 +137,9 @@
<Filter Include="Io\DualSense">
<UniqueIdentifier>{ff7eb8a7-5545-41af-bab1-348032b9a430}</UniqueIdentifier>
</Filter>
<Filter Include="Gui\custom items">
<UniqueIdentifier>{949cff6d-9cc5-4a8a-a453-a5144da8ecf4}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
@ -1109,7 +1112,7 @@
<Filter>Io\DualSense</Filter>
</ClCompile>
<ClCompile Include="rpcs3qt\custom_table_widget_item.cpp">
<Filter>Gui\game list</Filter>
<Filter>Gui\custom items</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
@ -1155,15 +1158,9 @@
<ClInclude Include="rpcs3qt\game_list_grid_delegate.h">
<Filter>Gui\game list</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\table_item_delegate.h">
<Filter>Gui\game list</Filter>
</ClInclude>
<ClInclude Include="Input\evdev_joystick_handler.h">
<Filter>Io\evdev</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\custom_table_widget_item.h">
<Filter>Gui\game list</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\qt_utils.h">
<Filter>Gui\utils</Filter>
</ClInclude>
@ -1215,6 +1212,15 @@
<ClInclude Include="Input\dualsense_pad_handler.h">
<Filter>Io\DualSense</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\custom_table_widget_item.h">
<Filter>Gui\custom items</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\table_item_delegate.h">
<Filter>Gui\custom items</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\numbered_widget_item.h">
<Filter>Gui\custom items</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
@ -1449,4 +1455,18 @@
<ItemGroup>
<ResourceCompile Include="rpcs3.rc" />
</ItemGroup>
<ItemGroup>
<None Include="QTGeneratedFiles\Release - LLVM\pkg_install_dialog.moc">
<Filter>Generated Files\Release - LLVM</Filter>
</None>
<None Include="QTGeneratedFiles\Debug\pkg_install_dialog.moc">
<Filter>Generated Files\Debug</Filter>
</None>
<None Include="QTGeneratedFiles\Release\pkg_install_dialog.moc">
<Filter>Generated Files\Release</Filter>
</None>
<None Include="QTGeneratedFiles\Debug - LLVM\pkg_install_dialog.moc">
<Filter>Generated Files\Debug - LLVM</Filter>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,31 @@
#pragma once
#include <QListWidgetItem>
class numbered_widget_item final : public QListWidgetItem
{
public:
explicit numbered_widget_item(const QString& text, QListWidget* listview = nullptr, int type = QListWidgetItem::Type)
: QListWidgetItem(text, listview, type)
{
}
QVariant data(int role) const override
{
switch (role)
{
case Qt::DisplayRole:
// Return number and original display text (e.g. "14. My Cool Game (BLUS12345)")
return QStringLiteral("%1. %2").arg(listWidget()->row(this) + 1).arg(QListWidgetItem::data(Qt::DisplayRole).toString());
default:
// Return original data
return QListWidgetItem::data(role);
}
}
bool operator<(const QListWidgetItem& other) const override
{
// Compare original display text
return QListWidgetItem::data(Qt::DisplayRole).toString() < other.QListWidgetItem::data(Qt::DisplayRole).toString();
}
};

View File

@ -1,5 +1,6 @@
#include "pkg_install_dialog.h"
#include "game_compatibility.h"
#include "numbered_widget_item.h"
#include <QDialogButtonBox>
#include <QPushButton>
@ -11,11 +12,10 @@
enum Roles
{
FullPathRole = Qt::UserRole + 0,
BaseDisplayRole = Qt::UserRole + 1,
ChangelogRole = Qt::UserRole + 2,
TitleRole = Qt::UserRole + 3,
TitleIdRole = Qt::UserRole + 4,
VersionRole = Qt::UserRole + 5,
ChangelogRole = Qt::UserRole + 1,
TitleRole = Qt::UserRole + 2,
TitleIdRole = Qt::UserRole + 3,
VersionRole = Qt::UserRole + 4,
};
pkg_install_dialog::pkg_install_dialog(const QStringList& paths, game_compatibility* compat, QWidget* parent)
@ -23,38 +23,6 @@ pkg_install_dialog::pkg_install_dialog(const QStringList& paths, game_compatibil
{
m_dir_list = new QListWidget(this);
class numbered_widget_item final : public QListWidgetItem
{
public:
explicit numbered_widget_item(const QString& text, QListWidget* listview = nullptr, int type = QListWidgetItem::Type)
: QListWidgetItem(text, listview, type)
{
}
QVariant data(int role) const override
{
QVariant result;
switch (role)
{
case Qt::DisplayRole:
result = QStringLiteral("%1. %2").arg(listWidget()->row(this) + 1).arg(data(Roles::BaseDisplayRole).toString());
break;
case Roles::BaseDisplayRole:
result = QListWidgetItem::data(Qt::DisplayRole);
break;
default:
result = QListWidgetItem::data(role);
break;
}
return result;
}
bool operator<(const QListWidgetItem& other) const override
{
return data(Roles::BaseDisplayRole).toString() < other.data(Roles::BaseDisplayRole).toString();
}
};
for (const QString& path : paths)
{
const compat::package_info info = game_compatibility::GetPkgInfo(path, compat);