diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-09-02 18:26:45 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-09-02 18:26:45 +0800 |
| commit | f7a43077fe4e139dd7e3f46f448e0951740ec148 (patch) | |
| tree | f6a68248fe42bd899e99049bab7fdb7e5d26ea60 /qml_plugin/src/launcher/mathcalc.rs | |
| parent | 2f7576faf493b4667b02dcb60ddbf3aa0a9f654b (diff) | |
fix: qmlfmt
IListView: animation
Diffstat (limited to 'qml_plugin/src/launcher/mathcalc.rs')
| -rw-r--r-- | qml_plugin/src/launcher/mathcalc.rs | 86 |
1 files changed, 27 insertions, 59 deletions
diff --git a/qml_plugin/src/launcher/mathcalc.rs b/qml_plugin/src/launcher/mathcalc.rs index d29239e..601dc3b 100644 --- a/qml_plugin/src/launcher/mathcalc.rs +++ b/qml_plugin/src/launcher/mathcalc.rs @@ -22,9 +22,7 @@ mod qobject { #[qobject] #[qml_element] #[qml_singleton] - #[qproperty( - QVariant, result - )] + #[qproperty(QVariant, result)] type MathCalc = super::MathCalcRs; #[qinvokable] @@ -63,61 +61,34 @@ impl Default for MathCalcRs { impl qobject::MathCalc { fn query(mut self: Pin<&mut Self>, input: QString) { let qt_thread = self.qt_thread(); - let ctx = Arc::clone( - &self - .as_mut() - .rust_mut() - .ctx, - ); + let ctx = Arc::clone(&self.as_mut().rust_mut().ctx); // TODO: consider moving to spawn_blocking - self.rust_mut() - .executor - .spawn( - async move { - let input = input.to_string(); - let result = parser::eval( - &mut *ctx - .lock() - .await, - &input, - // TODO: move to const/config - 53, - ) - .map_or_default( - |r| { - r.map_or_default( - |r| { - let r: QString = r - // to display scientific notation properly - // other ones show both version without e or shows *10^_ - // and have a = prefix - // to_string_big will result in 1/2=5.0000000000000000e − 1 - .to_string() - .into(); - if r != input.into() { - QVariant::from(&r) - } else { - QVariant::default() - } - }, - ) - }, - ); - _ = qt_thread - .queue( - |mut qo| { - qo.as_mut() - .set_result(result) - }, - ) - .unwrap_print(); - }, - ); + self.rust_mut().executor.spawn(async move { + let input = input.to_string(); + let result = parser::eval( + &mut *ctx.lock().await, + &input, + // TODO: move to const/config + 53, + ) + .map_or_default(|r| { + r.map_or_default(|r| { + let r: QString = r + // to display scientific notation properly + // other ones show both version without e or shows *10^_ + // and have a = prefix + // to_string_big will result in 1/2=5.0000000000000000e − 1 + .to_string() + .into(); + if r != input.into() { QVariant::from(&r) } else { QVariant::default() } + }) + }); + _ = qt_thread.queue(|mut qo| qo.as_mut().set_result(result)).unwrap_print(); + }); } fn reset(mut self: Pin<&mut Self>) { - self.as_mut() - .reset_result(); + self.as_mut().reset_result(); self.reset_ctx(); } @@ -126,13 +97,10 @@ impl qobject::MathCalc { } fn reset_ctx(mut self: Pin<&mut Self>) { - self.as_mut() - .rust_mut() - .ctx = Arc::new(Mutex::new(Self::new_ctx())) + self.as_mut().rust_mut().ctx = Arc::new(Mutex::new(Self::new_ctx())) } fn reset_result(mut self: Pin<&mut Self>) { - self.as_mut() - .set_result(QVariant::default()) + self.as_mut().set_result(QVariant::default()) } } |
