Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit 5d83fec

Browse files
committed
Fix controls importing on auto value
1 parent 2a587d4 commit 5d83fec

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

src/drivers/imager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ void Imager::import_controls(const QVariantList& controls, bool by_id)
6363
Control changed = control;
6464
qDebug() << "Importing control: " << control.id << ", " << control.name;
6565
changed.import(controls_mapped[key]);
66-
if(! changed.same_value(control))
66+
if(! changed.same_value(control)) {
67+
qDebug() << "control " << control << " has changed to " << changed;
6768
changed_controls.push_back(changed);
69+
}
6870
}
6971
}
7072
setControls(changed_controls);

src/drivers/imagercontrol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool Imager::Control::valid() const
5757
bool Imager::Control::same_value(const Imager::Control& other) const
5858
{
5959
if(supports_auto && (value_auto || other.value_auto) ) {
60-
qDebug() << "comparing auto values only";
60+
qDebug() << "comparing auto values only for control " << name << "[" << id << "]";
6161
return other.value_auto == value_auto;
6262
}
6363
return value == other.value;
@@ -96,6 +96,7 @@ QVariantMap Imager::Control::asMap() const
9696
void Imager::Control::import(const QVariantMap& data, bool full_import)
9797
{
9898
value = data["value"];
99+
value_auto = data["auto"].toBool();
99100
if(!full_import)
100101
return;
101102
name = data["name"].toString();
@@ -108,5 +109,4 @@ void Imager::Control::import(const QVariantMap& data, bool full_import)
108109
{"duration", [&]{ type = Number; is_duration = true; } },
109110
};
110111
types_map[data["type"].toString()]();
111-
value_auto = data["auto"].toBool();
112112
}

src/widgets/cameracontrolswidget.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class CameraControl : public QObject {
6666
ControlWidget *control_widget;
6767
QCheckBox *auto_value_widget;
6868
QLabel *control_changed_led;
69+
private slots:
70+
void auto_changed(bool isAuto);
6971
signals:
7072
void changed();
7173
};
@@ -98,18 +100,23 @@ CameraControl::CameraControl(const Imager::Control& control, Imager* imager, QWi
98100
new_value.value = v;
99101
emit changed();
100102
});
101-
connect(auto_value_widget, &QCheckBox::toggled, this, [this](bool checked) {
102-
new_value.value_auto = checked;
103-
if(! checked)
104-
new_value.value = control_widget->value();
105-
control_widget->setEnabled(!checked);
106-
emit changed();
107-
});
103+
connect(auto_value_widget, &QCheckBox::toggled, this, &CameraControl::auto_changed);
108104

109105
control_widget->setEnabled(!control.readonly && ! control.value_auto);
110106
connect(imager, &Imager::changed, this, &CameraControl::control_updated, Qt::QueuedConnection);
111107
}
112108

109+
void CameraControl::auto_changed(bool isAuto)
110+
{
111+
new_value.value_auto = isAuto;
112+
if(! isAuto)
113+
new_value.value = control_widget->value();
114+
control_widget->setEnabled(!isAuto);
115+
auto_value_widget->setChecked(isAuto);
116+
emit changed();
117+
}
118+
119+
113120
void CameraControl::importing(const QVariantList& controls)
114121
{
115122
auto found = find_if(controls.begin(), controls.end(), [this](const QVariant &v){ return v.toMap()["id"].toLongLong() == control.id; });
@@ -134,6 +141,9 @@ void CameraControl::control_updated(const Imager::Control& changed_control)
134141
control = changed_control;
135142
new_value = control;
136143
control_widget->update(changed_control);
144+
if(changed_control.supports_auto) {
145+
auto_changed(changed_control.value_auto);
146+
}
137147
control_changed_led->setPixmap(is_expected_value ? green_dot : red_dot);
138148
control_changed_led->show();
139149
QTimer::singleShot(5000, this, [this]{ control_changed_led->hide(); });

0 commit comments

Comments
 (0)