Changeset View
Changeset View
Standalone View
Standalone View
src/utils.cpp
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | |||||
74 | 74 | | |||
75 | void WordCount::fillFromContainer(KEduVocContainer &container, int translationIndex, | 75 | void WordCount::fillFromContainer(KEduVocContainer &container, int translationIndex, | ||
76 | KEduVocContainer::EnumEntriesRecursive recursive) | 76 | KEduVocContainer::EnumEntriesRecursive recursive) | ||
77 | { | 77 | { | ||
78 | clear(); | 78 | clear(); | ||
79 | 79 | | |||
80 | foreach (KEduVocExpression *entry, container.entries(recursive)) { | 80 | foreach (KEduVocExpression *entry, container.entries(recursive)) { | ||
81 | KEduVocTranslation &translation(*entry->translation(translationIndex)); | 81 | KEduVocTranslation &translation(*entry->translation(translationIndex)); | ||
82 | evaluateWord(translation, translation.text()); | ||||
83 | } | ||||
84 | } | ||||
85 | | ||||
86 | | ||||
87 | void WordCount::fillFromContainerForPracticeMode(KEduVocContainer &container, int translationIndex, | ||||
88 | const QStringList &activeConjugationTenses, | ||||
89 | KEduVocContainer::EnumEntriesRecursive recursive) | ||||
90 | { | ||||
91 | KEduVocWordFlags wordTypeToProcess(KEduVocWordFlag::NoInformation); | ||||
92 | switch (Prefs::practiceMode()) { | ||||
93 | case Prefs::EnumPracticeMode::GenderPractice: | ||||
94 | wordTypeToProcess = KEduVocWordFlag::Noun; | ||||
95 | break; | ||||
96 | case Prefs::EnumPracticeMode::ConjugationPractice: | ||||
97 | wordTypeToProcess = KEduVocWordFlag::Verb; | ||||
98 | break; | ||||
99 | case Prefs::EnumPracticeMode::ComparisonPractice: | ||||
100 | wordTypeToProcess = KEduVocWordFlag::Adjective | KEduVocWordFlag::Adverb; | ||||
101 | break; | ||||
102 | default: | ||||
103 | fillFromContainer(container, translationIndex, recursive); | ||||
104 | return; | ||||
105 | } | ||||
82 | 106 | | |||
107 | clear(); | ||||
108 | | ||||
109 | foreach (KEduVocExpression *entry, container.entries(recursive)) { | ||||
110 | KEduVocTranslation &translation(*entry->translation(translationIndex)); | ||||
111 | if (isValidForProcessing(translation, wordTypeToProcess)) { | ||||
112 | switch (wordTypeToProcess) { | ||||
113 | case KEduVocWordFlag::Noun: | ||||
114 | { | ||||
115 | KEduVocText article = translation.article(); | ||||
116 | evaluateWord(article, translation.text()); | ||||
117 | } | ||||
118 | break; | ||||
119 | case KEduVocWordFlag::Verb: | ||||
120 | { | ||||
121 | QStringList conjugationTenses = translation.conjugationTenses(); | ||||
122 | foreach(const QString &activeTense, activeConjugationTenses) | ||||
123 | { | ||||
124 | if (conjugationTenses.contains(activeTense)) { | ||||
125 | KEduVocConjugation conj = translation.getConjugation(activeTense); | ||||
126 | foreach (KEduVocWordFlags key, conj.keys()) { | ||||
127 | KEduVocText person = conj.conjugation(key); | ||||
128 | evaluateWord(person, person.text()); | ||||
129 | } | ||||
130 | } | ||||
131 | } | ||||
132 | } | ||||
133 | break; | ||||
134 | case KEduVocWordFlag::Adjective | KEduVocWordFlag::Adverb: | ||||
135 | { | ||||
136 | KEduVocText comparative = translation.comparativeForm(); | ||||
137 | evaluateWord(comparative, comparative.text()); | ||||
138 | KEduVocText superlative = translation.superlativeForm(); | ||||
139 | evaluateWord(superlative, superlative.text()); | ||||
140 | } | ||||
141 | break; | ||||
142 | } | ||||
143 | } | ||||
144 | } | ||||
145 | } | ||||
146 | | ||||
147 | bool WordCount::isValidForProcessing(KEduVocTranslation &trans, KEduVocWordFlags wordType) const | ||||
148 | { | ||||
149 | return !trans.isEmpty() | ||||
150 | && (trans.wordType() != nullptr) | ||||
151 | && ((trans.wordType()->wordType() & wordType) != 0); | ||||
152 | } | ||||
153 | | ||||
154 | void WordCount::evaluateWord(const KEduVocText &item, const QString &text) | ||||
155 | { | ||||
83 | ++totalWords; | 156 | ++totalWords; | ||
84 | if (translation.isEmpty()) { | 157 | if (text.isEmpty()) { | ||
85 | ++invalid; | 158 | ++invalid; | ||
86 | } else if (translation.preGrade() > 0) { | 159 | } else if (item.preGrade() > 0) { | ||
87 | // Initial phase (we assume correctness, i.e. if pregrade>0 then grade = 0) | 160 | // Initial phase (we assume correctness, i.e. if pregrade>0 then grade = 0) | ||
88 | ++initialWords; | 161 | ++initialWords; | ||
89 | ++pregrades[translation.preGrade()]; | 162 | ++pregrades[item.preGrade()]; | ||
90 | } else { | 163 | } else { | ||
91 | // Long term or unpracticed | 164 | // Long term or unpracticed | ||
92 | ++grades[translation.grade()]; | 165 | ++grades[item.grade()]; | ||
93 | } | | |||
94 | } | 166 | } | ||
95 | } | 167 | } | ||
96 | 168 | | |||
97 | 169 | | |||
98 | // ---------------------------------------------------------------- | 170 | // ---------------------------------------------------------------- | ||
99 | // class confidenceColors | 171 | // class confidenceColors | ||
100 | 172 | | |||
101 | 173 | | |||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | 255 | for (int i = KV_MAX_GRADE; i >= -2; --i) { | |||
214 | // so that the inner rectangle takes the shape of the outer rounded rectangle. | 286 | // so that the inner rectangle takes the shape of the outer rounded rectangle. | ||
215 | QPainterPath barElementIntersectedPath = roundedPath.intersected(barElementPath); | 287 | QPainterPath barElementIntersectedPath = roundedPath.intersected(barElementPath); | ||
216 | xPosition += barElementWidth; | 288 | xPosition += barElementWidth; | ||
217 | 289 | | |||
218 | // Paint! | 290 | // Paint! | ||
219 | painter.setBrush(QBrush(color)); | 291 | painter.setBrush(QBrush(color)); | ||
220 | painter.drawPath(barElementIntersectedPath); | 292 | painter.drawPath(barElementIntersectedPath); | ||
221 | } | 293 | } | ||
222 | } | 294 | } | ||
apol: Unrelated change |
Unrelated change