| 308 | } |
| 309 | |
| 310 | QModelIndex GrepOutputModel::nextItemIndex(const QModelIndex ¤tIdx) const |
| 311 | { |
| 312 | GrepOutputItem* current_item = nullptr; |
| 313 | |
| 314 | if (!currentIdx.isValid()) { |
| 315 | QStandardItem *it = item(0,0); |
| 316 | if (!it) return QModelIndex(); |
| 317 | current_item = static_cast<GrepOutputItem*>(it); |
| 318 | } |
| 319 | else |
| 320 | current_item = static_cast<GrepOutputItem*>(itemFromIndex(currentIdx)); |
| 321 | |
| 322 | if (current_item->parent() == nullptr) { |
| 323 | // root item with overview of search results |
| 324 | if (current_item->rowCount() > 0) |
| 325 | return nextItemIndex(current_item->child(0)->index()); |
| 326 | else |
| 327 | return QModelIndex(); |
| 328 | } else { |
| 329 | int row = currentIdx.row(); |
| 330 | if(!current_item->isText()) // the item is a file |
| 331 | { |
| 332 | int item_row = current_item->row(); |
| 333 | if(item_row < current_item->parent()->rowCount()) |
| 334 | { |
| 335 | return current_item->parent()->child(item_row)->child(0)->index(); |
| 336 | } |
| 337 | } |
| 338 | else // the item is a match |
| 339 | { |
| 340 | if(row < current_item->parent()->rowCount() - 1) |
| 341 | return current_item->parent()->child(row + 1)->index(); |
| 342 | else // we return the index of the first item of the next file |
| 343 | { |
| 344 | int parrent_row = current_item->parent()->row(); |
| 345 | if(parrent_row < current_item->parent()->parent()->rowCount() - 1) |
| 346 | { |
| 347 | return current_item->parent()->parent()->child(parrent_row + 1)->child(0)->index(); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | return currentIdx; |
| 353 | } |
| 354 | |
| 355 | const GrepOutputItem *GrepOutputModel::getRootItem() const { |
| 356 | return m_rootItem; |