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

@ -373,8 +373,8 @@ void ServiceItemModel::removeItem(int index) {
}
bool ServiceItemModel::moveRows(int sourceIndex, int destIndex, int count) {
qDebug() << index(sourceIndex).row();
qDebug() << index(destIndex).row();
qDebug() << sourceIndex;
qDebug() << destIndex;
const int lastIndex = rowCount() - 1;
@ -388,16 +388,21 @@ bool ServiceItemModel::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();
QModelIndex idx = index(destIndex);
ServiceItem *item = m_items[idx.row()];
emit rowMoved(sourceIndex, destIndex, *item);
return true;
}

View file

@ -113,6 +113,7 @@ public:
signals:
void itemAdded(const int &, const ServiceItem &);
void itemInserted(const int &, const ServiceItem &);
void rowMoved(const int &, const int &, const ServiceItem &);
private:

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);
}
}
}

View file

@ -86,6 +86,7 @@ public slots:
Q_INVOKABLE bool deactivate(int id);
void addItemFromService(const int &index, const ServiceItem &item);
void insertItemFromService(const int &index, const ServiceItem &item);
void moveRowFromService(const int &fromIndex, const int &toIndex, const ServiceItem &item);
private:
QList<Slide *> m_items;

View file

@ -151,6 +151,10 @@ int main(int argc, char *argv[])
SIGNAL(slideChanged(int)),
slideModel.get(),
SLOT(activate(int)));
QObject::connect(serviceItemModel.get(),
SIGNAL(rowMoved(const int&, const int&, const ServiceItem&)),
slideModel.get(),
SLOT(moveRowFromService(const int&, const int&, const ServiceItem&)));
bool loading = serviceItemModel.get()->loadLastSaved();