* Dump an item model. * @param model item model to dump * @param parent parent model index * @param indent number of spaces to indent */
| 82 | * @param indent number of spaces to indent |
| 83 | */ |
| 84 | void DebugUtils::dumpModel(const QAbstractItemModel& model, |
| 85 | const QModelIndex& parent, int indent) |
| 86 | { |
| 87 | if (indent == 0) { |
| 88 | QString name(model.objectName()); |
| 89 | if (name.isEmpty()) { |
| 90 | if (const QMetaObject* metaObject = model.metaObject()) { |
| 91 | name = QString::fromLatin1(metaObject->className()); |
| 92 | } |
| 93 | } |
| 94 | qDebug("Dump for %s", qPrintable(name)); |
| 95 | QString columnStr; |
| 96 | for (int i = 0; i < model.columnCount(parent); ++i) { |
| 97 | if (i != 0) |
| 98 | columnStr += QLatin1String(", "); |
| 99 | columnStr += QString::number(i); |
| 100 | columnStr += QLatin1String(": "); |
| 101 | columnStr += model.headerData(i, Qt::Horizontal).toString(); |
| 102 | } |
| 103 | qDebug("%s", qPrintable(columnStr)); |
| 104 | } |
| 105 | if (!model.hasChildren(parent)) |
| 106 | return; |
| 107 | |
| 108 | for (int row = 0; row < model.rowCount(parent); ++row) { |
| 109 | QString rowStr(indent, QLatin1Char(' ')); |
| 110 | QString rowHeader(model.headerData(row, Qt::Vertical).toString()); |
| 111 | rowStr += QString::number(row); |
| 112 | if (!rowHeader.isEmpty()) { |
| 113 | rowStr += QLatin1Char(' '); |
| 114 | rowStr += rowHeader; |
| 115 | } |
| 116 | rowStr += QLatin1Char(':'); |
| 117 | QModelIndexList indexesWithChildren; |
| 118 | for (int column = 0; column < model.columnCount(parent); ++column) { |
| 119 | QModelIndex idx(model.index(row, column, parent)); |
| 120 | if (column > 0) |
| 121 | rowStr += QLatin1String(","); |
| 122 | rowStr += QString(QLatin1String("%1%2:")) |
| 123 | .arg(model.hasChildren(idx) ? QLatin1String("p") : QLatin1String("")) |
| 124 | .arg(column); |
| 125 | rowStr += model.data(idx).toString(); |
| 126 | if (model.hasChildren(idx)) |
| 127 | indexesWithChildren.append(idx); |
| 128 | } |
| 129 | qDebug("%s", qPrintable(rowStr)); |
| 130 | const auto idxs = indexesWithChildren; |
| 131 | for (const QModelIndex& idx : idxs) { |
| 132 | dumpModel(model, idx, indent + 2); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | #else |
| 138 |
nothing calls this directly
no test coverage detected