Commit de1b5afc authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Fix document update race conditions in model updates

The StatisticsModel requires both an updated KVocDocument and an updated
set of selected languages before being able to answer model request
correctly. This change ensures that for invalid combinations no
out-of-bounds access is performed.

BUG: 413720
parent cbbeefef
Pipeline #257789 passed with stage
in 1 minute and 6 seconds
......@@ -92,6 +92,9 @@ QVariant StatisticsModel::data(const QModelIndex &index, int role) const
int StatisticsModel::averageGradeForPracticeMode(KEduVocContainer *container, int translation) const
{
if (m_documentSettings.size() <= translation) {
return 0;
}
WordCount wordCount;
wordCount.fillFromContainerForPracticeMode(*container, translation, m_documentSettings.at(translation)->conjugationTenses());
return wordCount.percentageCompleted();
......@@ -99,6 +102,9 @@ int StatisticsModel::averageGradeForPracticeMode(KEduVocContainer *container, in
int StatisticsModel::entryCountForPracticeMode(KEduVocContainer *container, int translation) const
{
if (m_documentSettings.size() <= translation) {
return 0;
}
WordCount wordCount;
wordCount.fillFromContainerForPracticeMode(*container, translation, m_documentSettings.at(translation)->conjugationTenses());
return wordCount.totalWords - wordCount.invalid;
......@@ -106,6 +112,9 @@ int StatisticsModel::entryCountForPracticeMode(KEduVocContainer *container, int
int StatisticsModel::expressionsOfGradeForPracticeMode(KEduVocContainer *container, int translation, grade_t grade) const
{
if (m_documentSettings.size() <= translation) {
return 0;
}
WordCount wordCount;
wordCount.fillFromContainerForPracticeMode(*container, translation, m_documentSettings.at(translation)->conjugationTenses());
return wordCount.grades[grade];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment