From f37813d8b69b8dc78502367f279f24fb9ba718a0 Mon Sep 17 00:00:00 2001 From: Techjar Date: Mon, 16 Jul 2018 17:15:37 -0400 Subject: [PATCH] Qt/IOWindow: Fix detection of button names containing non-alphabetical characters The button wouldn't be highlighted in the list, as it would look for something like `Click 1` instead of Click 1. --- .../Core/DolphinQt/Config/Mapping/IOWindow.cpp | 3 ++- .../DolphinQt/Config/Mapping/MappingCommon.cpp | 18 +++++++++++------- .../DolphinQt/Config/Mapping/MappingCommon.h | 14 +++++++++++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp b/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp index 6647df8d7c..f238f2e4a9 100644 --- a/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp @@ -187,7 +187,8 @@ void IOWindow::OnDetectButtonPressed() btn->setText(QStringLiteral("...")); const auto expr = MappingCommon::DetectExpression( - m_reference, g_controller_interface.FindDevice(m_devq).get(), m_devq); + m_reference, g_controller_interface.FindDevice(m_devq).get(), m_devq, + MappingCommon::Quote::Off); btn->setText(old_label); diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp index 49c29d29a7..9bbf1b17a1 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp @@ -14,7 +14,7 @@ namespace MappingCommon { QString GetExpressionForControl(const QString& control_name, const ciface::Core::DeviceQualifier& control_device, - const ciface::Core::DeviceQualifier& default_device) + const ciface::Core::DeviceQualifier& default_device, Quote quote) { QString expr; @@ -28,22 +28,26 @@ QString GetExpressionForControl(const QString& control_name, // append the control name expr += control_name; - QRegExp reg(QStringLiteral("[a-zA-Z]+")); - if (!reg.exactMatch(expr)) - expr = QStringLiteral("`%1`").arg(expr); + if (quote == Quote::On) + { + QRegExp reg(QStringLiteral("[a-zA-Z]+")); + if (!reg.exactMatch(expr)) + expr = QStringLiteral("`%1`").arg(expr); + } + return expr; } QString DetectExpression(ControlReference* reference, ciface::Core::Device* device, - const ciface::Core::DeviceQualifier& default_device) + const ciface::Core::DeviceQualifier& default_device, Quote quote) { ciface::Core::Device::Control* const ctrl = reference->Detect(5000, device); if (ctrl) { return MappingCommon::GetExpressionForControl(QString::fromStdString(ctrl->GetName()), - default_device, default_device); + default_device, default_device, quote); } return QStringLiteral(""); } -} +} // namespace MappingCommon diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingCommon.h b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.h index ef3ce7fe54..1ee3ae1ead 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingCommon.h +++ b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.h @@ -18,9 +18,17 @@ class DeviceQualifier; namespace MappingCommon { +enum class Quote +{ + On, + Off +}; + QString GetExpressionForControl(const QString& control_name, const ciface::Core::DeviceQualifier& control_device, - const ciface::Core::DeviceQualifier& default_device); + const ciface::Core::DeviceQualifier& default_device, + Quote quote = Quote::On); QString DetectExpression(ControlReference* reference, ciface::Core::Device* device, - const ciface::Core::DeviceQualifier& default_device); -} + const ciface::Core::DeviceQualifier& default_device, + Quote quote = Quote::On); +} // namespace MappingCommon