moving slides after moving serviceItems, need to fix count of slides

This commit is contained in:
Chris Cochrun 2023-01-24 06:17:47 -06:00
parent 02c4c8a47a
commit 08ed111efc
5 changed files with 47 additions and 6 deletions

View file

@ -303,14 +303,14 @@ bool SlideModel::moveRows(int sourceIndex, int destIndex, int count) {
const bool isMoveDown = destIndex > sourceIndex;
if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1,
parent, isMoveDown ? destIndex + 2 : destIndex)) {
parent, isMoveDown ? destIndex + 1 : destIndex)) {
qDebug() << "Can't move rows";
return false;
}
qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex;
m_items.move(sourceIndex, isMoveDown ? destIndex + 1 : destIndex);
m_items.move(sourceIndex, destIndex);
endMoveRows();
return true;
@ -548,3 +548,33 @@ void SlideModel::insertItemFromService(const int &index, const ServiceItem &item
}
}
void SlideModel::moveRowFromService(const int &fromIndex,
const int &toIndex,
const ServiceItem &item) {
const bool isMoveDown = toIndex > fromIndex;
qDebug() << "@@@Move SIs" << fromIndex << "to" << toIndex << "@@@";
int slideId = findSlideIdFromServItm(fromIndex);
int toSlideId = findSlideIdFromServItm(toIndex);
int count;
if (item.type() == "song")
count = item.text().length();
else if (item.type() == "presentation")
count = item.slideNumber();
else
count = 1;
int toId = count + slideId;
qDebug() << "@@@Move Row" << slideId << "to" << toSlideId << "@@@";
qDebug() << count;
moveRows(slideId, toSlideId, count);
m_items[toSlideId]->setServiceItemId(toIndex);
if (isMoveDown) {
for (int i = slideId; i < toSlideId; i++) {
m_items[i]->setServiceItemId(m_items[i]->serviceItemId() - 1);
}
} else {
for (int i = slideId; i > toSlideId; i--) {
m_items[i]->setServiceItemId(m_items[i]->serviceItemId() + 1);
}
}
}