Group GroupModel::group(const QModelIndex &index) const { GroupObject *go = d->groups.value(index.row()); if (go) return go->toGroup(); return Group(); }
QVariant GroupModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() >= d->groups.count()) { return QVariant(); } GroupObject *group = d->groups.value(index.row()); if (!group) return QVariant(); if (role == GroupRole) { return QVariant::fromValue(group->toGroup()); } else if (role == GroupObjectRole) { return QVariant::fromValue<QObject*>(group); } else if (role == ContactIdsRole) { return QVariant::fromValue(group->contactIds()); } else if (role == WeekdaySectionRole) { QDateTime dateTime = group->endTime().toLocalTime(); // Return the date for the past week, and group all older items together under an // arbitrary older date const int daysDiff = QDate::currentDate().toJulianDay() - dateTime.date().toJulianDay(); if (daysDiff < 7) return dateTime.date(); // Arbitrary static date for older items.. return QDate(2000, 1, 1); } int column = index.column(); if (role >= BaseRole) { column = role - BaseRole; role = Qt::DisplayRole; } if (role != Qt::DisplayRole) { return QVariant(); } QVariant var; switch (column) { case GroupId: var = QVariant::fromValue(group->id()); break; case LocalUid: var = QVariant::fromValue(group->localUid()); break; case RemoteUids: var = QVariant::fromValue(group->remoteUids()); break; case ChatName: var = QVariant::fromValue(group->chatName()); break; case EndTime: var = QVariant::fromValue(group->endTime()); break; case TotalMessages: var = QVariant::fromValue(group->totalMessages()); break; case UnreadMessages: var = QVariant::fromValue(group->unreadMessages()); break; case SentMessages: var = QVariant::fromValue(group->sentMessages()); break; case LastEventId: var = QVariant::fromValue(group->lastEventId()); break; case Contacts: var = QVariant::fromValue(group->contacts()); break; case LastMessageText: var = QVariant::fromValue(group->lastMessageText()); break; case LastVCardFileName: var = QVariant::fromValue(group->lastVCardFileName()); break; case LastVCardLabel: var = QVariant::fromValue(group->lastVCardLabel()); break; case LastEventType: var = QVariant::fromValue((int)group->lastEventType()); break; case LastEventStatus: var = QVariant::fromValue((int)group->lastEventStatus()); break; case LastModified: var = QVariant::fromValue(group->lastModified()); break; case StartTime: var = QVariant::fromValue(group->startTime()); break; default: qDebug() << "Group::data: invalid column id??" << column; break; } return var; }