From 6021e435bac42e44dd0e288361f8a9fb82963308 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 24 Jun 2024 00:28:44 +1000 Subject: [PATCH] Qt: Work around QList marshalling issue --- .../controllerbindingwidgets.cpp | 8 +++++--- .../controllersettingswindow.cpp | 18 +++++++++--------- src/duckstation-qt/controllersettingswindow.h | 12 +++++++----- src/duckstation-qt/qthost.cpp | 18 ++++++------------ src/duckstation-qt/qthost.h | 7 ++++--- src/duckstation-qt/setupwizarddialog.cpp | 14 ++++++++------ src/duckstation-qt/setupwizarddialog.h | 17 ++++++++++------- 7 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/duckstation-qt/controllerbindingwidgets.cpp b/src/duckstation-qt/controllerbindingwidgets.cpp index 4d60842d7..21b20fd14 100644 --- a/src/duckstation-qt/controllerbindingwidgets.cpp +++ b/src/duckstation-qt/controllerbindingwidgets.cpp @@ -269,11 +269,13 @@ void ControllerBindingWidget::onAutomaticBindingClicked() QMenu menu(this); bool added = false; - for (const QPair& dev : m_dialog->getDeviceList()) + for (const auto& [identifier, device_name] : m_dialog->getDeviceList()) { // we set it as data, because the device list could get invalidated while the menu is up - QAction* action = menu.addAction(QStringLiteral("%1 (%2)").arg(dev.first).arg(dev.second)); - action->setData(dev.first); + const QString qidentifier = QString::fromStdString(identifier); + QAction* action = + menu.addAction(QStringLiteral("%1 (%2)").arg(qidentifier).arg(QString::fromStdString(device_name))); + action->setData(qidentifier); connect(action, &QAction::triggered, this, [this, action]() { doDeviceAutomaticBinding(action->data().toString()); }); added = true; diff --git a/src/duckstation-qt/controllersettingswindow.cpp b/src/duckstation-qt/controllersettingswindow.cpp index ed6f9a66d..a9e854312 100644 --- a/src/duckstation-qt/controllersettingswindow.cpp +++ b/src/duckstation-qt/controllersettingswindow.cpp @@ -220,21 +220,21 @@ void ControllerSettingsWindow::onRestoreDefaultsClicked() switchProfile({}); } -void ControllerSettingsWindow::onInputDevicesEnumerated(const QList>& devices) +void ControllerSettingsWindow::onInputDevicesEnumerated(const std::vector>& devices) { m_device_list = devices; - for (const QPair& device : devices) - m_global_settings->addDeviceToList(device.first, device.second); + for (const auto& [device_name, display_name] : m_device_list) + m_global_settings->addDeviceToList(QString::fromStdString(device_name), QString::fromStdString(display_name)); } -void ControllerSettingsWindow::onInputDeviceConnected(const QString& identifier, const QString& device_name) +void ControllerSettingsWindow::onInputDeviceConnected(const std::string& identifier, const std::string& device_name) { m_device_list.emplace_back(identifier, device_name); - m_global_settings->addDeviceToList(identifier, device_name); + m_global_settings->addDeviceToList(QString::fromStdString(identifier), QString::fromStdString(device_name)); g_emu_thread->enumerateVibrationMotors(); } -void ControllerSettingsWindow::onInputDeviceDisconnected(const QString& identifier) +void ControllerSettingsWindow::onInputDeviceDisconnected(const std::string& identifier) { for (auto iter = m_device_list.begin(); iter != m_device_list.end(); ++iter) { @@ -245,7 +245,7 @@ void ControllerSettingsWindow::onInputDeviceDisconnected(const QString& identifi } } - m_global_settings->removeDeviceFromList(identifier); + m_global_settings->removeDeviceFromList(QString::fromStdString(identifier)); g_emu_thread->enumerateVibrationMotors(); } @@ -385,8 +385,8 @@ void ControllerSettingsWindow::createWidgets() m_ui.settingsContainer->addWidget(m_global_settings); connect(m_global_settings, &ControllerGlobalSettingsWidget::bindingSetupChanged, this, &ControllerSettingsWindow::createWidgets); - for (const QPair& dev : m_device_list) - m_global_settings->addDeviceToList(dev.first, dev.second); + for (const auto& [identifier, device_name] : m_device_list) + m_global_settings->addDeviceToList(QString::fromStdString(identifier), QString::fromStdString(device_name)); } // load mtap settings diff --git a/src/duckstation-qt/controllersettingswindow.h b/src/duckstation-qt/controllersettingswindow.h index 6b4b37f69..80ba9ed7b 100644 --- a/src/duckstation-qt/controllersettingswindow.h +++ b/src/duckstation-qt/controllersettingswindow.h @@ -17,6 +17,8 @@ #include #include +#include +#include class ControllerGlobalSettingsWidget; class ControllerBindingWidget; @@ -47,7 +49,7 @@ public: ALWAYS_INLINE HotkeySettingsWidget* getHotkeySettingsWidget() const { return m_hotkey_settings; } - ALWAYS_INLINE const QList>& getDeviceList() const { return m_device_list; } + ALWAYS_INLINE const std::vector>& getDeviceList() const { return m_device_list; } ALWAYS_INLINE const QStringList& getVibrationMotors() const { return m_vibration_motors; } ALWAYS_INLINE bool isEditingGlobalSettings() const { return m_profile_name.isEmpty(); } @@ -80,9 +82,9 @@ private Q_SLOTS: void onDeleteProfileClicked(); void onRestoreDefaultsClicked(); - void onInputDevicesEnumerated(const QList>& devices); - void onInputDeviceConnected(const QString& identifier, const QString& device_name); - void onInputDeviceDisconnected(const QString& identifier); + void onInputDevicesEnumerated(const std::vector>& devices); + void onInputDeviceConnected(const std::string& identifier, const std::string& device_name); + void onInputDeviceDisconnected(const std::string& identifier); void onVibrationMotorsEnumerated(const QList& motors); void createWidgets(); @@ -99,7 +101,7 @@ private: std::array m_port_bindings{}; HotkeySettingsWidget* m_hotkey_settings = nullptr; - QList> m_device_list; + std::vector> m_device_list; QStringList m_vibration_motors; QString m_profile_name; diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 3accb58a3..307170a1b 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -159,6 +159,9 @@ void QtHost::RegisterTypes() qRegisterMetaType(); qRegisterMetaType("GPURenderer"); qRegisterMetaType("InputBindingKey"); + qRegisterMetaType("std::string"); + qRegisterMetaType>>( + "std::vector>"); } bool QtHost::InBatchMode() @@ -1099,13 +1102,7 @@ void EmuThread::enumerateInputDevices() return; } - const std::vector> devs(InputManager::EnumerateDevices()); - QList> qdevs; - qdevs.reserve(devs.size()); - for (const std::pair& dev : devs) - qdevs.emplace_back(QString::fromStdString(dev.first), QString::fromStdString(dev.second)); - - onInputDevicesEnumerated(qdevs); + onInputDevicesEnumerated(InputManager::EnumerateDevices()); } void EmuThread::enumerateVibrationMotors() @@ -1863,9 +1860,7 @@ void Host::AddFixedInputBindings(SettingsInterface& si) void Host::OnInputDeviceConnected(std::string_view identifier, std::string_view device_name) { - emit g_emu_thread->onInputDeviceConnected( - identifier.empty() ? QString() : QString::fromUtf8(identifier.data(), identifier.size()), - device_name.empty() ? QString() : QString::fromUtf8(device_name.data(), device_name.size())); + emit g_emu_thread->onInputDeviceConnected(std::string(identifier), std::string(device_name)); if (System::IsValid() || g_emu_thread->isRunningFullscreenUI()) { @@ -1877,8 +1872,7 @@ void Host::OnInputDeviceConnected(std::string_view identifier, std::string_view void Host::OnInputDeviceDisconnected(InputBindingKey key, std::string_view identifier) { - emit g_emu_thread->onInputDeviceDisconnected( - identifier.empty() ? QString() : QString::fromUtf8(identifier.data(), identifier.size())); + emit g_emu_thread->onInputDeviceDisconnected(std::string(identifier)); if (g_settings.pause_on_controller_disconnection && System::GetState() == System::State::Running && InputManager::HasAnyBindingsForSource(key)) diff --git a/src/duckstation-qt/qthost.h b/src/duckstation-qt/qthost.h index 046041a62..40977268b 100644 --- a/src/duckstation-qt/qthost.h +++ b/src/duckstation-qt/qthost.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -124,9 +125,9 @@ Q_SIGNALS: void statusMessage(const QString& message); void debuggerMessageReported(const QString& message); void settingsResetToDefault(bool system, bool controller); - void onInputDevicesEnumerated(const QList>& devices); - void onInputDeviceConnected(const QString& identifier, const QString& device_name); - void onInputDeviceDisconnected(const QString& identifier); + void onInputDevicesEnumerated(const std::vector>& devices); + void onInputDeviceConnected(const std::string& identifier, const std::string& device_name); + void onInputDeviceDisconnected(const std::string& identifier); void onVibrationMotorsEnumerated(const QList& motors); void systemStarting(); void systemStarted(); diff --git a/src/duckstation-qt/setupwizarddialog.cpp b/src/duckstation-qt/setupwizarddialog.cpp index 840a8b8a2..4015fd590 100644 --- a/src/duckstation-qt/setupwizarddialog.cpp +++ b/src/duckstation-qt/setupwizarddialog.cpp @@ -445,11 +445,13 @@ void SetupWizardDialog::openAutomaticMappingMenu(u32 port, QLabel* update_label) QMenu menu(this); bool added = false; - for (const QPair& dev : m_device_list) + for (const auto& [identifier, device_name] : m_device_list) { // we set it as data, because the device list could get invalidated while the menu is up - QAction* action = menu.addAction(QStringLiteral("%1 (%2)").arg(dev.first).arg(dev.second)); - action->setData(dev.first); + const QString qidentifier = QString::fromStdString(identifier); + QAction* action = + menu.addAction(QStringLiteral("%1 (%2)").arg(qidentifier).arg(QString::fromStdString(device_name))); + action->setData(qidentifier); connect(action, &QAction::triggered, this, [this, port, update_label, action]() { doDeviceAutomaticBinding(port, update_label, action->data().toString()); }); @@ -492,17 +494,17 @@ void SetupWizardDialog::doDeviceAutomaticBinding(u32 port, QLabel* update_label, update_label->setText(device); } -void SetupWizardDialog::onInputDevicesEnumerated(const QList>& devices) +void SetupWizardDialog::onInputDevicesEnumerated(const std::vector>& devices) { m_device_list = devices; } -void SetupWizardDialog::onInputDeviceConnected(const QString& identifier, const QString& device_name) +void SetupWizardDialog::onInputDeviceConnected(const std::string& identifier, const std::string& device_name) { m_device_list.emplace_back(identifier, device_name); } -void SetupWizardDialog::onInputDeviceDisconnected(const QString& identifier) +void SetupWizardDialog::onInputDeviceDisconnected(const std::string& identifier) { for (auto iter = m_device_list.begin(); iter != m_device_list.end(); ++iter) { diff --git a/src/duckstation-qt/setupwizarddialog.h b/src/duckstation-qt/setupwizarddialog.h index c32cfd251..eead20f2a 100644 --- a/src/duckstation-qt/setupwizarddialog.h +++ b/src/duckstation-qt/setupwizarddialog.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin . +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin . // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once @@ -7,12 +7,15 @@ #include "ui_setupwizarddialog.h" +#include "core/bios.h" + #include #include #include #include - -#include "core/bios.h" +#include +#include +#include class SetupWizardDialog final : public QDialog { @@ -42,9 +45,9 @@ private Q_SLOTS: void refreshDirectoryList(); void resizeDirectoryListColumns(); - void onInputDevicesEnumerated(const QList>& devices); - void onInputDeviceConnected(const QString& identifier, const QString& device_name); - void onInputDeviceDisconnected(const QString& identifier); + void onInputDevicesEnumerated(const std::vector>& devices); + void onInputDeviceConnected(const std::string& identifier, const std::string& device_name); + void onInputDeviceDisconnected(const std::string& identifier); protected: void resizeEvent(QResizeEvent* event); @@ -79,5 +82,5 @@ private: std::array m_page_labels; - QList> m_device_list; + std::vector> m_device_list; };