Warning, file /education/parley/src/practice/comparisonbackendmode.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: 2010 Frederik Gladhorn <gladhorn@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "comparisonbackendmode.h" 0007 0008 #include <KLocalizedString> 0009 0010 #include "documentsettings.h" 0011 0012 using namespace Practice; 0013 0014 ComparisonBackendMode::ComparisonBackendMode(AbstractFrontend *frontend, QObject *parent, Practice::SessionManagerBase *sessionManager, KEduVocDocument *doc) 0015 : AbstractBackendMode(frontend, parent) 0016 , m_sessionManager(sessionManager) 0017 , m_doc(doc) 0018 { 0019 } 0020 0021 bool ComparisonBackendMode::setTestEntry(TestEntry *current) 0022 { 0023 m_current = current; 0024 m_lastAnswers.clear(); 0025 0026 int languageTo = current->languageTo(); 0027 int languageFrom = current->languageFrom(); 0028 0029 m_frontend->setQuestion(m_current->entry()->translation(languageFrom)->text()); 0030 QStringList answers; 0031 answers.append(m_current->entry()->translation(languageTo)->text()); 0032 answers.append(m_current->entry()->translation(languageTo)->comparativeForm().text()); 0033 answers.append(m_current->entry()->translation(languageTo)->superlativeForm().text()); 0034 m_frontend->setSolution(answers); 0035 0036 m_frontend->setQuestionSound(m_current->entry()->translation(m_current->languageFrom())->soundUrl()); 0037 m_frontend->setSolutionSound(m_current->entry()->translation(m_current->languageTo())->soundUrl()); 0038 m_frontend->setQuestionPronunciation(m_current->entry()->translation(m_current->languageFrom())->pronunciation()); 0039 m_frontend->setSolutionPronunciation(m_current->entry()->translation(m_current->languageTo())->pronunciation()); 0040 m_frontend->setResultState(AbstractFrontend::QuestionState); 0041 m_frontend->showQuestion(); 0042 return true; 0043 } 0044 0045 void ComparisonBackendMode::checkAnswer() 0046 { 0047 QStringList answers = m_frontend->userInput().toStringList(); 0048 0049 if (answers == m_lastAnswers) { 0050 Q_EMIT answerWrongShowSolution(); 0051 return; 0052 } 0053 0054 bool absoluteCorrect = answers.at(0) == m_current->entry()->translation(m_current->languageTo())->text(); 0055 bool comparativeCorrect = answers.at(1) == m_current->entry()->translation(m_current->languageTo())->comparativeForm().text(); 0056 bool superlativeCorrect = answers.at(2) == m_current->entry()->translation(m_current->languageTo())->superlativeForm().text(); 0057 0058 if (absoluteCorrect && comparativeCorrect && superlativeCorrect) { 0059 m_frontend->setFeedback(i18n("All comparison forms were right.")); 0060 Q_EMIT answerRight(); 0061 } else { 0062 if (!absoluteCorrect) { 0063 m_frontend->setFeedback( 0064 i18nc("the user entered the wrong absolute form when practicing comparison forms of adjectives (the base form of the adjective is wrong)", 0065 "\"%1\" is the wrong word.", 0066 answers.at(0))); 0067 } else { 0068 if ((!comparativeCorrect) && (!superlativeCorrect)) { 0069 m_frontend->setFeedback(i18nc("the user entered the wrong comparison forms when practicing comparison forms of adjectives (good, better, best)", 0070 "Both comparison forms (comparative and superlative) are wrong.")); 0071 } else if (!comparativeCorrect) { 0072 m_frontend->setFeedback( 0073 i18nc("the user entered the wrong comparison forms when practicing comparison forms of adjectives (second form wrong - better)", 0074 "The comparative is wrong.")); 0075 } else if (!superlativeCorrect) { 0076 m_frontend->setFeedback( 0077 i18nc("the user entered the wrong comparison forms when practicing comparison forms of adjectives (third form wrong - best)", 0078 "The superlative is wrong.")); 0079 } 0080 } 0081 Q_EMIT answerWrongRetry(); 0082 } 0083 m_lastAnswers = answers; 0084 } 0085 0086 void ComparisonBackendMode::hintAction() 0087 { 0088 // FIXME 0089 } 0090 0091 void ComparisonBackendMode::updateGrades() 0092 { 0093 QStringList answers = m_frontend->userInput().toStringList(); 0094 0095 bool absoluteCorrect = answers.at(0) == m_current->entry()->translation(m_current->languageTo())->text(); 0096 bool comparativeCorrect = answers.at(1) == m_current->entry()->translation(m_current->languageTo())->comparativeForm().text(); 0097 bool superlativeCorrect = answers.at(2) == m_current->entry()->translation(m_current->languageTo())->superlativeForm().text(); 0098 0099 // TODO way too much duplicated code here 0100 0101 KEduVocTranslation *translation = m_current->entry()->translation(m_current->languageTo()); 0102 0103 translation->incPracticeCount(); 0104 translation->setPracticeDate(QDateTime::currentDateTime()); 0105 0106 updateGrade(*translation, absoluteCorrect, m_current->statisticBadCount() == 0); 0107 0108 KEduVocText comp = translation->comparativeForm(); 0109 0110 comp.incPracticeCount(); 0111 comp.setPracticeDate(QDateTime::currentDateTime()); 0112 0113 updateGrade(comp, comparativeCorrect, m_current->statisticBadCount() == 0); 0114 translation->setComparativeForm(comp); 0115 0116 KEduVocText super = translation->superlativeForm(); 0117 0118 super.incPracticeCount(); 0119 super.setPracticeDate(QDateTime::currentDateTime()); 0120 0121 updateGrade(super, superlativeCorrect, m_current->statisticBadCount() == 0); 0122 translation->setSuperlativeForm(super); 0123 } 0124 0125 grade_t ComparisonBackendMode::currentPreGradeForEntry() const 0126 { 0127 KEduVocTranslation *translation = m_current->entry()->translation(m_current->languageTo()); 0128 if (translation) { 0129 return qMin(translation->comparativeForm().preGrade(), translation->superlativeForm().preGrade()); 0130 } 0131 return KV_NORM_GRADE; 0132 } 0133 0134 grade_t ComparisonBackendMode::currentGradeForEntry() const 0135 { 0136 KEduVocTranslation *translation = m_current->entry()->translation(m_current->languageTo()); 0137 if (translation) { 0138 return qMin(translation->comparativeForm().grade(), translation->superlativeForm().grade()); 0139 } 0140 return KV_NORM_GRADE; 0141 }