From 471c72456fb675c9033942ebd27b936c61965d9f Mon Sep 17 00:00:00 2001
From: Edric Milaret <edric.ladent-milaret@savoirfairelinux.com>
Date: Thu, 1 Sep 2016 10:51:45 -0400
Subject: [PATCH] fix move in codecmodel

We were removing and inserting an item instead of just moving it
That confused the selection in the UI.

This fix is only applied for windows because the gnome and osx clients
don't yet support the layoutChanged signals which are emitted when move
operations are performed on the source models of proxy models.

Change-Id: I6a62164231e44f3894d300b3445c781ed8062cbd
Tuleap: #933
---
 src/codecmodel.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/codecmodel.cpp b/src/codecmodel.cpp
index 22c4e0f2..6615249c 100644
--- a/src/codecmodel.cpp
+++ b/src/codecmodel.cpp
@@ -573,6 +573,14 @@ bool CodecModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int
 
       const QModelIndex codecIdx = d_ptr->getIndexofCodecByID(codecId);
 
+#ifdef Q_OS_WIN
+      /* To understand why qtDestinationRow is needed
+      http://doc.qt.io/qt-5/qabstractitemmodel.html#beginMoveRows */
+      auto qtDestinationRow = destinationRow > codecIdx.row() ? destinationRow+1 : destinationRow;
+      beginMoveRows(parent, codecIdx.row(), codecIdx.row(), parent, qtDestinationRow);
+      d_ptr->m_lCodecs.move(codecIdx.row(), destinationRow);
+      endMoveRows();
+#else
       beginRemoveRows(QModelIndex(), codecIdx.row(), codecIdx.row());
       CodecModelPrivate::CodecData* codecInfo = d_ptr->m_lCodecs[codecIdx.row()];
       d_ptr->m_lCodecs.removeAt(codecIdx.row());
@@ -581,6 +589,7 @@ bool CodecModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int
       beginInsertRows(QModelIndex(), destinationRow, destinationRow);
       d_ptr->m_lCodecs.insert(destinationRow,codecInfo);
       endInsertRows();
+#endif
 
       this << EditAction::MODIFY;
 
-- 
GitLab