From 98d5203a2590a43e7c7b09f45206ebf499fbcaff Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Thu, 5 Dec 2019 11:00:29 +0500 Subject: [PATCH 1/3] Implement filtering by multiple tags --- src/mainwindow.cpp | 64 +++++++++++++++++++++++++++++++++++++--------- src/mainwindow.h | 2 ++ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 73ca5bb790..9c0cde3818 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5347,27 +5347,48 @@ void MainWindow::filterNotesByTag() { fileNameList = Note::fetchAllNotTaggedNames(); break; default: - // check if there is an active tag - Tag activeTag = Tag::activeTag(); - - if (!activeTag.isFetched()) { - return; + //check for multiple active; + auto selectedItems = ui->tagTreeWidget->selectedItems(); + QList tagIds; + Tag activeTag; + qWarning () << selectedItems.count(); + if (selectedItems.count() > 1) { + Q_FOREACH(const QTreeWidgetItem *i, selectedItems) { + qWarning () << i->data(0, Qt::DisplayRole).toString(); + int id = i->data(0, Qt::UserRole).toInt(); + tagIds << id; + } + } else { + // check if there is an active tag + activeTag = Tag::activeTag(); + if (!activeTag.isFetched()) { + return; + } + tagIds << activeTag.getId(); } QList tags; - // check if the notes should be viewed recursively - if (Tag::isTaggingShowNotesRecursively()) { - tags = Tag::fetchRecursivelyByParentId(activeTag.getId()); - } else { - tags << activeTag; + Q_FOREACH(int id, tagIds) { + tags << Tag::fetch(id); } - qDebug() << __func__ << " - 'tags': " << tags; + QList tagList; + + Q_FOREACH(const Tag &t, tags) { + // check if the notes should be viewed recursively + if (Tag::isTaggingShowNotesRecursively()) { + tagList << Tag::fetchRecursivelyByParentId(t.getId()); + } else { + tagList << t; + } + } + + qDebug() << __func__ << " - 'tags': " << tagList; auto selectedFolderItems = ui->noteSubFolderTreeWidget->selectedItems(); - Q_FOREACH(const Tag &tag, tags) { + Q_FOREACH(const Tag &tag, tagList) { // fetch all linked note names if (selectedFolderItems.count() > 1) { Q_FOREACH(const QTreeWidgetItem *i, selectedFolderItems) { @@ -8271,6 +8292,25 @@ void MainWindow::on_tagTreeWidget_currentItemChanged( int tagId = current->data(0, Qt::UserRole).toInt(); Tag::setAsActive(tagId); + int count = ui->tagTreeWidget->selectedItems().count(); + if (count > 1) return; + + const QSignalBlocker blocker(ui->searchLineEdit); + Q_UNUSED(blocker) + + ui->searchLineEdit->clear(); + filterNotes(); +} + +/** + * Sets a new active tag + */ +void MainWindow::on_tagTreeWidget_itemSelectionChanged() { + + int count = ui->tagTreeWidget->selectedItems().count(); + + if (count <= 1) return; + const QSignalBlocker blocker(ui->searchLineEdit); Q_UNUSED(blocker) diff --git a/src/mainwindow.h b/src/mainwindow.h index b73d5faec6..5c6de80e79 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -364,6 +364,8 @@ private slots: void on_tagTreeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); + void on_tagTreeWidget_itemSelectionChanged(); + void on_tagTreeWidget_customContextMenuRequested(const QPoint &pos); void moveSelectedTagsToTagId(int tagId); From 1bdf4beea8bd945a57e7d8fcd77a05f91989d4b0 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Thu, 5 Dec 2019 11:06:29 +0500 Subject: [PATCH 2/3] Remove unneccasary debugging stuff --- src/mainwindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9c0cde3818..37309575b2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5351,10 +5351,10 @@ void MainWindow::filterNotesByTag() { auto selectedItems = ui->tagTreeWidget->selectedItems(); QList tagIds; Tag activeTag; - qWarning () << selectedItems.count(); + if (selectedItems.count() > 1) { Q_FOREACH(const QTreeWidgetItem *i, selectedItems) { - qWarning () << i->data(0, Qt::DisplayRole).toString(); + int id = i->data(0, Qt::UserRole).toInt(); tagIds << id; } @@ -8303,7 +8303,7 @@ void MainWindow::on_tagTreeWidget_currentItemChanged( } /** - * Sets a new active tag + * Triggers filtering when multiple tags are selected */ void MainWindow::on_tagTreeWidget_itemSelectionChanged() { From 5f9bba7ee6106a66fb709fcca70146a80b260bbd Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Thu, 5 Dec 2019 13:23:14 +0500 Subject: [PATCH 3/3] Fix unselecting to one tag doesn't update noteList --- src/mainwindow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 37309575b2..2ae44e2859 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -8309,7 +8309,13 @@ void MainWindow::on_tagTreeWidget_itemSelectionChanged() { int count = ui->tagTreeWidget->selectedItems().count(); - if (count <= 1) return; + if (count <= 1) { + if (count == 1) { + on_tagTreeWidget_currentItemChanged( ui->tagTreeWidget->selectedItems().first(), + Q_NULLPTR); + } + return; + } const QSignalBlocker blocker(ui->searchLineEdit); Q_UNUSED(blocker)