From 020e812bceb98b44649b11a288fc2dff634cfba2 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sat, 15 Apr 2023 14:37:53 -0500 Subject: [PATCH] some tweaks to the models in rust --- src/rust/image_model.rs | 29 +++++++++++++++++++++++++++-- src/rust/video_model.rs | 7 ++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/rust/image_model.rs b/src/rust/image_model.rs index ee90a71..fe53552 100644 --- a/src/rust/image_model.rs +++ b/src/rust/image_model.rs @@ -158,8 +158,7 @@ mod image_model { } } - #[qinvokable] - pub fn add_item( + fn add_item( mut self: Pin<&mut Self>, image_id: i32, image_title: QString, @@ -229,6 +228,32 @@ mod image_model { } } + #[qinvokable] + pub fn update_file_path( + mut self: Pin<&mut Self>, + index: i32, + updated_file_path: QString, + ) -> bool { + let mut vector_roles = QVector_i32::default(); + vector_roles.append(self.as_ref().get_role(Role::PathRole)); + let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); + + let db = &mut self.as_mut().get_db(); + let result = update(images.filter(id.eq(index))) + .set(path.eq(updated_file_path.to_string())) + .execute(db); + match result { + Ok(_i) => { + let image = self.as_mut().images_mut().get_mut(index as usize).unwrap(); + image.path = updated_file_path; + self.as_mut() + .emit_data_changed(model_index, model_index, &vector_roles); + true + } + Err(_e) => false, + } + } + #[qinvokable] pub fn get_item(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant { println!("{index}"); diff --git a/src/rust/video_model.rs b/src/rust/video_model.rs index f7f6b16..96f6225 100644 --- a/src/rust/video_model.rs +++ b/src/rust/video_model.rs @@ -191,6 +191,9 @@ mod video_model { id.eq(&video_id), title.eq(&video_title.to_string()), path.eq(&video_path.to_string()), + start_time.eq(&video.start_time), + end_time.eq(&video.end_time), + looping.eq(&video.looping), )) .execute(db); println!("{:?}", result); @@ -202,7 +205,9 @@ mod video_model { true } Err(_e) => { - println!("Cannot connect to database"); + println!( + "Cannot connect to database or there was an error in inserting the video" + ); false } }