Trying to tweak the image_model for a better count function

Apparently there is a bug in the way these functions are called from
QML so we aren't getting the count of items in the library. All other
functions seem to be working but not this, so I tried a property and
the same situation...
This commit is contained in:
Chris Cochrun 2023-04-19 14:16:38 -05:00
parent 3ce236aefe
commit 270cb67570

View file

@ -39,6 +39,8 @@ mod image_model {
#[cxx_qt::qobject(base = "QAbstractListModel")]
#[derive(Default, Debug)]
pub struct ImageModel {
#[qproperty]
count_rows: i32,
highest_id: i32,
images: Vec<self::Image>,
}
@ -355,13 +357,16 @@ mod image_model {
#[qinvokable(cxx_override)]
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
let cnt = self.rust().images.len() as i32;
// self.as_mut().set_count(cnt);
// println!("row count is {cnt}");
cnt
}
#[qinvokable]
pub fn count(&self) -> i32 {
self.rust().images.len() as i32
pub fn count(mut self: Pin<&mut Self>) -> i32 {
let cnt = self.rust().images.len() as i32;
self.as_mut().set_count_rows(cnt);
cnt
}
}
}