From 79af63545a87f98a1cbaac048aba06a49abcf762 Mon Sep 17 00:00:00 2001 From: Jasem Mutlaq Date: Fri, 30 Aug 2024 12:49:47 +0300 Subject: [PATCH] Add isSwitchOn and findOnSwitchName convenience functions --- .../property/indipropertyswitch.cpp | 14 +++++++++++++- libs/indidevice/property/indipropertyswitch.h | 2 ++ libs/indidevice/property/indipropertyview.h | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/libs/indidevice/property/indipropertyswitch.cpp b/libs/indidevice/property/indipropertyswitch.cpp index f4e2a9c863..05e7a4788f 100644 --- a/libs/indidevice/property/indipropertyswitch.cpp +++ b/libs/indidevice/property/indipropertyswitch.cpp @@ -52,19 +52,31 @@ int PropertySwitch::findOnSwitchIndex() const return d->typedProperty.findOnSwitchIndex(); } +std::string PropertySwitch::findOnSwitchName() const +{ + D_PTR(const PropertySwitch); + return d->typedProperty.findOnSwitchName(); +} + INDI::WidgetViewSwitch *PropertySwitch::findOnSwitch() const { D_PTR(const PropertySwitch); return d->typedProperty.findOnSwitch(); } +bool PropertySwitch::isSwitchOn(const std::string &name) const +{ + D_PTR(const PropertySwitch); + return d->typedProperty.isSwitchOn(name); +} + bool PropertySwitch::update(const ISState states[], const char * const names[], int n) { D_PTR(PropertySwitch); if (d->onNewValuesCallback) { NewValues newValues; - for (int i=0; i public: void reset(); int findOnSwitchIndex() const; + std::string findOnSwitchName() const; INDI::WidgetViewSwitch *findOnSwitch() const; + bool isSwitchOn(const std::string &name) const; public: void setRule(ISRule rule); diff --git a/libs/indidevice/property/indipropertyview.h b/libs/indidevice/property/indipropertyview.h index f87cdde906..edbf06dba9 100644 --- a/libs/indidevice/property/indipropertyview.h +++ b/libs/indidevice/property/indipropertyview.h @@ -142,12 +142,29 @@ struct PropertyView: PROPERTYVIEW_BASE_ACCESS WidgetTraits::PropertyType return static_cast(IUFindOnSwitch(this)); } + template = true> + bool isSwitchOn(const std::string &name) const + { + auto onSwitch = findOnSwitch(); + return (onSwitch && onSwitch->isNameMatch(name)); + } + template = true> int findOnSwitchIndex() const { return IUFindOnSwitchIndex(this); } + template = true> + std::string findOnSwitchName() const + { + auto onSwitch = findOnSwitch(); + if (onSwitch) + return onSwitch->getName(); + else + return std::string(); + } + public: // only for INumber template = true> void updateMinMax(); /* outside implementation - only driver side, see indipropertyview_driver.cpp */ @@ -472,7 +489,7 @@ struct WidgetView: PROPERTYVIEW_BASE_ACCESS IText { return getLabel() == otherLabel; } - + bool isEmpty() const { return getText()[0] == '\0';