QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
BatteryIndicatorSettings.cc
Go to the documentation of this file.
2
3#include <QSettings>
4
5DECLARE_SETTINGGROUP(BatteryIndicator, "BatteryIndicator")
6{
7}
8
10DECLARE_SETTINGSFACT(BatteryIndicatorSettings, consolidateMultipleBatteries)
11
13{
14 if (!_threshold1Fact) {
15 _threshold1Fact = _createSettingsFact(threshold1Name);
16 connect(_threshold1Fact, &SettingsFact::rawValueChanged, this, &BatteryIndicatorSettings::_threshold1Changed);
17 }
18 return _threshold1Fact;
19}
20
22{
23 if (!_threshold2Fact) {
24 _threshold2Fact = _createSettingsFact(threshold2Name);
25 connect(_threshold2Fact, &SettingsFact::rawValueChanged, this, &BatteryIndicatorSettings::_threshold2Changed);
26 }
27 return _threshold2Fact;
28}
29
30// Change handlers for thresholds
31void BatteryIndicatorSettings::_threshold1Changed() {
32 validateThreshold1(); // Call validation when threshold1 value changes
33}
34
35void BatteryIndicatorSettings::_threshold2Changed() {
36 validateThreshold2(); // Call validation when threshold2 value changes
37}
38
39// Validate threshold1 value
40void BatteryIndicatorSettings::validateThreshold1() {
41 int value = threshold1()->rawValue().toInt();
42 setThreshold1(value); // Call the setter with the current value
43}
44
45// Validate threshold2 value
46void BatteryIndicatorSettings::validateThreshold2() {
47 int value = threshold2()->rawValue().toInt();
48 setThreshold2(value); // Call the setter with the current value
49}
50
51// Set threshold1 with validation
53 // Ensure value is at least 16 and less than 100
54 if (value < 16) {
55 threshold1()->setRawValue(17); // Adjust to minimum valid value
56 } else if (value > 99) {
57 threshold1()->setRawValue(99); // Cap at maximum valid value
58 } else {
59 // Check if value is greater than threshold2
60 if (value > threshold2()->rawValue().toInt()) {
61 threshold1()->setRawValue(value);
62 } else {
63 // Ensure threshold1 is greater than threshold2
64 threshold1()->setRawValue(threshold2()->rawValue().toInt() + 1);
65 }
66 }
67}
68
69// Set threshold2 with validation
71 // Ensure value is greater than 15
72 if (value <= 15) {
73 threshold2()->setRawValue(16); // Adjust to the minimum valid value
74 return;
75 }
76
77 // Check if value is less than threshold1
78 if (value < threshold1()->rawValue().toInt()) {
79 threshold2()->setRawValue(value);
80 } else {
81 // Ensure threshold2 is less than threshold1
82 threshold2()->setRawValue(threshold1()->rawValue().toInt() - 1);
83 }
84}
#define DECLARE_SETTINGSFACT_NO_FUNC(CLASS, NAME)
#define DECLARE_SETTINGSFACT(CLASS, NAME)
#define DECLARE_SETTINGGROUP(NAME, GROUP)
Fact *threshold2 READ threshold2 CONSTANT Fact * threshold2()
Fact *threshold1 READ threshold1 CONSTANT Fact * threshold1()
void rawValueChanged(const QVariant &value)