From 71d9254446c054130121e5a204bef333e0bcd2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Fri, 25 Mar 2016 14:15:49 +0100 Subject: [PATCH] fixed resorting comics by drag&drop in tags and reading lists --- YACReaderLibrary/db/comic_model.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp index 37b452d0..0cfc4610 100644 --- a/YACReaderLibrary/db/comic_model.cpp +++ b/YACReaderLibrary/db/comic_model.cpp @@ -119,6 +119,10 @@ bool ComicModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int QLOG_TRACE() << newSorting; int tempRow = row; + + if(tempRow < 0) + tempRow = _data.count(); + foreach(qulonglong id, comicIds) { int i = 0; @@ -126,21 +130,28 @@ bool ComicModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int if(item->data(Id) == id) { beginMoveRows(parent,i,i,parent,tempRow); - _data.removeAll(item); - _data.insert(tempRow++, item); + + bool skipElement = i == tempRow || i + 1 == tempRow; + + if(!skipElement) + { + if(i > tempRow) + _data.move(i, tempRow); + else + _data.move(i, tempRow - 1); + } + endMoveRows(); + + if(i > tempRow) + tempRow++; + break; } i++; } } - /*if(!beginMoveRows(parent,currentIndexes.first(),currentIndexes.last(),parent,row)) - return false;*/ - _data = resortedData; //TODO No longer needed - - - //TODO emit signals //TODO fix selection QList allComicIds; foreach (ComicItem *item, _data) {