| 49 | } |
| 50 | |
| 51 | QVariant ReadingListModel::data(const QModelIndex &index, int role) const |
| 52 | { |
| 53 | if (!index.isValid()) |
| 54 | return QVariant(); |
| 55 | |
| 56 | auto item = static_cast<ListItem *>(index.internalPointer()); |
| 57 | |
| 58 | if (role == ReadingListModel::TypeListsRole) { |
| 59 | if (typeid(*item) == typeid(SpecialListItem)) |
| 60 | return QVariant(ReadingListModel::SpecialList); |
| 61 | |
| 62 | if (typeid(*item) == typeid(LabelItem)) |
| 63 | return QVariant(ReadingListModel::Label); |
| 64 | |
| 65 | if (typeid(*item) == typeid(ReadingListItem)) |
| 66 | return QVariant(ReadingListModel::ReadingList); |
| 67 | |
| 68 | if (typeid(*item) == typeid(ReadingListSeparatorItem)) |
| 69 | return QVariant(ReadingListModel::Separator); |
| 70 | } |
| 71 | |
| 72 | if (role == ReadingListModel::LabelColorRole && typeid(*item) == typeid(LabelItem)) { |
| 73 | auto labelItem = static_cast<LabelItem *>(item); |
| 74 | return QVariant(labelItem->colorid()); |
| 75 | } |
| 76 | |
| 77 | if (role == ReadingListModel::IDRole) { |
| 78 | QLOG_DEBUG() << "getting role"; |
| 79 | return item->getId(); |
| 80 | } |
| 81 | |
| 82 | if (role == ReadingListModel::SpecialListTypeRole && typeid(*item) == typeid(SpecialListItem)) { |
| 83 | auto specialListItem = static_cast<SpecialListItem *>(item); |
| 84 | return QVariant::fromValue(specialListItem->getType()); |
| 85 | } |
| 86 | |
| 87 | if (typeid(*item) == typeid(ReadingListSeparatorItem)) |
| 88 | return QVariant(); |
| 89 | |
| 90 | if (role == Qt::DecorationRole) { |
| 91 | return QVariant(item->getIcon()); |
| 92 | } |
| 93 | |
| 94 | if (role != Qt::DisplayRole) |
| 95 | return QVariant(); |
| 96 | |
| 97 | return item->data(index.column()); |
| 98 | } |
| 99 | |
| 100 | Qt::ItemFlags ReadingListModel::flags(const QModelIndex &index) const |
| 101 | { |
no test coverage detected