moving slides after moving serviceItems, need to fix count of slides
This commit is contained in:
parent
02c4c8a47a
commit
08ed111efc
5 changed files with 47 additions and 6 deletions
|
@ -373,8 +373,8 @@ void ServiceItemModel::removeItem(int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServiceItemModel::moveRows(int sourceIndex, int destIndex, int count) {
|
bool ServiceItemModel::moveRows(int sourceIndex, int destIndex, int count) {
|
||||||
qDebug() << index(sourceIndex).row();
|
qDebug() << sourceIndex;
|
||||||
qDebug() << index(destIndex).row();
|
qDebug() << destIndex;
|
||||||
|
|
||||||
const int lastIndex = rowCount() - 1;
|
const int lastIndex = rowCount() - 1;
|
||||||
|
|
||||||
|
@ -388,16 +388,21 @@ bool ServiceItemModel::moveRows(int sourceIndex, int destIndex, int count) {
|
||||||
const bool isMoveDown = destIndex > sourceIndex;
|
const bool isMoveDown = destIndex > sourceIndex;
|
||||||
|
|
||||||
if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1,
|
if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1,
|
||||||
parent, isMoveDown ? destIndex + 2 : destIndex)) {
|
parent, isMoveDown ? destIndex + 1 : destIndex)) {
|
||||||
qDebug() << "Can't move rows";
|
qDebug() << "Can't move rows";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex;
|
qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex;
|
||||||
|
|
||||||
m_items.move(sourceIndex, isMoveDown ? destIndex + 1 : destIndex);
|
m_items.move(sourceIndex, destIndex);
|
||||||
|
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
|
|
||||||
|
QModelIndex idx = index(destIndex);
|
||||||
|
ServiceItem *item = m_items[idx.row()];
|
||||||
|
emit rowMoved(sourceIndex, destIndex, *item);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,7 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void itemAdded(const int &, const ServiceItem &);
|
void itemAdded(const int &, const ServiceItem &);
|
||||||
void itemInserted(const int &, const ServiceItem &);
|
void itemInserted(const int &, const ServiceItem &);
|
||||||
|
void rowMoved(const int &, const int &, const ServiceItem &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -303,14 +303,14 @@ bool SlideModel::moveRows(int sourceIndex, int destIndex, int count) {
|
||||||
const bool isMoveDown = destIndex > sourceIndex;
|
const bool isMoveDown = destIndex > sourceIndex;
|
||||||
|
|
||||||
if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1,
|
if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1,
|
||||||
parent, isMoveDown ? destIndex + 2 : destIndex)) {
|
parent, isMoveDown ? destIndex + 1 : destIndex)) {
|
||||||
qDebug() << "Can't move rows";
|
qDebug() << "Can't move rows";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex;
|
qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex;
|
||||||
|
|
||||||
m_items.move(sourceIndex, isMoveDown ? destIndex + 1 : destIndex);
|
m_items.move(sourceIndex, destIndex);
|
||||||
|
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
return true;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ public slots:
|
||||||
Q_INVOKABLE bool deactivate(int id);
|
Q_INVOKABLE bool deactivate(int id);
|
||||||
void addItemFromService(const int &index, const ServiceItem &item);
|
void addItemFromService(const int &index, const ServiceItem &item);
|
||||||
void insertItemFromService(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:
|
private:
|
||||||
QList<Slide *> m_items;
|
QList<Slide *> m_items;
|
||||||
|
|
|
@ -151,6 +151,10 @@ int main(int argc, char *argv[])
|
||||||
SIGNAL(slideChanged(int)),
|
SIGNAL(slideChanged(int)),
|
||||||
slideModel.get(),
|
slideModel.get(),
|
||||||
SLOT(activate(int)));
|
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();
|
bool loading = serviceItemModel.get()->loadLastSaved();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue