Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement filtering by multiple tags #1481

Merged
merged 3 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 57 additions & 11 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5347,27 +5347,48 @@ void MainWindow::filterNotesByTag() {
fileNameList = Note::fetchAllNotTaggedNames();
break;
default:
// check if there is an active tag
Tag activeTag = Tag::activeTag();
//check for multiple active;
auto selectedItems = ui->tagTreeWidget->selectedItems();
QList<int> tagIds;
Tag activeTag;

if (!activeTag.isFetched()) {
return;
if (selectedItems.count() > 1) {
Q_FOREACH(const QTreeWidgetItem *i, selectedItems) {

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<Tag> 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<Tag> 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) {
Expand Down Expand Up @@ -8271,6 +8292,31 @@ 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();
}

/**
* Triggers filtering when multiple tags are selected
*/
void MainWindow::on_tagTreeWidget_itemSelectionChanged() {

int count = ui->tagTreeWidget->selectedItems().count();

if (count <= 1) {
if (count == 1) {
on_tagTreeWidget_currentItemChanged( ui->tagTreeWidget->selectedItems().first(),
Q_NULLPTR);
}
return;
}

const QSignalBlocker blocker(ui->searchLineEdit);
Q_UNUSED(blocker)

Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down