| 70 | |
| 71 | |
| 72 | QVariant ThreadFrameModel::data(const QModelIndex& index, int role) const |
| 73 | { |
| 74 | if (!index.isValid()) |
| 75 | return QVariant(); |
| 76 | |
| 77 | if (role != Qt::DisplayRole && role != Qt::SizeHintRole) |
| 78 | return QVariant(); |
| 79 | |
| 80 | if (index.column() >= columnCount()) |
| 81 | return QVariant(); |
| 82 | |
| 83 | FrameItem* item = static_cast<FrameItem*>(index.internalPointer()); |
| 84 | if (!item) |
| 85 | return QVariant(); |
| 86 | |
| 87 | // do not use columns other than thread info & state for thread rows |
| 88 | if (!item->isFrame() && index.column() > ThreadFrameModel::ThreadColumn) |
| 89 | return QVariant(); |
| 90 | |
| 91 | switch (index.column()) |
| 92 | { |
| 93 | case ThreadFrameModel::StateColumn: |
| 94 | { |
| 95 | if (item->isFrame()) |
| 96 | return QVariant(); |
| 97 | |
| 98 | QString text = item->isFrozen() ? "Frozen" : "Unfrozen"; |
| 99 | if (role == Qt::SizeHintRole) |
| 100 | return QVariant((qulonglong)text.size()); |
| 101 | |
| 102 | return QVariant(text); |
| 103 | } |
| 104 | case ThreadFrameModel::ThreadColumn: |
| 105 | { |
| 106 | if (item->isFrame()) |
| 107 | return QVariant(); |
| 108 | |
| 109 | auto isActiveThread = m_controller->GetActiveThread().m_tid == item->tid(); |
| 110 | |
| 111 | QString text = QString::asprintf("%s0x%x @ 0x%" PRIx64, isActiveThread ? "(*) " : "", item->tid(), item->threadPc()); |
| 112 | if (role == Qt::SizeHintRole) |
| 113 | return QVariant((qulonglong)text.size()); |
| 114 | |
| 115 | return QVariant(text); |
| 116 | } |
| 117 | case ThreadFrameModel::FrameIndexColumn: |
| 118 | { |
| 119 | QString text = QString::asprintf("%lu", item->frameIndex()); |
| 120 | if (role == Qt::SizeHintRole) |
| 121 | return QVariant((qulonglong)text.size()); |
| 122 | |
| 123 | return QVariant(text); |
| 124 | } |
| 125 | case ThreadFrameModel::ModuleColumn: |
| 126 | { |
| 127 | QString text = QString::fromStdString(item->module()); |
| 128 | if (role == Qt::SizeHintRole) |
| 129 | return QVariant((qulonglong)text.size()); |