From a87831df8d7da51f57fa99d319e831900de8302f Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle Date: Thu, 31 Aug 2023 06:52:55 +0200 Subject: [PATCH] #2819 fix: note counting per tag --- CHANGELOG.md | 5 +++++ src/mainwindow.cpp | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a41e422e53..590d513da1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # QOwnNotes Changelog +## 23.9.0 +- when all notes of a tag, including the notes of their child-tags are shown in the + note list the numbers of notes per tag are now calculated correctly in the tag tree + (for [#2819](https://github.com/pbek/QOwnNotes/issues/2819)) + ## 23.8.2 - added a **new editor color schema** *Atom Mellow Dark* by @davuses (for [#2817](https://github.com/pbek/QOwnNotes/issues/2817)) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0dc1b387f3..17ec821d35 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -7451,17 +7451,23 @@ QTreeWidgetItem *MainWindow::addTagToTagTreeWidget(QTreeWidgetItem *parent, cons const QString name = tag._name; auto hideCount = QSettings().value("tagsPanelHideNoteCount", false).toBool(); - int count = 0; + int linkCount = 0; + QVector linkedNoteIds; + bool isMultipleTags = false; + if (!hideCount) { const QVector tagIdListToCount = Tag::isTaggingShowNotesRecursively() ? Tag::fetchTagIdsRecursivelyByParentId(tagId) : QVector{tag._id}; + isMultipleTags = tagIdListToCount.count() > 1; const auto selectedSubFolderItems = ui->noteSubFolderTreeWidget->selectedItems(); const bool showNotesFromAllSubFolders = this->_showNotesFromAllNoteSubFolders; const bool isShowNotesRecursively = NoteSubFolder::isNoteSubfoldersPanelShowNotesRecursively(); if (selectedSubFolderItems.count() > 1) { + linkedNoteIds.reserve(tagIdListToCount.size()); + for (const int tagIdToCount : tagIdListToCount) { for (QTreeWidgetItem *folderItem : selectedSubFolderItems) { int id = folderItem->data(0, Qt::UserRole).toInt(); @@ -7471,19 +7477,44 @@ QTreeWidgetItem *MainWindow::addTagToTagTreeWidget(QTreeWidgetItem *parent, cons continue; } - count = Tag::countLinkedNoteFileNamesForNoteSubFolder( - tagIdToCount, folder, showNotesFromAllSubFolders, isShowNotesRecursively); + if (!isMultipleTags) { + linkCount = Tag::countLinkedNoteFileNamesForNoteSubFolder( + tagIdToCount, folder, showNotesFromAllSubFolders, isShowNotesRecursively); + } else { + linkedNoteIds << Tag::fetchAllLinkedNoteIdsForFolder( + tagIdToCount, + folder, showNotesFromAllSubFolders, + isShowNotesRecursively); + } } } } else { for (const int tagToCount : tagIdListToCount) { - count = Tag::countLinkedNoteFileNames(tagToCount, showNotesFromAllSubFolders, - isShowNotesRecursively); + if (!isMultipleTags) { + linkCount = Tag::countLinkedNoteFileNames(tagToCount, showNotesFromAllSubFolders, + isShowNotesRecursively); + } else { + linkedNoteIds << Tag::fetchAllLinkedNoteIds( + tagToCount, + showNotesFromAllSubFolders, + isShowNotesRecursively); + } + } + } + } + + if (isMultipleTags) { + // remove duplicate note ids + QVector uniqueLinkedNoteIds; + for (const int &value : linkedNoteIds) { + if (!uniqueLinkedNoteIds.contains(value)) { + uniqueLinkedNoteIds.append(value); } } + + linkCount = uniqueLinkedNoteIds.count(); } - const int linkCount = count; const QString toolTip = tr("Show all notes tagged with '%1' (%2)").arg(name, QString::number(linkCount)); auto *item = new QTreeWidgetItem();