UI: *Model: Don't emit dataChanged() with invalid indexes

This commit is contained in:
Nodir Temirkhodjaev 2024-10-29 17:11:10 +05:00
parent 1ab3cb60b8
commit 60ba3b2bca
2 changed files with 10 additions and 2 deletions

View File

@ -103,8 +103,12 @@ void StringListModel::reset()
void StringListModel::refresh()
{
const int rowCount = this->rowCount();
if (rowCount <= 0)
return;
const auto firstCell = index(0, 0);
const auto lastCell = index(rowCount() - 1, 0);
const auto lastCell = index(rowCount - 1, 0);
emit dataChanged(firstCell, lastCell);
}

View File

@ -65,8 +65,12 @@ void TableItemModel::refresh()
{
invalidateRowCache();
const int rowCount = this->rowCount();
if (rowCount <= 0)
return;
const auto firstCell = index(0, 0);
const auto lastCell = index(rowCount() - 1, columnCount(firstCell) - 1);
const auto lastCell = index(rowCount - 1, columnCount(firstCell) - 1);
emit dataChanged(firstCell, lastCell);
}