Skip to content

Commit

Permalink
#2819 fix: note counting per tag
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed Aug 31, 2023
1 parent 40d19c8 commit a87831d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
5 changes: 5 additions & 0 deletions 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))
Expand Down
43 changes: 37 additions & 6 deletions src/mainwindow.cpp
Expand Up @@ -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<int> linkedNoteIds;
bool isMultipleTags = false;

if (!hideCount) {
const QVector<int> tagIdListToCount = Tag::isTaggingShowNotesRecursively()
? Tag::fetchTagIdsRecursivelyByParentId(tagId)
: QVector<int>{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();
Expand All @@ -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<int> 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();
Expand Down

0 comments on commit a87831d

Please sign in to comment.