File indexing completed on 2024-05-05 07:51:20
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "collection.h" 0007 0008 // KEduVocDocument library 0009 0010 // Parley 0011 #include "../utils.h" 0012 #include "entryfilter.h" 0013 0014 // ---------------------------------------------------------------- 0015 0016 Collection::Collection(QUrl *url, QObject *parent) 0017 : QObject(parent) 0018 , m_doc(new KEduVocDocument(this)) 0019 { 0020 // We ignore file locks here because we open the file for readonly 0021 // purposes only. 0022 m_doc->open(*url, KEduVocDocument::FileOpenReadOnly); 0023 } 0024 0025 Collection::~Collection() 0026 { 0027 qDeleteAll(m_allTestEntries); 0028 } 0029 0030 KEduVocDocument *Collection::eduVocDocument() 0031 { 0032 return m_doc; 0033 } 0034 0035 void Collection::numDueWords(WordCount &wc) 0036 { 0037 // Get the entries from the collection. Cache them for future use. 0038 if (m_allTestEntries.isEmpty()) { 0039 EntryFilter filter(m_doc, this); 0040 m_allTestEntries = filter.entries(false); 0041 } 0042 0043 // Count the number of words due for each grade level. 0044 for (const TestEntry *entry : qAsConst(m_allTestEntries)) { 0045 int languageTo = entry->languageTo(); 0046 KEduVocExpression *exp = entry->entry(); 0047 0048 int grade = exp->translation(languageTo)->grade(); 0049 int pregrade = exp->translation(languageTo)->preGrade(); 0050 if (exp->translation(languageTo)->text().isEmpty()) { 0051 wc.invalid++; 0052 } else if (pregrade > 0) { 0053 wc.pregrades[pregrade]++; 0054 wc.initialWords++; 0055 wc.grades[0]++; 0056 } else { 0057 wc.grades[grade]++; 0058 } 0059 } 0060 0061 wc.totalWords = m_allTestEntries.count(); 0062 // kDebug() << m_doc->title() << wc.totalWords << "entries"; 0063 } 0064 0065 #include "moc_collection.cpp"