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

Code before:
{
    if (indexes.isEmpty()) {
        return nullptr;
    }
    QStringList d;
    for (const auto &index : indexes) {
        auto id = index.data(NoteListModel::NoteID).toInt();
        d.append(QString::number(id));
    }
    if (d.isEmpty()) {
        return nullptr;
    }
    QMimeData *mimeData = new QMimeData;
    mimeData->setData(NOTE_MIME, d.join(QStringLiteral(PATH_SEPERATOR)).toUtf8());
    return mimeData;
}

bool NoteListModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column,
                                 const QModelIndex &parent)
{
    Q_UNUSED(column);
    auto getRef = [this](int rowIndex) -> NodeData & {
        if (rowIndex < m_pinnedList.size()) {
            return m_pinnedList[rowIndex];
        }
        return m_noteList[rowIndex - m_pinnedList.size()];
    };

    if (!(mime->hasFormat(NOTE_MIME) && action == Qt::MoveAction)) {
        return false;
    }
    if (row == -1) {
        // valid index: drop onto item
        if (parent.isValid()) {
            row = parent.row();
        } else {
            // invalid index: append at bottom, after last toplevel
            row = rowCount(parent);
        }
    }
    bool toPinned = false;
    if (row >= m_pinnedList.size()) {
        toPinned = false;
    } else {
        toPinned = true;
    }
    auto idl = QString::fromUtf8(mime->data(NOTE_MIME)).split(QStringLiteral(PATH_SEPERATOR));
    QSet<int> movedIds;
    QModelIndexList idxe;
    for (const auto &id_s : qAsConst(idl)) {
        auto nodeId = id_s.toInt();

Review comment (suggestion):
You're changing one of 6 occurrences of this `getRef` function. Consider changing it to a private member and replacing all occurrences.

Code after:
        return nullptr;
    }
    QStringList d;
    for (const auto &index : indexes) {
        auto id = index.data(NoteListModel::NoteID).toInt();
        d.append(QString::number(id));
    }
    if (d.isEmpty()) {
        return nullptr;
    }
    QMimeData *mimeData = new QMimeData;
    mimeData->setData(NOTE_MIME, d.join(QStringLiteral(PATH_SEPERATOR)).toUtf8());
    return mimeData;
}

bool NoteListModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column,
                                 const QModelIndex &parent)
{
    Q_UNUSED(column);

    if (!(mime->hasFormat(NOTE_MIME) && action == Qt::MoveAction)) {
        return false;
    }
    if (row == -1) {
        // valid index: drop onto item
        if (parent.isValid()) {
            row = parent.row();
        } else {
            // invalid index: append at bottom, after last toplevel
            row = rowCount(parent);
        }
    }
    bool toPinned = false;
    if (row >= m_pinnedList.size()) {
        toPinned = false;
    } else {
        toPinned = true;
    }
    auto idl = QString::fromUtf8(mime->data(NOTE_MIME)).split(QStringLiteral(PATH_SEPERATOR));
    QSet<int> movedIds;
    QModelIndexList idxe;
    for (const auto &id_s : qAsConst(idl)) {
        auto nodeId = id_s.toInt();
        idxe.append(getNoteIndex(nodeId));
    }
    emit rowsAboutToBeMovedC(idxe);
    beginResetModel();
    if (toPinned) {
        for (const auto &index : qAsConst(idxe)) {
            auto &note = getRef(index.row());
            if (!note.isPinnedNote()) {