some tweaks to the models in rust
This commit is contained in:
parent
ab168af16f
commit
020e812bce
2 changed files with 33 additions and 3 deletions
|
@ -158,8 +158,7 @@ mod image_model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
fn add_item(
|
||||||
pub fn add_item(
|
|
||||||
mut self: Pin<&mut Self>,
|
mut self: Pin<&mut Self>,
|
||||||
image_id: i32,
|
image_id: i32,
|
||||||
image_title: QString,
|
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]
|
#[qinvokable]
|
||||||
pub fn get_item(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant {
|
pub fn get_item(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant {
|
||||||
println!("{index}");
|
println!("{index}");
|
||||||
|
|
|
@ -191,6 +191,9 @@ mod video_model {
|
||||||
id.eq(&video_id),
|
id.eq(&video_id),
|
||||||
title.eq(&video_title.to_string()),
|
title.eq(&video_title.to_string()),
|
||||||
path.eq(&video_path.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);
|
.execute(db);
|
||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
|
@ -202,7 +205,9 @@ mod video_model {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
println!("Cannot connect to database");
|
println!(
|
||||||
|
"Cannot connect to database or there was an error in inserting the video"
|
||||||
|
);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue