diff --git a/autotests/testmemorycalendar.h b/autotests/testmemorycalendar.h --- a/autotests/testmemorycalendar.h +++ b/autotests/testmemorycalendar.h @@ -23,6 +23,7 @@ void testRecurrenceExceptions(); void testChangeRecurId(); void testRawEventsForDate(); + void testVisibility(); }; #endif diff --git a/autotests/testmemorycalendar.cpp b/autotests/testmemorycalendar.cpp --- a/autotests/testmemorycalendar.cpp +++ b/autotests/testmemorycalendar.cpp @@ -307,3 +307,22 @@ cal->close(); } + +void MemoryCalendarTest::testVisibility() +{ + MemoryCalendar::Ptr cal(new MemoryCalendar(QTimeZone::utc())); + const QString notebook = QLatin1String("Notebook"); + + QVERIFY(cal->addNotebook(notebook, true)); + QVERIFY(cal->isVisible(notebook)); + + Event::Ptr event = Event::Ptr(new Event()); + QVERIFY(cal->addIncidence(event)); + QVERIFY(cal->setNotebook(event, notebook)); + + QVERIFY(cal->isVisible(event)); + + QVERIFY(cal->updateNotebook(notebook, false)); + QVERIFY(!cal->isVisible(notebook)); + QVERIFY(!cal->isVisible(event)); +} diff --git a/src/calendar.h b/src/calendar.h --- a/src/calendar.h +++ b/src/calendar.h @@ -483,6 +483,13 @@ */ Q_REQUIRED_RESULT bool isVisible(const Incidence::Ptr &incidence) const; + /** + Check if notebook is visible. + @param notebook notebook uid. + @return true if notebook is visible, false otherwise + */ + Q_REQUIRED_RESULT bool isVisible(const QString ¬ebook) const; + /** List all notebook incidences in the memory. diff --git a/src/calendar.cpp b/src/calendar.cpp --- a/src/calendar.cpp +++ b/src/calendar.cpp @@ -324,6 +324,12 @@ return false; } else { d->mNotebooks.insert(notebook, isVisible); + const QList incidences = d->mNotebookIncidences.values(notebook); + for (Incidence::Ptr incidence : incidences) { + QHash::Iterator it = d->mIncidenceVisibility.find(incidence); + if (it != d->mIncidenceVisibility.end()) + *it = isVisible; + } return true; } } @@ -374,6 +380,12 @@ return rv; } +bool Calendar::isVisible(const QString ¬ebook) const +{ + QHash::ConstIterator it = d->mNotebooks.find(notebook); + return (it != d->mNotebooks.constEnd()) ? *it : true; +} + void Calendar::clearNotebookAssociations() { d->mNotebookIncidences.clear();