Merge pull request #7273 from Techjar/qt-iowindow-detect-spaces
Qt/IOWindow: Fix detection of button names containing non-alphabetical characters
This commit is contained in:
commit
6af7c1fe27
|
@ -190,7 +190,8 @@ void IOWindow::OnDetectButtonPressed()
|
||||||
btn->setText(QStringLiteral("..."));
|
btn->setText(QStringLiteral("..."));
|
||||||
|
|
||||||
const auto expr = MappingCommon::DetectExpression(
|
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);
|
btn->setText(old_label);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace MappingCommon
|
||||||
{
|
{
|
||||||
QString GetExpressionForControl(const QString& control_name,
|
QString GetExpressionForControl(const QString& control_name,
|
||||||
const ciface::Core::DeviceQualifier& control_device,
|
const ciface::Core::DeviceQualifier& control_device,
|
||||||
const ciface::Core::DeviceQualifier& default_device)
|
const ciface::Core::DeviceQualifier& default_device, Quote quote)
|
||||||
{
|
{
|
||||||
QString expr;
|
QString expr;
|
||||||
|
|
||||||
|
@ -28,22 +28,26 @@ QString GetExpressionForControl(const QString& control_name,
|
||||||
// append the control name
|
// append the control name
|
||||||
expr += control_name;
|
expr += control_name;
|
||||||
|
|
||||||
|
if (quote == Quote::On)
|
||||||
|
{
|
||||||
QRegExp reg(QStringLiteral("[a-zA-Z]+"));
|
QRegExp reg(QStringLiteral("[a-zA-Z]+"));
|
||||||
if (!reg.exactMatch(expr))
|
if (!reg.exactMatch(expr))
|
||||||
expr = QStringLiteral("`%1`").arg(expr);
|
expr = QStringLiteral("`%1`").arg(expr);
|
||||||
|
}
|
||||||
|
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DetectExpression(ControlReference* reference, ciface::Core::Device* device,
|
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);
|
ciface::Core::Device::Control* const ctrl = reference->Detect(5000, device);
|
||||||
|
|
||||||
if (ctrl)
|
if (ctrl)
|
||||||
{
|
{
|
||||||
return MappingCommon::GetExpressionForControl(QString::fromStdString(ctrl->GetName()),
|
return MappingCommon::GetExpressionForControl(QString::fromStdString(ctrl->GetName()),
|
||||||
default_device, default_device);
|
default_device, default_device, quote);
|
||||||
}
|
}
|
||||||
return QStringLiteral("");
|
return QStringLiteral("");
|
||||||
}
|
}
|
||||||
}
|
} // namespace MappingCommon
|
||||||
|
|
|
@ -18,9 +18,17 @@ class DeviceQualifier;
|
||||||
|
|
||||||
namespace MappingCommon
|
namespace MappingCommon
|
||||||
{
|
{
|
||||||
|
enum class Quote
|
||||||
|
{
|
||||||
|
On,
|
||||||
|
Off
|
||||||
|
};
|
||||||
|
|
||||||
QString GetExpressionForControl(const QString& control_name,
|
QString GetExpressionForControl(const QString& control_name,
|
||||||
const ciface::Core::DeviceQualifier& control_device,
|
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,
|
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
|
||||||
|
|
Loading…
Reference in New Issue