mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-09-10 12:03:18 +02:00
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
This commit is contained in:
parent
84fb218d38
commit
7044627551
2 changed files with 19 additions and 11 deletions
|
@ -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};
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue