Qt: Work around QList<QPair> marshalling issue

This commit is contained in:
Stenzek 2024-06-24 00:28:44 +10:00
parent 6bfd862cb3
commit 6021e435ba
No known key found for this signature in database
7 changed files with 49 additions and 45 deletions

View File

@ -269,11 +269,13 @@ void ControllerBindingWidget::onAutomaticBindingClicked()
QMenu menu(this);
bool added = false;
for (const QPair<QString, QString>& 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;

View File

@ -220,21 +220,21 @@ void ControllerSettingsWindow::onRestoreDefaultsClicked()
switchProfile({});
}
void ControllerSettingsWindow::onInputDevicesEnumerated(const QList<QPair<QString, QString>>& devices)
void ControllerSettingsWindow::onInputDevicesEnumerated(const std::vector<std::pair<std::string, std::string>>& devices)
{
m_device_list = devices;
for (const QPair<QString, QString>& 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<QString, QString>& 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

View File

@ -17,6 +17,8 @@
#include <array>
#include <string>
#include <utility>
#include <vector>
class ControllerGlobalSettingsWidget;
class ControllerBindingWidget;
@ -47,7 +49,7 @@ public:
ALWAYS_INLINE HotkeySettingsWidget* getHotkeySettingsWidget() const { return m_hotkey_settings; }
ALWAYS_INLINE const QList<QPair<QString, QString>>& getDeviceList() const { return m_device_list; }
ALWAYS_INLINE const std::vector<std::pair<std::string, std::string>>& 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<QPair<QString, QString>>& devices);
void onInputDeviceConnected(const QString& identifier, const QString& device_name);
void onInputDeviceDisconnected(const QString& identifier);
void onInputDevicesEnumerated(const std::vector<std::pair<std::string, std::string>>& devices);
void onInputDeviceConnected(const std::string& identifier, const std::string& device_name);
void onInputDeviceDisconnected(const std::string& identifier);
void onVibrationMotorsEnumerated(const QList<InputBindingKey>& motors);
void createWidgets();
@ -99,7 +101,7 @@ private:
std::array<ControllerBindingWidget*, MAX_PORTS> m_port_bindings{};
HotkeySettingsWidget* m_hotkey_settings = nullptr;
QList<QPair<QString, QString>> m_device_list;
std::vector<std::pair<std::string, std::string>> m_device_list;
QStringList m_vibration_motors;
QString m_profile_name;

View File

@ -159,6 +159,9 @@ void QtHost::RegisterTypes()
qRegisterMetaType<const GameList::Entry*>();
qRegisterMetaType<GPURenderer>("GPURenderer");
qRegisterMetaType<InputBindingKey>("InputBindingKey");
qRegisterMetaType<std::string>("std::string");
qRegisterMetaType<std::vector<std::pair<std::string, std::string>>>(
"std::vector<std::pair<std::string, std::string>>");
}
bool QtHost::InBatchMode()
@ -1099,13 +1102,7 @@ void EmuThread::enumerateInputDevices()
return;
}
const std::vector<std::pair<std::string, std::string>> devs(InputManager::EnumerateDevices());
QList<QPair<QString, QString>> qdevs;
qdevs.reserve(devs.size());
for (const std::pair<std::string, std::string>& 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))

View File

@ -27,6 +27,7 @@
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -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<QPair<QString, QString>>& devices);
void onInputDeviceConnected(const QString& identifier, const QString& device_name);
void onInputDeviceDisconnected(const QString& identifier);
void onInputDevicesEnumerated(const std::vector<std::pair<std::string, std::string>>& devices);
void onInputDeviceConnected(const std::string& identifier, const std::string& device_name);
void onInputDeviceDisconnected(const std::string& identifier);
void onVibrationMotorsEnumerated(const QList<InputBindingKey>& motors);
void systemStarting();
void systemStarted();

View File

@ -445,11 +445,13 @@ void SetupWizardDialog::openAutomaticMappingMenu(u32 port, QLabel* update_label)
QMenu menu(this);
bool added = false;
for (const QPair<QString, QString>& 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<QPair<QString, QString>>& devices)
void SetupWizardDialog::onInputDevicesEnumerated(const std::vector<std::pair<std::string, std::string>>& 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)
{

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>.
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>.
// 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 <QtCore/QList>
#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtWidgets/QDialog>
#include "core/bios.h"
#include <string>
#include <utility>
#include <vector>
class SetupWizardDialog final : public QDialog
{
@ -42,9 +45,9 @@ private Q_SLOTS:
void refreshDirectoryList();
void resizeDirectoryListColumns();
void onInputDevicesEnumerated(const QList<QPair<QString, QString>>& devices);
void onInputDeviceConnected(const QString& identifier, const QString& device_name);
void onInputDeviceDisconnected(const QString& identifier);
void onInputDevicesEnumerated(const std::vector<std::pair<std::string, std::string>>& 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<QLabel*, Page_Count> m_page_labels;
QList<QPair<QString, QString>> m_device_list;
std::vector<std::pair<std::string, std::string>> m_device_list;
};