From 60ba3b2bca73504064a689e5499674a88332c34c Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Tue, 29 Oct 2024 17:11:10 +0500 Subject: [PATCH] UI: *Model: Don't emit dataChanged() with invalid indexes --- src/ui/util/model/stringlistmodel.cpp | 6 +++++- src/ui/util/model/tableitemmodel.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ui/util/model/stringlistmodel.cpp b/src/ui/util/model/stringlistmodel.cpp index f909c382..9bcfceea 100644 --- a/src/ui/util/model/stringlistmodel.cpp +++ b/src/ui/util/model/stringlistmodel.cpp @@ -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); } diff --git a/src/ui/util/model/tableitemmodel.cpp b/src/ui/util/model/tableitemmodel.cpp index 81da6fa5..eeffa5e3 100644 --- a/src/ui/util/model/tableitemmodel.cpp +++ b/src/ui/util/model/tableitemmodel.cpp @@ -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); }