diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-08-03 20:11:48 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-08-04 23:07:51 +0800 |
| commit | f36d416853696b103934b56ee57118c733191dfa (patch) | |
| tree | 29c824be162d51dffcbbb35137dcd4596d7a15bd /qml_plugin/src/launcher/smartcalc.rs | |
| parent | 029ff8999a5d3c1613302b805228cd6927b4dddb (diff) | |
feat: make use of ExclusiveExecutor
mathcalc: use to_string_big()
// to display scientific notation properly
// other ones show both version without e or shows *10^_
// and have a = prefix
unwrap_print queueing to qt main thread
Diffstat (limited to 'qml_plugin/src/launcher/smartcalc.rs')
| -rw-r--r-- | qml_plugin/src/launcher/smartcalc.rs | 88 |
1 files changed, 48 insertions, 40 deletions
diff --git a/qml_plugin/src/launcher/smartcalc.rs b/qml_plugin/src/launcher/smartcalc.rs index 9e94f77..98cb037 100644 --- a/qml_plugin/src/launcher/smartcalc.rs +++ b/qml_plugin/src/launcher/smartcalc.rs @@ -1,8 +1,9 @@ -use cxx_qt::Threading; +use cxx_qt::{CxxQtType, Threading}; use cxx_qt_lib::{QString, QVariant}; use std::pin::Pin; +use unwrap_print::PrintableResult; -use crate::RUNTIME; +use crate::{ExclusiveExecutor, RUNTIME}; #[cxx_qt::bridge] mod qobject { @@ -79,6 +80,8 @@ pub struct SmartCalcRs { result_type: qobject::ResultType, cached_query: QVariant, + + executor: ExclusiveExecutor, } impl qobject::SmartCalc { @@ -89,44 +92,49 @@ impl qobject::SmartCalc { self.as_mut() .set_cached_query((&input.clone()).into()); let qt_thread = self.qt_thread(); - RUNTIME.spawn( - async move { - let result = smart_calculator::calculate( - &input.to_string(), - None, - ) - .await; - qt_thread.queue( - |mut qo| { - qo.as_mut() - .set_result_type( - match &result { - Ok(value) => (&value.res_type).into(), - Err(_) => qobject::ResultType::Unset, - }, - ); - qo.as_mut() - .set_result( - // TODO: do the calc outside of ts main qt ui render thread.(all - // *.rs) - match result { - Ok(value) => { - if value.formatted == value.input { - QVariant::default() - } else { - let result: QString = value - .formatted - .into(); - QVariant::from(&result) - } - } - Err(_) => QVariant::default(), - }, - ) - }, - ) - }, - ); + self.as_mut() + .rust_mut() + .executor + .spawn( + async move { + let result = smart_calculator::calculate( + &input.to_string(), + None, + ) + .await; + qt_thread + .queue( + |mut qo| { + qo.as_mut() + .set_result_type( + match &result { + Ok(value) => (&value.res_type).into(), + Err(_) => qobject::ResultType::Unset, + }, + ); + qo.as_mut() + .set_result( + // TODO: do the calc outside of ts main qt ui render + // thread.(all *.rs) + match result { + Ok(value) => { + if value.formatted == value.input { + QVariant::default() + } else { + let result: QString = value + .formatted + .into(); + QVariant::from(&result) + } + } + Err(_) => QVariant::default(), + }, + ) + }, + ) + .unwrap_print(); + }, + ); } fn reset(mut self: Pin<&mut Self>) { |
