Commit f681c514 authored by David Jarvie's avatar David Jarvie

Fix collection ID not being set in some events => deletions failed

parent 4930ff01
......@@ -1260,24 +1260,37 @@ void AkonadiModel::getChildEvents(const QModelIndex& parent, CalEvent::Type type
}
#endif
KAEvent AkonadiModel::event(const QModelIndex& index) const
{
return event(index.data(ItemRole).value<Item>());
}
KAEvent AkonadiModel::event(Item::Id itemId) const
{
QModelIndex ix = itemIndex(itemId);
if (!ix.isValid())
return KAEvent();
return event(ix);
return event(ix.data(ItemRole).value<Item>(), ix, 0);
}
KAEvent AkonadiModel::event(const QModelIndex& index) const
{
return event(index.data(ItemRole).value<Item>(), index, 0);
}
KAEvent AkonadiModel::event(const Item& item) const
KAEvent AkonadiModel::event(const Item& item, const QModelIndex& index, Collection* collection) const
{
if (!item.isValid() || !item.hasPayload<KAEvent>())
return KAEvent();
return item.payload<KAEvent>();
const QModelIndex ix = index.isValid() ? index : itemIndex(item.id());
if (!ix.isValid())
return KAEvent();
KAEvent e = item.payload<KAEvent>();
if (e.isValid())
{
Collection c = data(index, ParentCollectionRole).value<Collection>();
// Set collection ID using a const method, to avoid unnecessary copying of KAEvent
e.setCollectionId_const(c.id());
if (collection)
*collection = c;
}
return e;
}
#if 0
......@@ -1629,14 +1642,11 @@ AkonadiModel::EventList AkonadiModel::eventList(const QModelIndex& parent, int s
EventList events;
for (int row = start; row <= end; ++row)
{
Collection c;
QModelIndex ix = index(row, 0, parent);
KAEvent evnt = event(ix.data(ItemRole).value<Item>());
KAEvent evnt = event(ix.data(ItemRole).value<Item>(), ix, &c);
if (evnt.isValid())
{
Collection c = data(ix, ParentCollectionRole).value<Collection>();
evnt.setCollectionId(c.id());
events += Event(evnt, c);
}
}
return events;
}
......
......@@ -144,7 +144,7 @@ class AkonadiModel : public Akonadi::EntityTreeModel
/** Return the alarm with the specified unique identifier.
* @return the event, or invalid event if no such event exists.
*/
KAEvent event(const Akonadi::Item&) const;
KAEvent event(const Akonadi::Item& item) const { return event(item, QModelIndex(), 0); }
KAEvent event(Akonadi::Item::Id) const;
KAEvent event(const QModelIndex&) const;
using QObject::event; // prevent warning about hidden virtual method
......@@ -279,6 +279,7 @@ class AkonadiModel : public Akonadi::EntityTreeModel
};
AkonadiModel(Akonadi::ChangeRecorder*, QObject* parent);
KAEvent event(const Akonadi::Item&, const QModelIndex&, Akonadi::Collection*) const;
QString alarmTimeText(const DateTime&) const;
QString timeToAlarmText(const DateTime&) const;
void signalDataChanged(bool (*checkFunc)(const Akonadi::Item&), int startColumn, int endColumn, const QModelIndex& parent);
......
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