Warning, file /education/parley/src/practice/sessionmanagerfixed.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2014 Inge Wallin <inge@lysator.liu.se> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "sessionmanagerfixed.h" 0007 0008 // kdelibs 0009 #include <KConfig> 0010 #include <KLocalizedString> 0011 #include <QDebug> 0012 0013 // kdeedulibs 0014 #include <KEduVocExpression> 0015 0016 // parley 0017 #include <prefs.h> 0018 0019 using namespace Practice; 0020 0021 SessionManagerFixed::SessionManagerFixed(QWidget *parent) 0022 : SessionManagerBase(parent) 0023 { 0024 } 0025 0026 SessionManagerFixed::~SessionManagerFixed() 0027 { 0028 } 0029 0030 void SessionManagerFixed::initializeTraining() 0031 { 0032 const int MaxEntries = Prefs::sessionMaxSize(); 0033 const int MaxNewWords = Prefs::sessionMaxNewWords(); 0034 0035 // We will never add anything to the session after it's initialized. 0036 m_notAskedTestEntries.clear(); 0037 0038 // Pick N new words if there are any into the active set. 0039 int numNewWords = 0; 0040 QList<TestEntry *>::Iterator it = m_allTestEntries.begin(); 0041 while (it != m_allTestEntries.end() && numNewWords < MaxNewWords && m_currentEntries.count() < MaxEntries) { 0042 if ((*it)->practiceModeDependentMinGrade() == 0 && (*it)->practiceModeDependentMinPreGrade() == 0) { 0043 m_currentEntries.append(*it); 0044 numNewWords++; 0045 it = m_allTestEntries.erase(it); 0046 } else { 0047 ++it; 0048 } 0049 } 0050 0051 // Pick the rest of the words from the already practiced ones. 0052 // Use higher graded entries before lower graded ones. 0053 for (int grade = KV_MAX_GRADE; grade > 0; --grade) { 0054 if (m_currentEntries.count() >= MaxEntries) { 0055 break; 0056 } 0057 0058 // Step through all entries and collect those at the current 0059 // grade until the session is filled. 0060 it = m_allTestEntries.begin(); 0061 while (it != m_allTestEntries.end() && m_currentEntries.count() < MaxEntries) { 0062 if ((*it)->practiceModeDependentMaxGrade() == grade) { 0063 m_currentEntries.append(*it); 0064 it = m_allTestEntries.erase(it); 0065 } else { 0066 ++it; 0067 } 0068 } 0069 } 0070 0071 // If there is still room in the session, pick the rest of the 0072 // words from the ones with pregrades. Also here, use higher 0073 // graded entries before lower graded ones. 0074 for (int preGrade = KV_MAX_GRADE; preGrade > 0; --preGrade) { 0075 if (m_currentEntries.count() >= MaxEntries) { 0076 break; 0077 } 0078 0079 // Step through all entries and collect those at the current 0080 // grade until the session is filled. 0081 it = m_allTestEntries.begin(); 0082 while (it != m_allTestEntries.end() && m_currentEntries.count() < MaxEntries) { 0083 if ((*it)->practiceModeDependentMaxPreGrade() == preGrade) { 0084 m_currentEntries.append(*it); 0085 it = m_allTestEntries.erase(it); 0086 } else { 0087 ++it; 0088 } 0089 } 0090 } 0091 0092 // The remaining entries have to be deleted to prevent memory leaking 0093 qDeleteAll(m_allTestEntries); 0094 0095 // Now we have decided exactly which ones to use. 0096 // We need to keep this for statistics reporting at the end. 0097 m_allTestEntries = m_currentEntries; 0098 }