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) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue