mirror of
https://github.com/stenzek/duckstation.git
synced 2025-07-12 21:20:19 +00:00
Qt: Avoid heap string copy for each context menu action
QString is copy-on-write.
This commit is contained in:
parent
308bc5f356
commit
4616dd3293
@ -59,13 +59,13 @@ GameListSettingsWidget::GameListSettingsWidget(SettingsWindow* dialog, QWidget*
|
|||||||
|
|
||||||
GameListSettingsWidget::~GameListSettingsWidget() = default;
|
GameListSettingsWidget::~GameListSettingsWidget() = default;
|
||||||
|
|
||||||
bool GameListSettingsWidget::addExcludedPath(const std::string& path)
|
bool GameListSettingsWidget::addExcludedPath(const QString& path)
|
||||||
{
|
{
|
||||||
if (!Host::AddValueToBaseStringListSetting("GameList", "ExcludedPaths", path.c_str()))
|
if (!Host::AddValueToBaseStringListSetting("GameList", "ExcludedPaths", path.toStdString().c_str()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Host::CommitBaseSettingChanges();
|
Host::CommitBaseSettingChanges();
|
||||||
m_ui.excludedPaths->addItem(QString::fromStdString(path));
|
m_ui.excludedPaths->addItem(path);
|
||||||
g_main_window->refreshGameList(false);
|
g_main_window->refreshGameList(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ void GameListSettingsWidget::onAddExcludedFileButtonClicked()
|
|||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
addExcludedPath(path.toStdString());
|
addExcludedPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameListSettingsWidget::onAddExcludedFolderButtonClicked()
|
void GameListSettingsWidget::onAddExcludedFolderButtonClicked()
|
||||||
@ -248,7 +248,7 @@ void GameListSettingsWidget::onAddExcludedFolderButtonClicked()
|
|||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
addExcludedPath(path.toStdString());
|
addExcludedPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameListSettingsWidget::onRemoveExcludedPathButtonClicked()
|
void GameListSettingsWidget::onRemoveExcludedPathButtonClicked()
|
||||||
|
@ -17,7 +17,7 @@ public:
|
|||||||
GameListSettingsWidget(SettingsWindow* dialog, QWidget* parent);
|
GameListSettingsWidget(SettingsWindow* dialog, QWidget* parent);
|
||||||
~GameListSettingsWidget();
|
~GameListSettingsWidget();
|
||||||
|
|
||||||
bool addExcludedPath(const std::string& path);
|
bool addExcludedPath(const QString& path);
|
||||||
void refreshExclusionList();
|
void refreshExclusionList();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
@ -1464,9 +1464,9 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
|
|||||||
|
|
||||||
if (!entry->IsDiscSet())
|
if (!entry->IsDiscSet())
|
||||||
{
|
{
|
||||||
connect(menu.addAction(tr("Properties...")), &QAction::triggered, [path = entry->path]() {
|
connect(menu.addAction(tr("Properties...")), &QAction::triggered, [qpath]() {
|
||||||
const auto lock = GameList::GetLock();
|
const auto lock = GameList::GetLock();
|
||||||
const GameList::Entry* entry = GameList::GetEntryForPath(path);
|
const GameList::Entry* entry = GameList::GetEntryForPath(qpath.toStdString());
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1491,9 +1491,9 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(menu.addAction(tr("Set Cover Image...")), &QAction::triggered, [this, path = entry->path]() {
|
connect(menu.addAction(tr("Set Cover Image...")), &QAction::triggered, [this, qpath]() {
|
||||||
const auto lock = GameList::GetLock();
|
const auto lock = GameList::GetLock();
|
||||||
const GameList::Entry* entry = GameList::GetEntryForPath(path);
|
const GameList::Entry* entry = GameList::GetEntryForPath(qpath.toStdString());
|
||||||
if (entry)
|
if (entry)
|
||||||
setGameListEntryCoverImage(entry);
|
setGameListEntryCoverImage(entry);
|
||||||
});
|
});
|
||||||
@ -1505,28 +1505,27 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
|
|||||||
populateGameListContextMenu(entry, this, &menu);
|
populateGameListContextMenu(entry, this, &menu);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
connect(menu.addAction(tr("Default Boot")), &QAction::triggered, [this, path = entry->path]() mutable {
|
connect(menu.addAction(tr("Default Boot")), &QAction::triggered,
|
||||||
g_emu_thread->bootSystem(getSystemBootParameters(std::move(path)));
|
[this, qpath]() mutable { g_emu_thread->bootSystem(getSystemBootParameters(qpath.toStdString())); });
|
||||||
});
|
|
||||||
|
|
||||||
connect(menu.addAction(tr("Fast Boot")), &QAction::triggered, [this, path = entry->path]() mutable {
|
connect(menu.addAction(tr("Fast Boot")), &QAction::triggered, [this, qpath]() mutable {
|
||||||
std::shared_ptr<SystemBootParameters> boot_params = getSystemBootParameters(std::move(path));
|
std::shared_ptr<SystemBootParameters> boot_params = getSystemBootParameters(qpath.toStdString());
|
||||||
boot_params->override_fast_boot = true;
|
boot_params->override_fast_boot = true;
|
||||||
g_emu_thread->bootSystem(std::move(boot_params));
|
g_emu_thread->bootSystem(std::move(boot_params));
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(menu.addAction(tr("Full Boot")), &QAction::triggered, [this, path = entry->path]() mutable {
|
connect(menu.addAction(tr("Full Boot")), &QAction::triggered, [this, qpath]() mutable {
|
||||||
std::shared_ptr<SystemBootParameters> boot_params = getSystemBootParameters(std::move(path));
|
std::shared_ptr<SystemBootParameters> boot_params = getSystemBootParameters(qpath.toStdString());
|
||||||
boot_params->override_fast_boot = false;
|
boot_params->override_fast_boot = false;
|
||||||
g_emu_thread->bootSystem(std::move(boot_params));
|
g_emu_thread->bootSystem(std::move(boot_params));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (m_ui.menuDebug->menuAction()->isVisible())
|
if (m_ui.menuDebug->menuAction()->isVisible())
|
||||||
{
|
{
|
||||||
connect(menu.addAction(tr("Boot and Debug")), &QAction::triggered, [this, path = entry->path]() mutable {
|
connect(menu.addAction(tr("Boot and Debug")), &QAction::triggered, [this, qpath]() mutable {
|
||||||
openCPUDebugger();
|
openCPUDebugger();
|
||||||
|
|
||||||
std::shared_ptr<SystemBootParameters> boot_params = getSystemBootParameters(std::move(path));
|
std::shared_ptr<SystemBootParameters> boot_params = getSystemBootParameters(qpath.toStdString());
|
||||||
boot_params->override_start_paused = true;
|
boot_params->override_start_paused = true;
|
||||||
boot_params->disable_achievements_hardcore_mode = true;
|
boot_params->disable_achievements_hardcore_mode = true;
|
||||||
g_emu_thread->bootSystem(std::move(boot_params));
|
g_emu_thread->bootSystem(std::move(boot_params));
|
||||||
@ -1544,10 +1543,10 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
connect(menu.addAction(tr("Properties...")), &QAction::triggered, [disc_set_name = entry->path]() {
|
connect(menu.addAction(tr("Properties...")), &QAction::triggered, [disc_set_name = qpath]() {
|
||||||
// resolve path first
|
// resolve path first
|
||||||
auto lock = GameList::GetLock();
|
auto lock = GameList::GetLock();
|
||||||
const GameList::Entry* first_disc = GameList::GetFirstDiscSetMember(disc_set_name);
|
const GameList::Entry* first_disc = GameList::GetFirstDiscSetMember(disc_set_name.toStdString());
|
||||||
if (first_disc)
|
if (first_disc)
|
||||||
{
|
{
|
||||||
SettingsWindow::openGamePropertiesDialog(first_disc->path, first_disc->title, first_disc->serial,
|
SettingsWindow::openGamePropertiesDialog(first_disc->path, first_disc->title, first_disc->serial,
|
||||||
@ -1555,9 +1554,9 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(menu.addAction(tr("Set Cover Image...")), &QAction::triggered, [this, path = entry->path]() {
|
connect(menu.addAction(tr("Set Cover Image...")), &QAction::triggered, [this, qpath]() {
|
||||||
const auto lock = GameList::GetLock();
|
const auto lock = GameList::GetLock();
|
||||||
const GameList::Entry* entry = GameList::GetEntryForPath(path);
|
const GameList::Entry* entry = GameList::GetEntryForPath(qpath.toStdString());
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1575,13 +1574,12 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
|
|||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
connect(menu.addAction(tr("Exclude From List")), &QAction::triggered, [this, path = entry->path]() {
|
connect(menu.addAction(tr("Exclude From List")), &QAction::triggered,
|
||||||
getSettingsWindow()->getGameListSettingsWidget()->addExcludedPath(path);
|
[this, qpath]() { getSettingsWindow()->getGameListSettingsWidget()->addExcludedPath(qpath); });
|
||||||
});
|
|
||||||
|
|
||||||
connect(menu.addAction(tr("Reset Play Time")), &QAction::triggered, [this, path = entry->path]() {
|
connect(menu.addAction(tr("Reset Play Time")), &QAction::triggered, [this, qpath]() {
|
||||||
const auto lock = GameList::GetLock();
|
const auto lock = GameList::GetLock();
|
||||||
const GameList::Entry* entry = GameList::GetEntryForPath(path);
|
const GameList::Entry* entry = GameList::GetEntryForPath(qpath.toStdString());
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user