diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-08-03 18:22:04 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-08-04 23:07:47 +0800 |
| commit | 029ff8999a5d3c1613302b805228cd6927b4dddb (patch) | |
| tree | 24b768bf3ed8aabad6ae3ff1d5322b60722fffef | |
| parent | 345c9344a37740fd084bf310be6e56e483c86d5e (diff) | |
qml: reset component when current state broke via new input
| -rw-r--r-- | popups/launcher/components/Calc.qml | 4 | ||||
| -rw-r--r-- | popups/launcher/components/ISmartCalc.qml | 6 | ||||
| -rw-r--r-- | qml_plugin/src/launcher/mathcalc.rs | 10 | ||||
| -rw-r--r-- | qml_plugin/src/launcher/smartcalc.rs | 11 |
4 files changed, 27 insertions, 4 deletions
diff --git a/popups/launcher/components/Calc.qml b/popups/launcher/components/Calc.qml index 6a88c9f..64cde8c 100644 --- a/popups/launcher/components/Calc.qml +++ b/popups/launcher/components/Calc.qml @@ -18,6 +18,10 @@ IComponent { } } + onInputChanged: { + MathCalc.reset_result(); + } + process: function () { MathCalc.query(input); const valid = MathCalc.result && MathCalc.result.length > 0; diff --git a/popups/launcher/components/ISmartCalc.qml b/popups/launcher/components/ISmartCalc.qml index 02b234a..2c31f88 100644 --- a/popups/launcher/components/ISmartCalc.qml +++ b/popups/launcher/components/ISmartCalc.qml @@ -21,8 +21,12 @@ IComponent { } } + onInputChanged: { + SmartCalc.reset_result(); + } + process: function () { - SmartCalc.query(input); + SmartCalc.query(input); const answer = SmartCalc.result; // TODO: use answer property rn its circular dependent since it has to be valid which is the line below const valid = SmartCalc.result && SmartCalc.result.length > 0 && category; diff --git a/qml_plugin/src/launcher/mathcalc.rs b/qml_plugin/src/launcher/mathcalc.rs index 626b970..4ac625d 100644 --- a/qml_plugin/src/launcher/mathcalc.rs +++ b/qml_plugin/src/launcher/mathcalc.rs @@ -34,6 +34,9 @@ mod qobject { #[qinvokable] fn reset_ctx(self: Pin<&mut MathCalc>); + + #[qinvokable] + fn reset_result(self: Pin<&mut MathCalc>); } impl cxx_qt::Threading for MathCalc {} @@ -95,7 +98,7 @@ impl qobject::MathCalc { fn reset(mut self: Pin<&mut Self>) { self.as_mut() - .set_result(QVariant::default()); + .reset_result(); self.reset_ctx(); } @@ -105,4 +108,9 @@ impl qobject::MathCalc { .ctx = Arc::new(Mutex::new(parser::Context::default().set_angle_unit(DEFAULT_ANGLE_UNIT))); } + + fn reset_result(mut self: Pin<&mut Self>) { + self.as_mut() + .set_result(QVariant::default()) + } } diff --git a/qml_plugin/src/launcher/smartcalc.rs b/qml_plugin/src/launcher/smartcalc.rs index eee975d..9e94f77 100644 --- a/qml_plugin/src/launcher/smartcalc.rs +++ b/qml_plugin/src/launcher/smartcalc.rs @@ -35,6 +35,9 @@ mod qobject { #[qinvokable] fn reset(self: Pin<&mut SmartCalc>); + + #[qinvokable] + fn reset_result(self: Pin<&mut SmartCalc>); } impl cxx_qt::Threading for SmartCalc {} @@ -128,10 +131,14 @@ impl qobject::SmartCalc { fn reset(mut self: Pin<&mut Self>) { self.as_mut() + .set_cached_query(QVariant::default()); + self.reset_result(); + } + + fn reset_result(mut self: Pin<&mut Self>) { + self.as_mut() .set_result(QVariant::default()); self.as_mut() .set_result_type(qobject::ResultType::Unset); - self.as_mut() - .set_cached_query(QVariant::default()); } } |
