QVariant SailorgramContactsModel::data(const QModelIndex &proxyIndex, int role) const { QModelIndex sourceindex = this->mapToSource(proxyIndex); if(role == SailorgramContactsModel::FirstLetterRole) { UserObject* user = this->_telegramdialoglistmodel->data(sourceindex, TelegramDialogListModel::RoleUserItem).value<UserObject*>(); return !user->firstName().isEmpty() ? user->firstName().mid(0, 1).toUpper() : user->lastName().mid(0, 1).toUpper(); } return this->_telegramdialoglistmodel->data(sourceindex, role); }
QVariant SailorgramContactsModel::data(const QModelIndex &proxyIndex, int role) const { if(!this->_telegramcontactsmodel) return QVariant(); QModelIndex sourceindex = this->mapToSource(proxyIndex); if((role == SailorgramContactsModel::UserRole) || (role == SailorgramContactsModel::LetterRole)) { ContactObject* contact = this->_telegramcontactsmodel->data(sourceindex, TelegramContactsModel::ItemRole).value<ContactObject*>(); TelegramQml* telegram = this->_telegramcontactsmodel->telegram(); UserObject* user = telegram->user(contact->userId()); if(role == SailorgramContactsModel::UserRole) return QVariant::fromValue(user); // Letter Role return !user->firstName().isEmpty() ? user->firstName().mid(0, 1).toUpper() : user->lastName().mid(0, 1).toUpper(); } else if(role == SailorgramContactsModel::ContactRole) return this->_telegramcontactsmodel->data(sourceindex, TelegramContactsModel::ItemRole); return this->_telegramcontactsmodel->data(sourceindex, role); }