| 261 | } |
| 262 | |
| 263 | QModelIndex GrepOutputModel::previousItemIndex(const QModelIndex ¤tIdx) const |
| 264 | { |
| 265 | GrepOutputItem* current_item = nullptr; |
| 266 | |
| 267 | if (!currentIdx.isValid()) { |
| 268 | // no item selected, search recursively for the last item in search results |
| 269 | QStandardItem *it = item(0,0); |
| 270 | while (it) { |
| 271 | QStandardItem *child = it->child( it->rowCount() - 1 ); |
| 272 | if (!child) return it->index(); |
| 273 | it = child; |
| 274 | } |
| 275 | return QModelIndex(); |
| 276 | } |
| 277 | else |
| 278 | current_item = static_cast<GrepOutputItem*>(itemFromIndex(currentIdx)); |
| 279 | |
| 280 | if (current_item->parent() != nullptr) { |
| 281 | int row = currentIdx.row(); |
| 282 | |
| 283 | if(!current_item->isText()) // the item is a file |
| 284 | { |
| 285 | int item_row = current_item->row(); |
| 286 | if(item_row > 0) |
| 287 | { |
| 288 | int idx_last_item = current_item->parent()->child(item_row - 1)->rowCount() - 1; |
| 289 | return current_item->parent()->child(item_row - 1)->child(idx_last_item)->index(); |
| 290 | } |
| 291 | } |
| 292 | else // the item is a match |
| 293 | { |
| 294 | if(row > 0) |
| 295 | return current_item->parent()->child(row - 1)->index(); |
| 296 | else // we return the index of the last item of the previous file |
| 297 | { |
| 298 | int parrent_row = current_item->parent()->row(); |
| 299 | if(parrent_row > 0) |
| 300 | { |
| 301 | int idx_last_item = current_item->parent()->parent()->child(parrent_row - 1)->rowCount() - 1; |
| 302 | return current_item->parent()->parent()->child(parrent_row - 1)->child(idx_last_item)->index(); |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | return currentIdx; |
| 308 | } |
| 309 | |
| 310 | QModelIndex GrepOutputModel::nextItemIndex(const QModelIndex ¤tIdx) const |
| 311 | { |
no test coverage detected