Skip to content
Snippets Groups Projects
Commit 70446275 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

messagelistmodel: improve moveMessages

+ moveMessage was doing useless computation to move messages one
by one even if blocks are supported
+ beginMoveRows/endMoveRows seems to do weird stuff if all the rows
should be moved causing some crashes. beginReset in this case
doesn't trigger this weird behaviour and is more efficient.

Change-Id: Ia4eb3cdbbe74bf9215fb673cb9af571f67225ffe
parent 84fb218d
No related branches found
No related tags found
No related merge requests found
......@@ -297,12 +297,8 @@ MessageListModel::moveMessage(const QString& msgId, const QString& parentId)
if (currentIndex == newIndex || newIndex == -1)
return;
moveMessage(currentIndex, newIndex);
// move a child message
if (!childMessageIdToMove.isEmpty()) {
moveMessage(childMessageIdToMove, msgId);
}
// Pretty every messages is moved
moveMessages(currentIndex, interactions_.size() - 1, newIndex);
}
void
......@@ -351,11 +347,23 @@ MessageListModel::removeMessage(int index, iterator it)
}
void
MessageListModel::moveMessage(int from, int to)
MessageListModel::moveMessages(int from, int last, int to)
{
Q_EMIT beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
interactions_.move(from, to);
Q_EMIT endMoveRows();
auto resetModel = (from <= 2 && last == interactions_.size() - 1);
if (last < from)
return;
if (resetModel) {
Q_EMIT beginResetModel();
} else {
Q_EMIT beginMoveRows(QModelIndex(), from, last, QModelIndex(), to);
}
for (int i = 0; i < (last - from); ++i)
interactions_.move(last, to);
if (resetModel) {
Q_EMIT endResetModel();
} else {
Q_EMIT endMoveRows();
}
}
bool
......
......@@ -171,7 +171,7 @@ private:
void insertMessage(int index, item_t& message);
iterator insertMessage(iterator it, item_t& message);
void removeMessage(int index, iterator it);
void moveMessage(int from, int to);
void moveMessages(int from, int last, int to);
QTimer* timestampTimer_ {nullptr};
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment