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:
Chris Cochrun 2023-09-17 14:35:37 -05:00
parent fe25209758
commit c57f9f8ac9
3 changed files with 69 additions and 12 deletions

View file

@ -115,7 +115,7 @@ Kirigami.ApplicationWindow {
Controls.Label { Controls.Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
Layout.rightMargin: Kirigami.Units.smallSpacing * 2 Layout.rightMargin: Kirigami.Units.smallSpacing * 2
text: "Total Service Items: " + ServiceItemModel.rowCount() text: "Total Service Items: " + ServiceItemModel.count()
} }
Controls.Label { Controls.Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight

View file

@ -382,10 +382,10 @@ Item {
contextType: "2d" contextType: "2d"
renderStrategy: Canvas.Threaded renderStrategy: Canvas.Threaded
onPaint: { onPaint: {
console.log(Kirigami.Theme.hoverColor.name()); console.log(Kirigami.Theme.hoverColor);
var ctx = getContext("2d"); var ctx = getContext("2d");
ctx.fillRule = Qt.OddEvenFill ctx.fillRule = Qt.OddEvenFill
ctx.fillStyle = Kirigami.Theme.hoverColor.rgb(); ctx.fillStyle = Kirigami.Theme.hoverColor;
ctx.rotate(30); ctx.rotate(30);
ctx.transform(0.8, 0, 0, 0.8, 0, 30) ctx.transform(0.8, 0, 0, 0.8, 0, 30)
ctx.path = tearDropPath; ctx.path = tearDropPath;
@ -452,7 +452,7 @@ Item {
id: serviceToolBar id: serviceToolBar
Layout.fillWidth: true Layout.fillWidth: true
opacity: 1.0 opacity: 1.0
display: Button.IconOnly display: Controls.Button.IconOnly
actions: [ actions: [
Kirigami.Action { Kirigami.Action {
text: "Up" text: "Up"

View file

@ -322,20 +322,63 @@ mod service_item_model {
dest_index: i32, dest_index: i32,
count: i32, count: i32,
) -> bool { ) -> 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] #[qinvokable]
pub fn move_up(mut self: Pin<&mut Self>, index: i32) -> bool { pub fn move_up(self: Pin<&mut Self>, index: i32) -> bool {
todo!(); self.move_rows(index, index - 1, 1)
} }
#[qinvokable] #[qinvokable]
pub fn move_down( pub fn move_down(self: Pin<&mut Self>, index: i32) -> bool {
mut self: Pin<&mut Self>, self.move_rows(index, index + 1, 1)
index: i32,
) -> bool {
todo!();
} }
#[qinvokable] #[qinvokable]
@ -904,6 +947,20 @@ mod service_item_model {
self: Pin<&mut qobject::ServiceItemMod>, 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( unsafe fn begin_remove_rows(
self: Pin<&mut qobject::ServiceItemMod>, self: Pin<&mut qobject::ServiceItemMod>,
parent: &QModelIndex, parent: &QModelIndex,