presentation/CommandBarRowModel.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "CommandBarRowModel.h" | ||
| 2 | |||
| 3 | 26118 | int CommandBarRowModel::rowCount(const QModelIndex &parent) const { | |
| 4 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 26118 times.
|
26118 | return parent.isValid() ? 0 : int(m_rows.size()); |
| 5 | } | ||
| 6 | |||
| 7 | 8316 | QVariant CommandBarRowModel::data(const QModelIndex &index, int role) const { | |
| 8 |
4/8✓ Branch 3 → 4 taken 8316 times.
✗ Branch 3 → 9 not taken.
✓ Branch 5 → 6 taken 8316 times.
✗ Branch 5 → 9 not taken.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 8316 times.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 8316 times.
|
8316 | if (!index.isValid() || index.row() < 0 || index.row() >= m_rows.size()) return {}; |
| 9 |
3/3✓ Branch 13 → 14 taken 5928 times.
✓ Branch 13 → 20 taken 2388 times.
✓ Branch 16 → 17 taken 5928 times.
|
8316 | if (role == GroupRole) return groupOf(m_rows.at(index.row())); |
| 10 |
1/2✓ Branch 20 → 21 taken 2388 times.
✗ Branch 20 → 24 not taken.
|
2388 | return role == RowRole ? m_rows.at(index.row()) : QVariant{}; |
| 11 | } | ||
| 12 | |||
| 13 | 816 | QHash<int, QByteArray> CommandBarRowModel::roleNames() const { | |
| 14 |
2/4✓ Branch 6 → 7 taken 1632 times.
✓ Branch 6 → 8 taken 816 times.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
|
2448 | return {{RowRole, "rowData"}, {GroupRole, "group"}}; |
| 15 | 816 | } | |
| 16 | |||
| 17 | 8388 | QString CommandBarRowModel::groupOf(const QVariant &row) { | |
| 18 |
3/3✓ Branch 2 → 3 taken 8388 times.
✓ Branch 7 → 8 taken 8388 times.
✓ Branch 8 → 9 taken 8388 times.
|
16776 | return row.toMap().value(QStringLiteral("group")).toString(); |
| 19 | } | ||
| 20 | |||
| 21 | 1166 | void CommandBarRowModel::setRows(const QVariantList &rows) { | |
| 22 | 1166 | const int common = int(qMin(m_rows.size(), rows.size())); | |
| 23 |
2/2✓ Branch 20 → 6 taken 1230 times.
✓ Branch 20 → 21 taken 852 times.
|
2082 | for (int i = 0; i < common; ++i) { |
| 24 |
4/4✓ Branch 7 → 8 taken 1230 times.
✓ Branch 9 → 10 taken 1230 times.
✓ Branch 13 → 14 taken 916 times.
✓ Branch 13 → 15 taken 314 times.
|
1230 | if (groupOf(m_rows.at(i)) == groupOf(rows.at(i))) continue; |
| 25 | 314 | beginResetModel(); | |
| 26 | 314 | m_rows = rows; | |
| 27 | 314 | endResetModel(); | |
| 28 | 314 | return; | |
| 29 | } | ||
| 30 |
2/2✓ Branch 23 → 24 taken 180 times.
✓ Branch 23 → 31 taken 672 times.
|
852 | if (rows.size() < m_rows.size()) { |
| 31 |
1/1✓ Branch 27 → 28 taken 180 times.
|
180 | beginRemoveRows({}, int(rows.size()), int(m_rows.size()) - 1); |
| 32 | 180 | m_rows.resize(rows.size()); | |
| 33 | 180 | endRemoveRows(); | |
| 34 | } | ||
| 35 | 852 | int first = -1; | |
| 36 | 852 | int last = -1; | |
| 37 |
2/2✓ Branch 44 → 32 taken 916 times.
✓ Branch 44 → 45 taken 852 times.
|
1768 | for (int i = 0; i < common; ++i) { |
| 38 |
2/2✓ Branch 35 → 36 taken 417 times.
✓ Branch 35 → 37 taken 499 times.
|
916 | if (m_rows.at(i) == rows.at(i)) continue; |
| 39 | 499 | m_rows[i] = rows.at(i); | |
| 40 |
2/2✓ Branch 40 → 41 taken 220 times.
✓ Branch 40 → 42 taken 279 times.
|
499 | if (first < 0) first = i; |
| 41 | 499 | last = i; | |
| 42 | } | ||
| 43 |
6/6✓ Branch 45 → 46 taken 220 times.
✓ Branch 45 → 54 taken 632 times.
✓ Branch 46 → 47 taken 220 times.
✓ Branch 48 → 49 taken 220 times.
✓ Branch 50 → 51 taken 220 times.
✓ Branch 51 → 52 taken 220 times.
|
852 | if (first >= 0) emit dataChanged(index(first), index(last), {RowRole}); |
| 44 |
2/2✓ Branch 56 → 57 taken 312 times.
✓ Branch 56 → 68 taken 540 times.
|
852 | if (rows.size() > m_rows.size()) { |
| 45 |
1/1✓ Branch 60 → 61 taken 312 times.
|
312 | beginInsertRows({}, int(m_rows.size()), int(rows.size()) - 1); |
| 46 |
2/2✓ Branch 66 → 62 taken 1584 times.
✓ Branch 66 → 67 taken 312 times.
|
1896 | for (qsizetype i = m_rows.size(); i < rows.size(); ++i) m_rows.append(rows.at(i)); |
| 47 | 312 | endInsertRows(); | |
| 48 | } | ||
| 49 | } | ||
| 50 |