ControllerInterface: Add IsHidden function to Control interface.

This commit is contained in:
Jordan Woyak 2024-03-14 22:09:41 -05:00
parent 0538366326
commit ee43c9508c
3 changed files with 32 additions and 20 deletions

View File

@ -587,28 +587,25 @@ void IOWindow::UpdateOptionList()
if (m_selected_device == nullptr)
return;
const auto add_rows = [this](auto& container) {
int row = 0;
for (ciface::Core::Device::Control* control : container)
{
m_option_list->insertRow(row);
if (control->IsHidden())
m_option_list->hideRow(row);
m_option_list->setItem(row, 0,
new QTableWidgetItem(QString::fromStdString(control->GetName())));
++row;
}
};
if (m_reference->IsInput())
{
int row = 0;
for (const auto* input : m_selected_device->Inputs())
{
m_option_list->insertRow(row);
m_option_list->setItem(row, 0,
new QTableWidgetItem(QString::fromStdString(input->GetName())));
++row;
}
}
add_rows(m_selected_device->Inputs());
else
{
int row = 0;
for (const auto* output : m_selected_device->Outputs())
{
m_option_list->insertRow(row);
m_option_list->setItem(row, 0,
new QTableWidgetItem(QString::fromStdString(output->GetName())));
++row;
}
}
add_rows(m_selected_device->Outputs());
}
void IOWindow::UpdateDeviceList()

View File

@ -125,6 +125,11 @@ bool Device::Control::IsMatchingName(std::string_view name) const
return GetName() == name;
}
bool Device::Control::IsHidden() const
{
return false;
}
ControlState Device::FullAnalogSurface::GetState() const
{
return (1 + std::max(0.0, m_high.GetState()) - std::max(0.0, m_low.GetState())) / 2;
@ -141,6 +146,11 @@ bool Device::FullAnalogSurface::IsDetectable() const
return m_low.IsDetectable() && m_high.IsDetectable();
}
bool Device::FullAnalogSurface::IsHidden() const
{
return m_low.IsHidden() && m_high.IsHidden();
}
bool Device::FullAnalogSurface::IsMatchingName(std::string_view name) const
{
if (Control::IsMatchingName(name))

View File

@ -64,6 +64,10 @@ public:
// May be overridden to allow multiple valid names.
// Useful for backwards-compatible configurations when names change.
virtual bool IsMatchingName(std::string_view name) const;
// May be overridden to hide in UI.
// Useful for backwards-compatible configurations when names change.
virtual bool IsHidden() const;
};
//
@ -164,6 +168,7 @@ protected:
ControlState GetState() const override;
std::string GetName() const override;
bool IsDetectable() const override;
bool IsHidden() const override;
bool IsMatchingName(std::string_view name) const override;
private: