Merge pull request #6210 from ligfx/qtmappingwindowdontstoredevq

MappingWindow: don't store devq separately from controller default device
This commit is contained in:
Leo Lam 2017-12-15 20:50:06 +01:00 committed by GitHub
commit a4592bc3c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 29 deletions

View File

@ -114,7 +114,7 @@ void IOWindow::Update()
m_range_spinbox->setValue(m_reference->range * SLIDER_TICK_COUNT); m_range_spinbox->setValue(m_reference->range * SLIDER_TICK_COUNT);
m_range_slider->setValue(m_reference->range * SLIDER_TICK_COUNT); m_range_slider->setValue(m_reference->range * SLIDER_TICK_COUNT);
m_devq.FromString(m_controller->GetDefaultDevice().ToString()); m_devq = m_controller->GetDefaultDevice();
UpdateDeviceList(); UpdateDeviceList();
UpdateOptionList(); UpdateOptionList();
@ -183,7 +183,7 @@ 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_devq); m_reference, g_controller_interface.FindDevice(m_devq).get(), m_devq);
btn->setText(old_label); btn->setText(old_label);

View File

@ -57,8 +57,7 @@ void MappingButton::OnButtonPressed()
Common::SleepCurrentThread(100); Common::SleepCurrentThread(100);
const auto expr = MappingCommon::DetectExpression( const auto expr = MappingCommon::DetectExpression(
m_reference, dev.get(), m_parent->GetParent()->GetDeviceQualifier(), m_reference, dev.get(), m_parent->GetController()->GetDefaultDevice());
m_parent->GetController()->GetDefaultDevice());
releaseMouse(); releaseMouse();
releaseKeyboard(); releaseKeyboard();
@ -90,7 +89,8 @@ void MappingButton::Clear()
void MappingButton::Update() void MappingButton::Update()
{ {
const auto lock = ControllerEmu::EmulatedController::GetStateLock(); const auto lock = ControllerEmu::EmulatedController::GetStateLock();
m_reference->UpdateReference(g_controller_interface, m_parent->GetParent()->GetDeviceQualifier()); m_reference->UpdateReference(g_controller_interface,
m_parent->GetController()->GetDefaultDevice());
setText(EscapeAmpersand(QString::fromStdString(m_reference->GetExpression()))); setText(EscapeAmpersand(QString::fromStdString(m_reference->GetExpression())));
} }

View File

@ -35,15 +35,14 @@ QString GetExpressionForControl(const QString& control_name,
} }
QString DetectExpression(ControlReference* reference, ciface::Core::Device* device, QString DetectExpression(ControlReference* reference, ciface::Core::Device* device,
const ciface::Core::DeviceQualifier& m_devq,
const ciface::Core::DeviceQualifier& default_device) const ciface::Core::DeviceQualifier& default_device)
{ {
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()), m_devq, return MappingCommon::GetExpressionForControl(QString::fromStdString(ctrl->GetName()),
default_device); default_device, default_device);
} }
return QStringLiteral(""); return QStringLiteral("");
} }

View File

@ -22,6 +22,5 @@ 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);
QString DetectExpression(ControlReference* reference, ciface::Core::Device* device, QString DetectExpression(ControlReference* reference, ciface::Core::Device* device,
const ciface::Core::DeviceQualifier& m_devq,
const ciface::Core::DeviceQualifier& default_device); const ciface::Core::DeviceQualifier& default_device);
} }

View File

@ -210,7 +210,6 @@ void MappingWindow::OnSaveProfilePressed()
void MappingWindow::OnDeviceChanged(int index) void MappingWindow::OnDeviceChanged(int index)
{ {
const auto device = m_devices_combo->currentText().toStdString(); const auto device = m_devices_combo->currentText().toStdString();
m_devq.FromString(device);
m_controller->SetDefaultDevice(device); m_controller->SetDefaultDevice(device);
} }
@ -298,7 +297,6 @@ void MappingWindow::SetMappingType(MappingWindow::Type type)
m_profiles_combo->addItem(QString::fromStdString(basename), QString::fromStdString(filename)); m_profiles_combo->addItem(QString::fromStdString(basename), QString::fromStdString(filename));
} }
if (m_controller != nullptr)
RefreshDevices(); RefreshDevices();
} }
@ -317,21 +315,13 @@ ControllerEmu::EmulatedController* MappingWindow::GetController() const
return m_controller; return m_controller;
} }
const ciface::Core::DeviceQualifier& MappingWindow::GetDeviceQualifier() const
{
return m_devq;
}
std::shared_ptr<ciface::Core::Device> MappingWindow::GetDevice() const std::shared_ptr<ciface::Core::Device> MappingWindow::GetDevice() const
{ {
return g_controller_interface.FindDevice(m_devq); return g_controller_interface.FindDevice(GetController()->GetDefaultDevice());
} }
void MappingWindow::OnDefaultFieldsPressed() void MappingWindow::OnDefaultFieldsPressed()
{ {
if (m_controller == nullptr)
return;
m_controller->LoadDefaults(g_controller_interface); m_controller->LoadDefaults(g_controller_interface);
m_controller->UpdateReferences(g_controller_interface); m_controller->UpdateReferences(g_controller_interface);
emit Update(); emit Update();

View File

@ -48,7 +48,6 @@ public:
explicit MappingWindow(QWidget* parent, Type type, int port_num); explicit MappingWindow(QWidget* parent, Type type, int port_num);
int GetPort() const; int GetPort() const;
const ciface::Core::DeviceQualifier& GetDeviceQualifier() const;
std::shared_ptr<ciface::Core::Device> GetDevice() const; std::shared_ptr<ciface::Core::Device> GetDevice() const;
ControllerEmu::EmulatedController* GetController() const; ControllerEmu::EmulatedController* GetController() const;
@ -106,5 +105,4 @@ private:
Type m_mapping_type; Type m_mapping_type;
const int m_port; const int m_port;
InputConfig* m_config; InputConfig* m_config;
ciface::Core::DeviceQualifier m_devq;
}; };

View File

@ -87,15 +87,17 @@ std::string DeviceQualifier::ToString() const
// //
void DeviceQualifier::FromString(const std::string& str) void DeviceQualifier::FromString(const std::string& str)
{ {
*this = {};
std::istringstream ss(str); std::istringstream ss(str);
std::getline(ss, source = "", '/'); std::getline(ss, source, '/');
// silly // silly
std::getline(ss, name, '/'); std::getline(ss, name, '/');
std::istringstream(name) >> (cid = -1); std::istringstream(name) >> cid;
std::getline(ss, name = ""); std::getline(ss, name);
} }
// //

View File

@ -18,9 +18,6 @@ namespace ciface
{ {
namespace Core namespace Core
{ {
// Forward declarations
class DeviceQualifier;
// //
// Device // Device
// //