Don't try getting data for invalid indices

BUG: 470639
This commit is contained in:
Tobias Fella
2023-06-08 14:48:59 +02:00
parent bc4c4f8519
commit 22107fc598

View File

@@ -50,10 +50,11 @@ QString CollapseStateProxyModel::aggregateEventToString(int sourceRow) const
if (!uniqueAuthors.contains(nextAuthor)) { if (!uniqueAuthors.contains(nextAuthor)) {
uniqueAuthors.append(nextAuthor); uniqueAuthors.append(nextAuthor);
} }
if (sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::DelegateTypeRole) if (i > 0
!= MessageEventModel::DelegateType::State // If it's not a state event && (sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::DelegateTypeRole)
|| sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::ShowSectionRole).toBool() // or the section needs to be visible != MessageEventModel::DelegateType::State // If it's not a state event
) { || sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::ShowSectionRole).toBool() // or the section needs to be visible
)) {
break; break;
} }
} }
@@ -108,10 +109,11 @@ QVariantList CollapseStateProxyModel::stateEventsList(int sourceRow) const
{"text", sourceModel()->data(sourceModel()->index(i, 0), Qt::DisplayRole).toString()}, {"text", sourceModel()->data(sourceModel()->index(i, 0), Qt::DisplayRole).toString()},
}; };
stateEvents.append(nextState); stateEvents.append(nextState);
if (sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::DelegateTypeRole) if (i > 0
!= MessageEventModel::DelegateType::State // If it's not a state event && (sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::DelegateTypeRole)
|| sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::ShowSectionRole).toBool() // or the section needs to be visible != MessageEventModel::DelegateType::State // If it's not a state event
) { || sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::ShowSectionRole).toBool() // or the section needs to be visible
)) {
break; break;
} }
} }
@@ -126,10 +128,11 @@ QVariantList CollapseStateProxyModel::authorList(int sourceRow) const
if (!uniqueAuthors.contains(nextAvatar)) { if (!uniqueAuthors.contains(nextAvatar)) {
uniqueAuthors.append(nextAvatar); uniqueAuthors.append(nextAvatar);
} }
if (sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::DelegateTypeRole) if (i > 0
!= MessageEventModel::DelegateType::State // If it's not a state event && (sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::DelegateTypeRole)
|| sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::ShowSectionRole).toBool() // or the section needs to be visible != MessageEventModel::DelegateType::State // If it's not a state event
) { || sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::ShowSectionRole).toBool() // or the section needs to be visible
)) {
break; break;
} }
} }
@@ -148,10 +151,11 @@ QString CollapseStateProxyModel::excessAuthors(int row) const
if (!uniqueAuthors.contains(nextAvatar)) { if (!uniqueAuthors.contains(nextAvatar)) {
uniqueAuthors.append(nextAvatar); uniqueAuthors.append(nextAvatar);
} }
if (sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::DelegateTypeRole) if (i > 0
!= MessageEventModel::DelegateType::State // If it's not a state event && (sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::DelegateTypeRole)
|| sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::ShowSectionRole).toBool() // or the section needs to be visible != MessageEventModel::DelegateType::State // If it's not a state event
) { || sourceModel()->data(sourceModel()->index(i - 1, 0), MessageEventModel::ShowSectionRole).toBool() // or the section needs to be visible
)) {
break; break;
} }
} }