the moving of rows works but resets on move
This breaks fluid movements from QML with KirigamiDragHandles We will need to adjust how this move works in QML or get the begin_move_rows function to build. If it can build we can still use the KirigamiDragHandles.
This commit is contained in:
parent
fe25209758
commit
c57f9f8ac9
3 changed files with 69 additions and 12 deletions
|
@ -322,20 +322,63 @@ mod service_item_model {
|
|||
dest_index: i32,
|
||||
count: i32,
|
||||
) -> bool {
|
||||
todo!();
|
||||
let model_index =
|
||||
self.index(source_index, 0, &QModelIndex::default());
|
||||
let parent = model_index.parent();
|
||||
let source_id = source_index as usize;
|
||||
let dest_id = dest_index as usize;
|
||||
let count = count as usize;
|
||||
let end_service_item = source_id + count - 1;
|
||||
|
||||
println!("rust-end-service_item: {:?}", end_service_item);
|
||||
println!("rust-dest-service_item: {:?}", dest_index);
|
||||
unsafe {
|
||||
// this function doesn't build
|
||||
// self.as_mut().begin_move_rows(
|
||||
// &parent,
|
||||
// source_index,
|
||||
// source_index + count - 1,
|
||||
// &parent,
|
||||
// dest_index,
|
||||
// );
|
||||
self.as_mut().begin_reset_model();
|
||||
|
||||
if source_id < dest_id {
|
||||
let move_amount = dest_id - source_id - count + 1;
|
||||
self.as_mut().service_items_mut()
|
||||
[source_id..=dest_id]
|
||||
.rotate_right(move_amount);
|
||||
println!("rust-move_amount: {:?}", move_amount);
|
||||
} else {
|
||||
let move_amount =
|
||||
end_service_item - dest_id - count + 1;
|
||||
println!("rust-move_amount: {:?}", move_amount);
|
||||
self.as_mut().service_items_mut()
|
||||
[dest_id..=end_service_item]
|
||||
.rotate_left(move_amount);
|
||||
}
|
||||
|
||||
// this function works, begin does not
|
||||
// self.as_mut().end_move_rows();
|
||||
self.as_mut().end_reset_model();
|
||||
let item = self.as_mut().get_item(dest_index);
|
||||
self.as_mut().emit_item_moved(
|
||||
&source_index,
|
||||
&dest_index,
|
||||
&item,
|
||||
);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn move_up(mut self: Pin<&mut Self>, index: i32) -> bool {
|
||||
todo!();
|
||||
pub fn move_up(self: Pin<&mut Self>, index: i32) -> bool {
|
||||
self.move_rows(index, index - 1, 1)
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn move_down(
|
||||
mut self: Pin<&mut Self>,
|
||||
index: i32,
|
||||
) -> bool {
|
||||
todo!();
|
||||
pub fn move_down(self: Pin<&mut Self>, index: i32) -> bool {
|
||||
self.move_rows(index, index + 1, 1)
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
|
@ -904,6 +947,20 @@ mod service_item_model {
|
|||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
);
|
||||
|
||||
// cxx-qt can't build this function for some reason
|
||||
// unsafe fn begin_move_rows(
|
||||
// self: Pin<&mut qobject::ServiceItemMod>,
|
||||
// source_parent: &QModelIndex,
|
||||
// source_first: i32,
|
||||
// source_last: i32,
|
||||
// destination_parent: &QModelIndex,
|
||||
// destination_child: i32,
|
||||
// );
|
||||
|
||||
unsafe fn end_move_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
);
|
||||
|
||||
unsafe fn begin_remove_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
parent: &QModelIndex,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue