Skip to content

Commit 123b66e

Browse files
committed
Switches: update colour wheel preset format
Store presets as a single list of 9*5 doubles for each output type, rather than as nine individual setting paths with five preset values each. Contributes to #2534
1 parent 2049b24 commit 123b66e

File tree

4 files changed

+37
-43
lines changed

4 files changed

+37
-43
lines changed

components/dialogs/ColorWheelDialog.qml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ ModalDialog {
180180

181181
ColorPresetModel {
182182
id: rgbPresetModel
183-
settingUid: Global.systemSettings.serviceUid + "/Settings/Gui2/SwitchPane/Preset/RGB"
183+
settingUid: Global.systemSettings.serviceUid + "/Settings/Gui2/Switchpane/Preset/RGB"
184184
}
185185
ColorPresetModel {
186186
id: rgbWPresetModel
187-
settingUid: Global.systemSettings.serviceUid + "/Settings/Gui2/SwitchPane/Preset/RGBW"
187+
settingUid: Global.systemSettings.serviceUid + "/Settings/Gui2/Switchpane/Preset/RGBW"
188188
}
189189
ColorPresetModel {
190190
id: cctPresetModel
191-
settingUid: Global.systemSettings.serviceUid + "/Settings/Gui2/SwitchPane/Preset/CCT"
191+
settingUid: Global.systemSettings.serviceUid + "/Settings/Gui2/Switchpane/Preset/CCT"
192192
}
193193
}
194194

components/switches/delegates/SwitchableOutputCardDelegate_color.qml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,6 @@ FocusScope {
9999
uid: root.switchableOutput.uid + "/ValidTypes"
100100
}
101101

102-
// TODO remove these /Preset/* items - these add dummy presets that will actually
103-
// provided by the default settings on the system.
104-
VeQuickItem {
105-
uid: Global.systemSettings.serviceUid + "/Settings/Gui2/SwitchPane/Preset/RGB/0"
106-
Component.onCompleted: setValue([96, 89, 82, 0, 0 ]) // green
107-
}
108-
VeQuickItem {
109-
uid: Global.systemSettings.serviceUid + "/Settings/Gui2/SwitchPane/Preset/CCT/0"
110-
Component.onCompleted: setValue([210, 29, 93, 0, 4700 ]) // light blue
111-
}
112-
VeQuickItem {
113-
uid: Global.systemSettings.serviceUid + "/Settings/Gui2/SwitchPane/Preset/RGBW/0"
114-
Component.onCompleted: setValue([57, 100, 100, 0, 0 ]) // yellow
115-
}
116-
117102
Component {
118103
id: colorDialogComponent
119104

data/mock/conf/services/switch-controls-tester.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,5 +525,10 @@
525525
"/SwitchableOutput/color_dimmer_rgbw/Settings/ValidFunctions": 2,
526526
"/SwitchableOutput/color_dimmer_rgbw/State": 1,
527527
"/SwitchableOutput/color_dimmer_rgbw/Status": 9
528+
},
529+
"com.victronenergy.settings": {
530+
"/Settings/Gui2/Switchpane/Preset/RGB": [96,89,82,0,0,210,29,93,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
531+
"/Settings/Gui2/Switchpane/Preset/RGBW": [57,100,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
532+
"/Settings/Gui2/Switchpane/Preset/CCT": [210,29,93,0,4700,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
528533
}
529534
}

src/colordimmerdata.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ void getStorageColorData(const QVariantList &colorData, QColor *color, qreal *wh
4040
const qreal h = variantToReal(colorData.value(0));
4141
const qreal s = variantToReal(colorData.value(1));
4242
const qreal v = variantToReal(colorData.value(2));
43-
color->setHsvF(FastUtils::create()->scaleNumber(h, 0, 359, 0, 1), s / 100, v / 100);
43+
if (h == 0 && s == 0 && v == 0) {
44+
*color = QColor();
45+
} else {
46+
color->setHsvF(FastUtils::create()->scaleNumber(h, 0, 359, 0, 1), s / 100, v / 100);
47+
}
4448
}
4549
if (white) {
4650
*white = variantToReal(colorData.value(3));
@@ -51,11 +55,17 @@ void getStorageColorData(const QVariantList &colorData, QColor *color, qreal *wh
5155
}
5256
void addStorageColorData(QList<double> *colorData, const QColor color, qreal white, qreal colorTemperature)
5357
{
54-
float h, s, v;
55-
color.getHsvF(&h, &s, &v);
56-
colorData->append(FastUtils::create()->scaleNumber(h, 0, 1, 0, 359));
57-
colorData->append(s * 100);
58-
colorData->append(v * 100);
58+
if (color.isValid()) {
59+
float h, s, v;
60+
color.getHsvF(&h, &s, &v);
61+
colorData->append(FastUtils::create()->scaleNumber(h, 0, 1, 0, 359));
62+
colorData->append(s * 100);
63+
colorData->append(v * 100);
64+
} else {
65+
colorData->append(0);
66+
colorData->append(0);
67+
colorData->append(0);
68+
}
5969
colorData->append(white);
6070
colorData->append(colorTemperature);
6171
}
@@ -286,18 +296,12 @@ void ColorPresetModel::save()
286296
return;
287297
}
288298

299+
QList<double> colorData;
289300
for (int i = 0; i < m_colors.count(); ++i) {
290-
if (VeQItem *presetItem = m_settingItem->itemGetOrCreate(QString::number(i))) {
291-
const ColorInfo &info = m_colors.at(i);
292-
if (info.color.isValid()) {
293-
QList<double> colorData;
294-
::addStorageColorData(&colorData, info.color, info.white, info.colorTemperature);
295-
presetItem->setValue(QVariant::fromValue(colorData));
296-
} else {
297-
presetItem->setValue(QVariant());
298-
}
299-
}
301+
const ColorInfo &info = m_colors.at(i);
302+
::addStorageColorData(&colorData, info.color, info.white, info.colorTemperature);
300303
}
304+
m_settingItem->setValue(QVariant::fromValue(colorData));
301305
}
302306

303307
void ColorPresetModel::reload()
@@ -317,20 +321,20 @@ void ColorPresetModel::reload()
317321
emit countChanged();
318322
}
319323

320-
static const int presetCount = 9;
321-
beginInsertRows(QModelIndex(), 0, presetCount - 1);
322-
for (int i = 0; i < presetCount; ++i) {
324+
// Expect 9 groups of presets, where each preset is made up of 5 values
325+
static const int valuesPerPreset = 5;
326+
static const int presetGroupCount = 9;
327+
QVariantList colorData = m_settingItem->getValue().toList();
328+
beginInsertRows(QModelIndex(), 0, presetGroupCount - 1);
329+
for (int presetGroupIndex = 0; presetGroupIndex < presetGroupCount; ++presetGroupIndex) {
323330
QColor color;
324331
qreal white = 0;
325332
qreal colorTemperature = 0;
326-
if (VeQItem *presetItem = m_settingItem->itemGet(QString::number(i))) {
327-
const QVariantList colorData = presetItem->getValue().toList();
328-
if (!colorData.isEmpty()) {
329-
::getStorageColorData(colorData, &color, &white, &colorTemperature);
330-
}
331-
}
333+
::getStorageColorData(colorData.mid(presetGroupIndex * valuesPerPreset, valuesPerPreset),
334+
&color, &white, &colorTemperature);
332335
m_colors.append({ color, white, colorTemperature });
333336
}
337+
334338
endInsertRows();
335339
emit countChanged();
336340
}

0 commit comments

Comments
 (0)