adding the removal of items work on the slides

This isn't finished yet, but the core is there. I have yet to fully
remove slides after a service_item is removed.
This commit is contained in:
Chris Cochrun 2023-04-11 06:20:56 -05:00
parent 7a36b70a6d
commit f8ac7feea0
5 changed files with 35 additions and 10 deletions

View file

@ -303,7 +303,9 @@ void ServiceItemModel::removeItems() {
beginRemoveRows(QModelIndex(), i, i); beginRemoveRows(QModelIndex(), i, i);
m_items.removeAt(i); m_items.removeAt(i);
endRemoveRows(); endRemoveRows();
QVariantMap map = getItem(i);
emit rowRemoved(i, *item); emit rowRemoved(i, *item);
emit rowRemovedRust(i, map);
qDebug() << "emitted removal of item:" << item->name(); qDebug() << "emitted removal of item:" << item->name();
} }
} }

View file

@ -119,7 +119,9 @@ signals:
void itemInserted(const int &, const ServiceItem &); void itemInserted(const int &, const ServiceItem &);
void itemInsertedRust(const int &, const QVariantMap &); void itemInsertedRust(const int &, const QVariantMap &);
void rowMoved(const int &, const int &, const ServiceItem &); void rowMoved(const int &, const int &, const ServiceItem &);
void rowMovedRust(const int &, const int &, const QVariantMap &);
void rowRemoved(const int &, const ServiceItem &); void rowRemoved(const int &, const ServiceItem &);
void rowRemovedRust(const int &, const QVariantMap &);
void allRemoved(); void allRemoved();
private: private:

View file

@ -168,13 +168,13 @@ int main(int argc, char *argv[])
slideModel.get(), slideModel.get(),
SLOT(moveRowFromService(const int&, const int&, const ServiceItem&))); SLOT(moveRowFromService(const int&, const int&, const ServiceItem&)));
QObject::connect(serviceItemModel.get(), QObject::connect(serviceItemModel.get(),
SIGNAL(rowRemoved(const int&, const ServiceItem&)), &ServiceItemModel::rowRemovedRust,
slideModel.get(), slideMod.get(),
SLOT(removeServiceItem(const int&, const ServiceItem&))); &SlideyMod::removeItemFromService);
QObject::connect(serviceItemModel.get(), // QObject::connect(serviceItemModel.get(),
SIGNAL(allRemoved()), // SIGNAL(allRemoved()),
slideModel.get(), // slideMod.get(),
SLOT(clear())); // SLOT(clear()));
QObject::connect(slideobject.get(), QObject::connect(slideobject.get(),
SIGNAL(slideChanged(int)), SIGNAL(slideChanged(int)),
slideMod.get(), slideMod.get(),

View file

@ -506,7 +506,7 @@ Item {
icon.name: "delete" icon.name: "delete"
onTriggered: { onTriggered: {
showPassiveNotification("remove"); showPassiveNotification("remove");
removeItem(serviceItemList.currentIndex); removeItems();
} }
}, },
Kirigami.Action { Kirigami.Action {
@ -515,11 +515,12 @@ Item {
onTriggered: { onTriggered: {
showPassiveNotification("clearing all items"); showPassiveNotification("clearing all items");
ServiceItemModel.clearAll(); ServiceItemModel.clearAll();
serviceItemList.forceLayout()
} }
}, },
Kirigami.Action { Kirigami.Action {
text: "Load" text: "Load"
icon.name: "list-remove-all" icon.name: "fileopen"
onTriggered: { onTriggered: {
loadingItem.visible = !loadingItem.visible; loadingItem.visible = !loadingItem.visible;
} }

View file

@ -165,6 +165,15 @@ mod slide_model {
} }
} }
#[qinvokable]
pub fn remove_item_from_service(
mut self: Pin<&mut Self>,
index: i32,
service_item: &QMap_QString_QVariant,
) {
println!("Removing: {:?}", index);
}
#[qinvokable] #[qinvokable]
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) { pub fn remove_item(mut self: Pin<&mut Self>, index: i32) {
if index < 0 || (index as usize) >= self.slides().len() { if index < 0 || (index as usize) >= self.slides().len() {
@ -387,6 +396,14 @@ mod slide_model {
video_thumbnail: QString::from(""), video_thumbnail: QString::from(""),
}; };
// We need to move all the current slides service_item_id's up by one.
let slides_len = self.as_mut().slides_mut().len() as i32;
for slide in index..slides_len {
if let Some(slide) = self.as_mut().slides_mut().get_mut(slide as usize) {
slide.service_item_id += 1;
}
}
match ty { match ty {
Some(ty) if ty == QString::from("image") => { Some(ty) if ty == QString::from("image") => {
slide.ty = ty; slide.ty = ty;
@ -624,12 +641,15 @@ mod slide_model {
slide.active = false; slide.active = false;
} }
if let Some(slide) = self.as_mut().slides_mut().get_mut(index as usize) { if let Some(slide) = self.as_mut().slides_mut().get_mut(index as usize) {
println!("slide is activating {:?}", index);
println!("slide-title: {:?}", slide.service_item_id);
println!("slide-image-background: {:?}", slide.image_background);
println!("slide-video-background: {:?}", slide.video_background);
slide.active = true; slide.active = true;
self.as_mut().emit_data_changed(tl, br, &vector_roles); self.as_mut().emit_data_changed(tl, br, &vector_roles);
// We use this signal generated by our signals enum to tell QML that // We use this signal generated by our signals enum to tell QML that
// the active slide has changed which is used to reposition views. // the active slide has changed which is used to reposition views.
self.as_mut().emit_active_changed(); self.as_mut().emit_active_changed();
println!("slide is activating {:?}", index);
true true
} else { } else {
false false