MCPcopy Create free account
hub / github.com/KDE/kdevelop / previousItemIndex

Method previousItemIndex

plugins/grepview/grepoutputmodel.cpp:263–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

261}
262
263QModelIndex GrepOutputModel::previousItemIndex(const QModelIndex &currentIdx) 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
310QModelIndex GrepOutputModel::nextItemIndex(const QModelIndex &currentIdx) const
311{

Callers 1

selectPreviousItemMethod · 0.80

Calls 8

isTextMethod · 0.80
QModelIndexClass · 0.70
isValidMethod · 0.45
childMethod · 0.45
rowCountMethod · 0.45
indexMethod · 0.45
parentMethod · 0.45
rowMethod · 0.45

Tested by

no test coverage detected