Commit 6b0d0019 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Emit EventData for each day of a multi-day event

The applet itself does not resolve multi-day events, so if we
only generate single EventData for the whole event, it will only
show it on the one first day.
parent d5f73ef8
......@@ -178,7 +178,7 @@ void EventDataVisitorTest::testExplodeIncidenceOccurences_data()
const auto allTestData = TestDataParser::allTestData();
for (const auto &testData : allTestData) {
TestDataParser parser(testData);
TestDataParser parser(testData, true);
// skip non-recurring testcases
if (!parser.incidence()->recurs()) {
continue;
......@@ -275,7 +275,7 @@ void EventDataVisitorTest::testEventDataIdVisitor_data()
const auto allTestData = TestDataParser::allTestData();
for (const auto &testData : allTestData) {
TestDataParser parser(testData);
TestDataParser parser(testData, true);
QStringList uids;
Q_FOREACH (const auto &ed, parser.eventData()) {
uids.push_back(ed.uid());
......
......@@ -51,12 +51,12 @@ bool PimEventsPluginTest::compareEventDataHashes(const DateEventDataHash &actual
return true;
}
DateEventDataHash PimEventsPluginTest::populateCalendar(FakePimDataSource *source)
DateEventDataHash PimEventsPluginTest::populateCalendar(FakePimDataSource *source, bool uniqueEventData)
{
const QStringList allData = TestDataParser::allTestData();
DateEventDataHash expectedData;
Q_FOREACH (const QString &data, allData) {
TestDataParser parser(data);
TestDataParser parser(data, true);
if (parser.rangeEnd() < QDate(2016, 5, 1) || parser.rangeStart() > QDate(2016, 5, 31)) {
continue;
}
......@@ -65,7 +65,15 @@ DateEventDataHash PimEventsPluginTest::populateCalendar(FakePimDataSource *sourc
source->setAkonadiIdForIncidence(event, parser.akonadiId());
source->calendar()->addEvent(event);
Q_FOREACH (const CalendarEvents::EventData &dt, parser.eventData()) {
expectedData.insert(dt.startDateTime().date(), dt);
if (uniqueEventData) {
expectedData.insert(dt.startDateTime().date(), dt);
} else {
QDate d = dt.startDateTime().date();
while (d <= dt.endDateTime().date()) {
expectedData.insert(d, dt);
d = d.addDays(1);
}
}
}
}
}
......@@ -95,7 +103,7 @@ QVector<CalendarEvents::EventData> PimEventsPluginTest::findEventData(const KCal
void PimEventsPluginTest::testLoadEventsForDataRange()
{
FakePimDataSource source;
const DateEventDataHash expectedData = populateCalendar(&source);
const DateEventDataHash expectedData = populateCalendar(&source, false);
PimEventsPlugin plugin(&source);
QSignalSpy dataReadySpy(&plugin, &PimEventsPlugin::dataReady);
......@@ -125,7 +133,7 @@ void PimEventsPluginTest::testEventAdded()
Q_FOREACH (const QString &data, allData) {
TestDataParser parser(data);
TestDataParser parser(data, true);
if (parser.rangeEnd() < QDate(2016, 5, 1) || parser.rangeStart() > QDate(2016, 5, 31)) {
continue;
}
......@@ -135,7 +143,11 @@ void PimEventsPluginTest::testEventAdded()
source.calendar()->addEvent(event);
DateEventDataHash expectedData;
Q_FOREACH (const CalendarEvents::EventData &dt, parser.eventData()) {
expectedData.insert(dt.startDateTime().date(), dt);
QDate d = dt.startDateTime().date();
while (d <= dt.endDateTime().date()) {
expectedData.insert(d, dt);
d = d.addDays(1);
}
}
QCOMPARE(dataReadySpy.size(), 1);
......@@ -154,7 +166,7 @@ void PimEventsPluginTest::testEventModified()
QVERIFY(eventModifiedSpy.isValid());
// Populate model
const auto allData = populateCalendar(&source);
const auto allData = populateCalendar(&source, true);
// We don't care about the result of this, we just need to have mStart and
// mEnd set
......@@ -211,7 +223,7 @@ void PimEventsPluginTest::testEventRemoved()
QSignalSpy eventRemovedSpy(&plugin, &PimEventsPlugin::eventRemoved);
QVERIFY(eventRemovedSpy.isValid());
const auto allData = populateCalendar(&source);
const auto allData = populateCalendar(&source, true);
// We don't care about the result of this, we just need to have mStart and
// mEnd set
......
......@@ -46,7 +46,7 @@ private Q_SLOTS:
private:
bool compareEventDataHashes(const DateEventDataHash &actual,
const DateEventDataHash &expected);
DateEventDataHash populateCalendar(FakePimDataSource *source);
DateEventDataHash populateCalendar(FakePimDataSource *source, bool uniqueEventData);
QVector<CalendarEvents::EventData> findEventData(const KCalCore::Event::Ptr &event,
const DateEventDataHash &allData);
};
......
......@@ -31,8 +31,9 @@
#include <CalendarEvents/CalendarEventsPlugin>
TestDataParser::TestDataParser(const QString &testData)
TestDataParser::TestDataParser(const QString &testData, bool uniqueEventData)
: mTestData(testData)
, mUniqueEventData(uniqueEventData)
{
parse();
}
......@@ -125,7 +126,17 @@ void TestDataParser::parse()
const QDateTime endDateTime = parseDateTime(obj[QStringLiteral("endDateTime")].toObject());
eventData.setEndDateTime(endDateTime);
eventData.setUid(obj[QStringLiteral("uid")].toString());
mEventData.push_back(eventData);
if (mUniqueEventData) {
mEventData.push_back(eventData);
} else {
QDate d = startDateTime.date();
const QDate dateEnd = endDateTime.date();
while (d <= dateEnd) {
mEventData.push_back(eventData);
d = d.addDays(1);
}
}
}
QVERIFY(!mEventData.isEmpty());
}
......@@ -30,7 +30,7 @@ class QJsonObject;
class TestDataParser
{
public:
explicit TestDataParser(const QString &testData);
explicit TestDataParser(const QString &testData, bool uniqueEventData = false);
~TestDataParser();
QDate rangeStart() const;
......@@ -51,4 +51,5 @@ private:
qint64 mAkonadiId;
KCalCore::Incidence::Ptr mIncidence;
QVector<CalendarEvents::EventData> mEventData;
bool mUniqueEventData;
};
......@@ -147,12 +147,12 @@ bool EventDataVisitor::visit(const KCalCore::Incidence::Ptr &incidence,
const auto list = explodeIncidenceOccurences(data, incidence, ok);
if (ok) {
for (const auto &data : list) {
mResults.insert(data.startDateTime().date(), data);
insertResult(data);
}
}
return ok;
} else if (isInRange(data.startDateTime().date(), data.endDateTime().date())) {
mResults.insert(data.startDateTime().date(), data);
insertResult(data);
return true;
}
......@@ -169,6 +169,17 @@ bool EventDataVisitor::visit(const KCalCore::Todo::Ptr &todo)
return visit(todo, CalendarEvents::EventData::Todo);
}
void EventDataVisitor::insertResult(const CalendarEvents::EventData &result)
{
QDate d = result.startDateTime().date();
const QDate end = result.endDateTime().date();
while (d <= end) {
mResults.insert(d, result);
d = d.addDays(1);
}
}
CalendarEvents::EventData EventDataVisitor::incidenceData(const KCalCore::Incidence::Ptr &incidence) const
{
CalendarEvents::EventData data;
......
......@@ -63,6 +63,8 @@ protected:
bool visit(const KCalCore::Journal::Ptr &) Q_DECL_OVERRIDE { return false; }
bool visit(const KCalCore::FreeBusy::Ptr &) Q_DECL_OVERRIDE { return false; }
private:
void insertResult(const CalendarEvents::EventData &result);
bool visit(const KCalCore::Incidence::Ptr &incidence, CalendarEvents::EventData::EventType eventType);
CalendarEvents::EventData incidenceData(const KCalCore::Incidence::Ptr &incidence) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment