Skip to content

Commit

Permalink
Fix out of bounds and sort issue
Browse files Browse the repository at this point in the history
Was a bug when switching between item/tab view where out of bounds errors could occur.

Fix refresh sorting issue on view change

Make warnings more explicit and 'safer'.  This by itself would have fixed crashes caused by calling rowCount in
old assertion with out-of-date parent.
  • Loading branch information
ericsium committed May 7, 2016
1 parent dc93bd8 commit 844a0be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/items_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,18 @@ QModelIndex ItemsModel::parent(const QModelIndex &index) const {
}

QModelIndex ItemsModel::index(int row, int column, const QModelIndex &parent) const {
// bucket
if (row < 0 || row >= rowCount(parent) || column < 0 || column >= columnCount(parent)) {
QLOG_WARN() << "Unexpected Index request: row(" << row << ") maxrow(" << rowCount(parent)
<< ") col(" << column << ") maxcol(" << columnCount(parent);
return QModelIndex();
}

if (parent.isValid()) {
if (parent.row() >= (signed)search_.buckets().size()) {
QLOG_WARN() << "Should not happen: Index request parent contains invalid row";
return QModelIndex();
}
// item, we pass parent's (bucket's) row through ID parameter
return createIndex(row, column, static_cast<quintptr>(parent.row() + 1));
} else {
if (row >= (signed)search_.buckets().size()) {
QLOG_WARN() << "Index request asking for invalid row";
return QModelIndex();
}
return createIndex(row, column, static_cast<quintptr>(0));
}
}
3 changes: 2 additions & 1 deletion src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ void Search::SetViewMode(ViewMode mode)

current_mode_ = mode;
// Force immediate view update
view_->doItemsLayout();
view_->reset();
model_->SetSorted(false);
model_->sort();

if (mode == ByTab)
Expand Down

0 comments on commit 844a0be

Please sign in to comment.