Changeset View
Changeset View
Standalone View
Standalone View
src/collection/testentry.cpp
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Line(s) | |||||
158 | { | 158 | { | ||
159 | return m_conjugationPronouns; | 159 | return m_conjugationPronouns; | ||
160 | } | 160 | } | ||
161 | 161 | | |||
162 | void TestEntry::setConjugationPronouns(const QList<KEduVocWordFlags>& flags) | 162 | void TestEntry::setConjugationPronouns(const QList<KEduVocWordFlags>& flags) | ||
163 | { | 163 | { | ||
164 | m_conjugationPronouns = flags; | 164 | m_conjugationPronouns = flags; | ||
165 | } | 165 | } | ||
166 | | ||||
167 | grade_t TestEntry::practiceModeDependentMinGrade() const | ||||
168 | { | ||||
169 | return practiceModeDependentGrade(&KEduVocTranslation::grade, qMin<grade_t>); | ||||
170 | } | ||||
171 | | ||||
172 | | ||||
173 | grade_t TestEntry::practiceModeDependentMinPreGrade() const | ||||
174 | { | ||||
175 | return practiceModeDependentGrade(&KEduVocText::preGrade, qMin<grade_t>); | ||||
176 | } | ||||
177 | | ||||
178 | | ||||
179 | grade_t TestEntry::practiceModeDependentMaxGrade() const | ||||
180 | { | ||||
181 | return practiceModeDependentGrade(&KEduVocText::grade, qMax<grade_t>); | ||||
182 | } | ||||
183 | | ||||
184 | | ||||
185 | grade_t TestEntry::practiceModeDependentMaxPreGrade() const | ||||
186 | { | ||||
187 | return practiceModeDependentGrade(&KEduVocText::preGrade, qMax<grade_t>); | ||||
188 | } | ||||
189 | | ||||
190 | | ||||
191 | grade_t TestEntry::practiceModeDependentGrade(std::function<grade_t(KEduVocText)> gradeFunc, | ||||
192 | std::function<grade_t(grade_t, grade_t)> minMaxFunc) const | ||||
193 | { | ||||
194 | grade_t result(0); | ||||
195 | const KEduVocTranslation *translation(entry()->translation(languageTo())); | ||||
196 | switch (Prefs::practiceMode()) { | ||||
197 | | ||||
198 | // For gender practice the article (pre-)grades are required. | ||||
199 | case Prefs::EnumPracticeMode::GenderPractice: | ||||
200 | result = gradeFunc(translation->article()); | ||||
201 | break; | ||||
202 | | ||||
203 | // For conjugation practice the conjugation (pre-)grades are required. | ||||
204 | // For the specified tense the highest/lowest values of all specified gramatical persons | ||||
205 | // is evaluated. | ||||
206 | case Prefs::EnumPracticeMode::ConjugationPractice: | ||||
207 | { | ||||
208 | KEduVocConjugation conj(translation->getConjugation(conjugationTense())); | ||||
209 | // Depending on what minMaxFunc is used result needs an appropriate initialisation | ||||
210 | result = (minMaxFunc(0, 1) == 1) ? KV_MIN_GRADE:KV_MAX_GRADE; | ||||
211 | foreach(KEduVocWordFlags pronoun, conjugationPronouns()) { | ||||
212 | result = minMaxFunc(result, gradeFunc(conj.conjugation(pronoun))); | ||||
213 | } | ||||
214 | } | ||||
215 | break; | ||||
216 | | ||||
217 | // For comparison practice the (pre-)grades of the positive, comparative and superlative | ||||
218 | // are required. Then highest/lowest value is evaluated. | ||||
219 | case Prefs::EnumPracticeMode::ComparisonPractice: | ||||
220 | { | ||||
221 | result = gradeFunc(translation->comparativeForm()); | ||||
222 | result = minMaxFunc(result, gradeFunc(translation->superlativeForm())); | ||||
223 | } | ||||
224 | break; | ||||
225 | | ||||
226 | // For all other practice forms the basic (pre-)grades are required. | ||||
227 | default: | ||||
228 | result = gradeFunc(*translation); | ||||
229 | break; | ||||
230 | } | ||||
231 | return result; | ||||
232 | } |