| 89 | } |
| 90 | |
| 91 | QModelIndex find(const QModelIndex &start, const QString &value, bool reverse) const |
| 92 | { |
| 93 | QModelIndex parentIndex = parent(start); |
| 94 | auto compare = [&](int r) -> QModelIndex |
| 95 | { |
| 96 | QModelIndex idx = index(r, start.column(), parentIndex); |
| 97 | if (!idx.isValid() || idx == start) |
| 98 | { |
| 99 | return QModelIndex(); |
| 100 | } |
| 101 | QVariant v = data(idx, Qt::DisplayRole); |
| 102 | QString t = v.toString(); |
| 103 | if (t.contains(value, Qt::CaseInsensitive)) |
| 104 | return idx; |
| 105 | return QModelIndex(); |
| 106 | }; |
| 107 | if(reverse) |
| 108 | { |
| 109 | int from = start.row(); |
| 110 | int to = 0; |
| 111 | |
| 112 | for (int i = 0; i < 2; ++i) |
| 113 | { |
| 114 | for (int r = from; (r >= to); --r) |
| 115 | { |
| 116 | auto idx = compare(r); |
| 117 | if(idx.isValid()) |
| 118 | return idx; |
| 119 | } |
| 120 | // prepare for the next iteration |
| 121 | from = rowCount() - 1; |
| 122 | to = start.row(); |
| 123 | } |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | int from = start.row(); |
| 128 | int to = rowCount(parentIndex); |
| 129 | |
| 130 | for (int i = 0; i < 2; ++i) |
| 131 | { |
| 132 | for (int r = from; (r < to); ++r) |
| 133 | { |
| 134 | auto idx = compare(r); |
| 135 | if(idx.isValid()) |
| 136 | return idx; |
| 137 | } |
| 138 | // prepare for the next iteration |
| 139 | from = 0; |
| 140 | to = start.row(); |
| 141 | } |
| 142 | } |
| 143 | return QModelIndex(); |
| 144 | } |
| 145 | private: |
| 146 | QFont m_font; |
| 147 | std::unique_ptr<LogColorCache> m_colors; |
no test coverage detected