Permalink
Browse files

Merge pull request #6952 from spycrab/qt_map_all

Qt/Mapping: Add option to map all devices at once
  • Loading branch information...
spycrab committed May 23, 2018
2 parents dfb1dba + 574c609 commit 4c1425b4193686922635247ed4dad5691439b5f4
@@ -2,7 +2,9 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <future>
#include <thread>
#include <utility>
#include <QApplication>
#include <QFontMetrics>
@@ -108,15 +110,64 @@ void MappingButton::Detect()
// Make sure that we don't block event handling
std::thread thread([this] {
const auto dev = m_parent->GetDevice();
setText(QStringLiteral("..."));
// Avoid that the button press itself is registered as an event
Common::SleepCurrentThread(100);
const auto expr = MappingCommon::DetectExpression(
m_reference, dev.get(), m_parent->GetController()->GetDefaultDevice());
std::vector<std::future<std::pair<QString, QString>>> futures;
QString expr;
if (m_parent->GetParent()->IsMappingAllDevices())
{
for (const std::string& device_str : g_controller_interface.GetAllDeviceStrings())
{
ciface::Core::DeviceQualifier devq;
devq.FromString(device_str);
auto dev = g_controller_interface.FindDevice(devq);
auto future = std::async(std::launch::async, [this, devq, dev, device_str] {
return std::make_pair(
QString::fromStdString(device_str),
MappingCommon::DetectExpression(m_reference, dev.get(),
m_parent->GetController()->GetDefaultDevice()));
});
futures.push_back(std::move(future));
}
bool done = false;
while (!done)
{
for (auto& future : futures)
{
const auto status = future.wait_for(std::chrono::milliseconds(10));
if (status == std::future_status::ready)
{
const auto pair = future.get();
done = true;
if (pair.second.isEmpty())
break;
expr = QStringLiteral("`%1:%2`")
.arg(pair.first)
.arg(pair.second.startsWith(QLatin1Char('`')) ? pair.second.mid(1) :
pair.second);
break;
}
}
}
}
else
{
const auto dev = m_parent->GetDevice();
expr = MappingCommon::DetectExpression(m_reference, dev.get(),
m_parent->GetController()->GetDefaultDevice());
}
releaseMouse();
releaseKeyboard();
@@ -222,10 +222,18 @@ void MappingWindow::OnSaveProfilePressed()
void MappingWindow::OnDeviceChanged(int index)
{
if (IsMappingAllDevices())
return;
const auto device = m_devices_combo->currentText().toStdString();
m_controller->SetDefaultDevice(device);
}
bool MappingWindow::IsMappingAllDevices() const
{
return m_devices_combo->currentIndex() == m_devices_combo->count() - 1;
}
void MappingWindow::RefreshDevices()
{
m_devices_combo->clear();
@@ -245,6 +253,8 @@ void MappingWindow::RefreshDevices()
m_devices_combo->addItem(QString::fromStdString(name));
}
m_devices_combo->addItem(tr("All devices"));
m_devices_combo->setCurrentIndex(0);
});
}
@@ -52,6 +52,7 @@ class MappingWindow final : public QDialog
std::shared_ptr<ciface::Core::Device> GetDevice() const;
ControllerEmu::EmulatedController* GetController() const;
bool IsIterativeInput() const;
bool IsMappingAllDevices() const;
signals:
void Update();

0 comments on commit 4c1425b

Please sign in to comment.