bug: fixed inserting slides in the middle of songs
Since songs had more than one slide, anything inserted after the first multi-slide item would break the insertion. ServiceItem indexes are not the same as the slide indexes so we needed to find the right index, then properly change the other indexes in the right spot. I think I've done this by using rust iterators better.
This commit is contained in:
parent
a02f55eb0b
commit
3c09565a12
2 changed files with 26 additions and 15 deletions
|
@ -239,7 +239,7 @@ void ServiceItemModel::addItem(const QString &name, const QString &type,
|
||||||
qDebug() << "*&";
|
qDebug() << "*&";
|
||||||
qDebug() << itm;
|
qDebug() << itm;
|
||||||
qDebug() << "*&";
|
qDebug() << "*&";
|
||||||
emit itemAdded(rowCount() - 1, *item);
|
// emit itemAdded(rowCount() - 1, *item);
|
||||||
emit itemAddedRust(rowCount() - 1, itm);
|
emit itemAddedRust(rowCount() - 1, itm);
|
||||||
qDebug() << "EMITTED ITEM ADDED" << rowCount();
|
qDebug() << "EMITTED ITEM ADDED" << rowCount();
|
||||||
qDebug() << "#################################";
|
qDebug() << "#################################";
|
||||||
|
@ -278,7 +278,7 @@ void ServiceItemModel::insertItem(const int &index, const QString &name,
|
||||||
} else
|
} else
|
||||||
qDebug() << "idx isn't valid";
|
qDebug() << "idx isn't valid";
|
||||||
|
|
||||||
emit itemInserted(index, *item);
|
// emit itemInserted(index, *item);
|
||||||
emit itemInsertedRust(index, itm);
|
emit itemInsertedRust(index, itm);
|
||||||
|
|
||||||
qDebug() << "EMITTED ITEM INSERTED";
|
qDebug() << "EMITTED ITEM INSERTED";
|
||||||
|
|
|
@ -346,29 +346,40 @@ mod slide_model {
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
slide.video_thumbnail = QString::from("");
|
slide.video_thumbnail = QString::from("");
|
||||||
|
|
||||||
// We need to move all the current slides service_item_id's up by one.
|
let slides_iter = self.as_mut().slides_mut().iter_mut();
|
||||||
let slides_len = self.as_mut().slides_mut().len() as i32;
|
let mut slide_index = 0;
|
||||||
for slide in index..slides_len {
|
for (i, slide) in slides_iter.enumerate().rev() {
|
||||||
if let Some(slide) = self.as_mut().slides_mut().get_mut(slide as usize) {
|
if slide.service_item_id == index {
|
||||||
slide.service_item_id += 1;
|
slide_index = i as i32;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need to move all the current slides service_item_id's up by one.
|
||||||
|
let slides_iter = self.as_mut().slides_mut().iter_mut();
|
||||||
|
for slide in slides_iter.filter(|x| x.service_item_id >= index) {
|
||||||
|
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;
|
||||||
slide.image_background = background;
|
slide.image_background = background;
|
||||||
slide.video_background = QString::from("");
|
slide.video_background = QString::from("");
|
||||||
slide.slide_index = 0;
|
slide.slide_index = 0;
|
||||||
self.as_mut().insert_slide(&slide, index);
|
self.as_mut().insert_slide(&slide, slide_index);
|
||||||
}
|
}
|
||||||
Some(ty) if ty == QString::from("song") => {
|
Some(ty) if ty == QString::from("song") => {
|
||||||
for i in 0..text_vec.len() {
|
let count = text_vec.len();
|
||||||
println!("add song of {:?} length", text_vec.len());
|
for (i, text) in text_vec.iter().enumerate() {
|
||||||
|
println!(
|
||||||
|
"rust: add song of {:?} length at index {:?}",
|
||||||
|
&count, &slide_index
|
||||||
|
);
|
||||||
slide.ty = ty.clone();
|
slide.ty = ty.clone();
|
||||||
// println!("{:?}", text_vec[i].clone());
|
// println!("{:?}", text_vec[i].clone());
|
||||||
slide.text = text_vec[i].clone();
|
slide.text = text.clone();
|
||||||
slide.slide_count = text_vec.len() as i32;
|
slide.slide_count = count as i32;
|
||||||
slide.slide_index = i as i32;
|
slide.slide_index = i as i32;
|
||||||
if background_type == QString::from("image") {
|
if background_type == QString::from("image") {
|
||||||
slide.image_background = background.clone();
|
slide.image_background = background.clone();
|
||||||
|
@ -377,7 +388,7 @@ mod slide_model {
|
||||||
slide.video_background = background.clone();
|
slide.video_background = background.clone();
|
||||||
slide.image_background = QString::from("");
|
slide.image_background = QString::from("");
|
||||||
}
|
}
|
||||||
self.as_mut().insert_slide(&slide, index + i as i32);
|
self.as_mut().insert_slide(&slide, slide_index + i as i32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(ty) if ty == QString::from("video") => {
|
Some(ty) if ty == QString::from("video") => {
|
||||||
|
@ -385,7 +396,7 @@ mod slide_model {
|
||||||
slide.image_background = QString::from("");
|
slide.image_background = QString::from("");
|
||||||
slide.video_background = background;
|
slide.video_background = background;
|
||||||
slide.slide_index = 0;
|
slide.slide_index = 0;
|
||||||
self.as_mut().insert_slide(&slide, index);
|
self.as_mut().insert_slide(&slide, slide_index);
|
||||||
}
|
}
|
||||||
Some(ty) if ty == QString::from("presentation") => {
|
Some(ty) if ty == QString::from("presentation") => {
|
||||||
for i in 0..slide.slide_count {
|
for i in 0..slide.slide_count {
|
||||||
|
@ -393,7 +404,7 @@ mod slide_model {
|
||||||
slide.image_background = background.clone();
|
slide.image_background = background.clone();
|
||||||
slide.video_background = QString::from("");
|
slide.video_background = QString::from("");
|
||||||
slide.slide_index = i;
|
slide.slide_index = i;
|
||||||
self.as_mut().insert_slide(&slide, index + i as i32);
|
self.as_mut().insert_slide(&slide, slide_index + i as i32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => println!("It's somethign else!"),
|
_ => println!("It's somethign else!"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue