| 69 | } |
| 70 | |
| 71 | QVariant MetaObjectTreeClientProxyModel::data(const QModelIndex &index, int role) const |
| 72 | { |
| 73 | if (!sourceModel() || !index.isValid()) |
| 74 | return QVariant(); |
| 75 | |
| 76 | if (index.column() == QMetaObjectModel::ObjectColumn) { |
| 77 | const auto issues = QIdentityProxyModel::data(index, QMetaObjectModel::MetaObjectIssues).value<QMetaObjectValidatorResult::Results>(); |
| 78 | switch (role) { |
| 79 | case Qt::DecorationRole: |
| 80 | if (issues != QMetaObjectValidatorResult::NoIssue) |
| 81 | return qApp->style()->standardIcon(QStyle::SP_MessageBoxWarning); |
| 82 | break; |
| 83 | case Qt::ToolTipRole: { |
| 84 | if (issues != QMetaObjectValidatorResult::NoIssue) |
| 85 | return issuesToString(issues); |
| 86 | const auto invalid = index.sibling(index.row(), QMetaObjectModel::ObjectInclusiveAliveCountColumn).data(QMetaObjectModel::MetaObjectInvalid).toBool(); |
| 87 | if (invalid) |
| 88 | return tr("This meta object might have been deleted."); |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | return QIdentityProxyModel::data(index, role); |
| 93 | } |
| 94 | |
| 95 | if ((role != Qt::BackgroundRole && role != Qt::ToolTipRole) || !m_qobjIndex.isValid()) |
| 96 | return QIdentityProxyModel::data(index, role); |
| 97 | |
| 98 | if (!needsBackground(index)) |
| 99 | return QIdentityProxyModel::data(index, role); // top-level but not QObject, or QObject incl count |
| 100 | |
| 101 | const auto count = index.data(Qt::DisplayRole).toInt(); |
| 102 | if (count <= 0) |
| 103 | return QIdentityProxyModel::data(index, role); |
| 104 | |
| 105 | const auto totalColumn = (index.column() == QMetaObjectModel::ObjectSelfCountColumn || index.column() == QMetaObjectModel::ObjectInclusiveCountColumn) ? QMetaObjectModel::ObjectInclusiveCountColumn : QMetaObjectModel::ObjectInclusiveAliveCountColumn; |
| 106 | const auto totalCount = m_qobjIndex.sibling(m_qobjIndex.row(), totalColumn).data().toInt(); |
| 107 | const auto ratio = ( double )count / ( double )totalCount; |
| 108 | |
| 109 | // at this point, role can only be background or tooltip |
| 110 | |
| 111 | if (role == Qt::BackgroundRole) |
| 112 | return colorForRatio(ratio); |
| 113 | |
| 114 | Q_ASSERT(role == Qt::ToolTipRole); |
| 115 | return tr("%1%").arg(ratio * 100.0, 0, 'f', 2); |
| 116 | } |
| 117 | |
| 118 | QVariant MetaObjectTreeClientProxyModel::headerData(int section, Qt::Orientation orientation, int role) const |
| 119 | { |
no test coverage detected