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

Code before:
        for (const auto &idx : qAsConst(indexList)) {
            notes.insert(idx.data(NoteListModel::NoteID).toInt());
        }
        contextMenu->clear();
        if (m_tagPool) {
            m_tagsMenu = contextMenu->addMenu("Tags ...");
            for (auto action : qAsConst(m_noteTagActions)) {
                delete action;
            }
            m_noteTagActions.clear();
            auto createTagIcon = [](const QString &color) -> QIcon {
                QPixmap pix{ 32, 32 };
                pix.fill(Qt::transparent);
                QPainter painter{ &pix };
                painter.setRenderHint(QPainter::Antialiasing);
                auto iconRect = QRect((pix.width() - 30) / 2, (pix.height() - 30) / 2, 30, 30);
                painter.setBrush(QColor(color));
                painter.setPen(QColor(color));
                painter.drawEllipse(iconRect);
                return QIcon{ pix };
            };
            QSet<int> tagInNote;
            const auto tagIds = m_tagPool->tagIds();
            for (const auto &id : tagIds) {
                bool all = true;
                for (const auto &idx : qAsConst(indexList)) {
                    auto tags = idx.data(NoteListModel::NoteTagsList).value<QSet<int>>();
                    if (!tags.contains(id)) {
                        all = false;
                        break;
                    }
                }
                if (all) {
                    tagInNote.insert(id);
                }
            }
            for (auto id : qAsConst(tagInNote)) {
                auto tag = m_tagPool->getTag(id);
                auto tagAction = new QAction(QString("✓ Remove tag ") + tag.name(), this);
                connect(tagAction, &QAction::triggered, this,
                        [this, id, notes] { removeNotesFromTag(notes, id); });
                tagAction->setIcon(createTagIcon(tag.color()));
                m_tagsMenu->addAction(tagAction);
                m_noteTagActions.append(tagAction);
            }
            m_tagsMenu->addSeparator();
            for (auto id : tagIds) {
                if (tagInNote.contains(id)) {
                    continue;
                }
                auto tag = m_tagPool->getTag(id);

Review comment (suggestion):
Rather than creating variations of generic names, we should prefer specific names. I think in this case `selectedIndex` would be suitable (and in some other places, as far as I could see).

Renaming `indexList` to `selectedIndexes` would be good, but not necessarily in this patch.

Code after:
        if (m_tagPool) {
            m_tagsMenu = contextMenu->addMenu("Tags ...");
            for (auto action : qAsConst(m_noteTagActions)) {
                delete action;
            }
            m_noteTagActions.clear();
            auto createTagIcon = [](const QString &color) -> QIcon {
                QPixmap pix{ 32, 32 };
                pix.fill(Qt::transparent);
                QPainter painter{ &pix };
                painter.setRenderHint(QPainter::Antialiasing);
                auto iconRect = QRect((pix.width() - 30) / 2, (pix.height() - 30) / 2, 30, 30);
                painter.setBrush(QColor(color));
                painter.setPen(QColor(color));
                painter.drawEllipse(iconRect);
                return QIcon{ pix };
            };
            QSet<int> tagInNote;
            const auto tagIds = m_tagPool->tagIds();
            for (const auto &id : tagIds) {
                bool all = true;
                for (const auto &selectedIndex : qAsConst(indexList)) {
                    auto tags = selectedIndex.data(NoteListModel::NoteTagsList).value<QSet<int>>();
                    if (!tags.contains(id)) {
                        all = false;
                        break;
                    }
                }
                if (all) {
                    tagInNote.insert(id);
                }
            }
            for (auto id : qAsConst(tagInNote)) {
                auto tag = m_tagPool->getTag(id);
                auto tagAction = new QAction(QString("✓ Remove tag ") + tag.name(), this);
                connect(tagAction, &QAction::triggered, this,
                        [this, id, notes] { removeNotesFromTag(notes, id); });
                tagAction->setIcon(createTagIcon(tag.color()));
                m_tagsMenu->addAction(tagAction);
                m_noteTagActions.append(tagAction);
            }
            m_tagsMenu->addSeparator();
            for (auto id : tagIds) {
                if (tagInNote.contains(id)) {
                    continue;
                }
                auto tag = m_tagPool->getTag(id);
                auto tagAction = new QAction(QString(" ") + tag.name(), this);
                connect(tagAction, &QAction::triggered, this,
                        [this, id, notes] { addNotesToTag(notes, id); });
                tagAction->setIcon(createTagIcon(tag.color()));