Skip to content

Commit

Permalink
Merge pull request #1481 from Waqar144/mul-tags
Browse files Browse the repository at this point in the history
Implement filtering by multiple tags
  • Loading branch information
pbek authored Dec 5, 2019
2 parents 9033dab + 5f9bba7 commit a6dcd75
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
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

0 comments on commit a6dcd75

Please sign in to comment.