Repository: nuttyartist/notes
File: src/notelistmodel.cpp (C++)

Code before:
        }
        for (const auto &id_s : qAsConst(idl)) {
            auto nodeId = id_s.toInt();
            for (int i = 0; i < m_pinnedList.size(); ++i) {
                if (m_pinnedList[i].id() == nodeId) {
                    m_pinnedList.move(i, row);
                    break;
                }
            }
            movedIds.insert(nodeId);
        }
    } else {
        for (const auto &index : qAsConst(idxe)) {
            auto &note = getRef(index.row());
            movedIds.insert(note.id());
            if (!note.isPinnedNote()) {
                continue;
            }
            note.setIsPinnedNote(false);
            emit requestUpdatePinned(note.id(), false);
            int destinationChild = 0;
            if (m_listViewInfo.parentFolderId == SpecialNodeID::TrashFolder) {
                auto lastMod = index.data(NoteDeletionDateTime).toDateTime();
                for (destinationChild = 0; destinationChild < m_noteList.size();
                     ++destinationChild) {
                    note = m_noteList[destinationChild];
                    if (note.deletionDateTime() <= lastMod) {
                        break;
                    }
                }
            } else {
                auto lastMod = index.data(NoteLastModificationDateTime).toDateTime();
                for (destinationChild = 0; destinationChild < m_noteList.size();
                     ++destinationChild) {
                    note = m_noteList[destinationChild];
                    if (note.lastModificationdateTime() <= lastMod) {
                        break;
                    }
                }
            }
            m_noteList.insert(destinationChild, m_pinnedList.takeAt(index.row()));
        }
    }

    endResetModel();
    QModelIndexList destinations;
    for (const auto &id : movedIds) {
        auto index = getNoteIndex(id);
        if (!index.isValid()) {
            continue;
        }

Review comment (suggestion):
Erm, this massively changes the behavior. Previously, it was storing a read-only `NodeData` reference to `m_noteList[destinationChild]`, which was used to inspect the `deletionDateTime`. Whereas the new line copies `m_noteList[destinationChild]` into the previously referenced node data instead.

(also applies below)

Code after:
            }
            movedIds.insert(nodeId);
        }
    } else {
        for (const auto &index : qAsConst(idxe)) {
            auto &note = getRef(index.row());
            movedIds.insert(note.id());
            if (!note.isPinnedNote()) {
                continue;
            }
            note.setIsPinnedNote(false);
            emit requestUpdatePinned(note.id(), false);
            int destinationChild = 0;
            if (m_listViewInfo.parentFolderId == SpecialNodeID::TrashFolder) {
                auto lastMod = index.data(NoteDeletionDateTime).toDateTime();
                for (destinationChild = 0; destinationChild < m_noteList.size();
                     ++destinationChild) {
                    if (m_noteList[destinationChild].deletionDateTime() <= lastMod) {
                        break;
                    }
                }
            } else {
                auto lastMod = index.data(NoteLastModificationDateTime).toDateTime();
                for (destinationChild = 0; destinationChild < m_noteList.size();
                     ++destinationChild) {
                    if (m_noteList[destinationChild].deletionDateTime() <= lastMod) {
                        break;
                    }
                }
            }
            m_noteList.insert(destinationChild, m_pinnedList.takeAt(index.row()));
        }
    }

    endResetModel();
    QModelIndexList destinations;
    for (const auto &id : movedIds) {
        auto index = getNoteIndex(id);
        if (!index.isValid()) {
            continue;
        }
        destinations.append(index);
    }
    emit selectNotes(destinations);
    emit rowsMovedC(destinations);
    updatePinnedRelativePosition();
    return true;
}

QModelIndex NoteListModel::getFirstUnpinnedNote() const
{