• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
  • practice
comparisonbackendmode.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2010 Frederik Gladhorn <gladhorn@kde.org>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 
15 #include "comparisonbackendmode.h"
16 
17 #include <KLocalizedString>
18 
19 #include "documentsettings.h"
20 
21 using namespace Practice;
22 
23 ComparisonBackendMode::ComparisonBackendMode(AbstractFrontend* frontend, QObject* parent,
24  Practice::SessionManagerBase* sessionManager,
25  KEduVocDocument* doc)
26  : AbstractBackendMode(frontend, parent)
27  , m_sessionManager(sessionManager)
28  , m_doc(doc)
29 {
30 }
31 
32 bool ComparisonBackendMode::setTestEntry(TestEntry* current)
33 {
34  m_current = current;
35  m_lastAnswers.clear();
36 
37  int languageTo = current->languageTo();
38  int languageFrom = current->languageFrom();
39 
40  m_frontend->setQuestion(m_current->entry()->translation(languageFrom)->text());
41  QStringList answers;
42  answers.append(m_current->entry()->translation(languageTo)->text());
43  answers.append(m_current->entry()->translation(languageTo)->comparative());
44  answers.append(m_current->entry()->translation(languageTo)->superlative());
45  m_frontend->setSolution(answers);
46 
47  m_frontend->setQuestionSound(m_current->entry()->translation(m_current->languageFrom())->soundUrl());
48  m_frontend->setSolutionSound(m_current->entry()->translation(m_current->languageTo())->soundUrl());
49  m_frontend->setQuestionPronunciation(m_current->entry()->translation(m_current->languageFrom())->pronunciation());
50  m_frontend->setSolutionPronunciation(m_current->entry()->translation(m_current->languageTo())->pronunciation());
51  m_frontend->setResultState(AbstractFrontend::QuestionState);
52  m_frontend->showQuestion();
53  return true;
54 }
55 
56 void ComparisonBackendMode::checkAnswer()
57 {
58  QStringList answers = m_frontend->userInput().toStringList();
59 
60  if (answers == m_lastAnswers) {
61  emit answerWrongShowSolution();
62  return;
63  }
64 
65  bool absoluteCorrect = answers.at(0) == m_current->entry()->translation(m_current->languageTo())->text();
66  bool comparativeCorrect = answers.at(1) == m_current->entry()->translation(m_current->languageTo())->comparative();
67  bool superlativeCorrect = answers.at(2) == m_current->entry()->translation(m_current->languageTo())->superlative();
68 
69  if (absoluteCorrect && comparativeCorrect && superlativeCorrect) {
70  m_frontend->setFeedback(i18n("All comparison forms were right."));
71  emit answerRight();
72  } else {
73  if (!absoluteCorrect) {
74  m_frontend->setFeedback(i18nc("the user entered the wrong absolute form when practicing comparison forms of adjectives (the base form of the adjective is wrong)",
75  "\"%1\" is the wrong word.", answers.at(0)));
76  } else {
77  if ((!comparativeCorrect) && (!superlativeCorrect)) {
78  m_frontend->setFeedback(i18nc("the user entered the wrong comparison forms when practicing comparison forms of adjectives (good, better, best)",
79  "Both comparison forms (comparative and superlative) are wrong."));
80  } else if (!comparativeCorrect) {
81  m_frontend->setFeedback(i18nc("the user entered the wrong comparison forms when practicing comparison forms of adjectives (second form wrong - better)",
82  "The comparative is wrong."));
83  } else if (!superlativeCorrect) {
84  m_frontend->setFeedback(i18nc("the user entered the wrong comparison forms when practicing comparison forms of adjectives (third form wrong - best)",
85  "The superlative is wrong."));
86  }
87  }
88  emit answerWrongRetry();
89  }
90  m_lastAnswers = answers;
91 }
92 
93 void ComparisonBackendMode::hintAction()
94 {
95  // FIXME
96 }
97 
98 void ComparisonBackendMode::updateGrades()
99 {
100  QStringList answers = m_frontend->userInput().toStringList();
101 
102  bool absoluteCorrect = answers.at(0) == m_current->entry()->translation(m_current->languageTo())->text();
103  bool comparativeCorrect = answers.at(1) == m_current->entry()->translation(m_current->languageTo())->comparative();
104  bool superlativeCorrect = answers.at(2) == m_current->entry()->translation(m_current->languageTo())->superlative();
105 
106  // TODO way too much duplicated code here
107 
108  KEduVocTranslation* translation = m_current->entry()->translation(m_current->languageTo());
109 
110  translation->incPracticeCount();
111  translation->setPracticeDate(QDateTime::currentDateTime());
112 
113  updateGrade(*translation, absoluteCorrect, m_current->statisticBadCount() == 0);
114 
115  KEduVocText comp = translation->comparativeForm();
116 
117  comp.incPracticeCount();
118  comp.setPracticeDate(QDateTime::currentDateTime());
119 
120  updateGrade(comp, comparativeCorrect, m_current->statisticBadCount() == 0);
121  translation->setComparativeForm(comp);
122 
123  KEduVocText super = translation->superlativeForm();
124 
125  super.incPracticeCount();
126  super.setPracticeDate(QDateTime::currentDateTime());
127 
128  updateGrade(super, superlativeCorrect, m_current->statisticBadCount() == 0);
129  translation->setSuperlativeForm(super);
130 }
131 
132 
133 
134 #include "comparisonbackendmode.moc"
QList::clear
void clear()
Practice::AbstractFrontend::setResultState
virtual void setResultState(ResultState resultState)=0
The result state indicated whether a word is counted as correct (and grades are raised) and can be ch...
TestEntry::entry
KEduVocExpression * entry() const
Definition: testentry.cpp:149
Practice::AbstractFrontend::setQuestion
virtual void setQuestion(const QVariant &question)=0
Practice::AbstractFrontend::showQuestion
virtual void showQuestion()=0
enter question mode - the user is asked to provide the solution
Practice::ComparisonBackendMode::hintAction
virtual void hintAction()
Definition: comparisonbackendmode.cpp:93
Practice::AbstractBackendMode::answerRight
void answerRight()
QList::at
const T & at(int i) const
Practice::AbstractBackendMode::updateGrade
void updateGrade(KEduVocText &text, bool isCorrectAnswer, bool hasNoPreviousBadAnswers)
Update the grade for the current entry.
Definition: abstractbackendmode.cpp:84
documentsettings.h
Practice::ComparisonBackendMode::ComparisonBackendMode
ComparisonBackendMode(AbstractFrontend *frontend, QObject *parent, Practice::SessionManagerBase *sessionManager, KEduVocDocument *doc)
Definition: comparisonbackendmode.cpp:23
Practice::AbstractFrontend::QuestionState
Definition: abstractfrontend.h:42
Practice::AbstractFrontend::setSolution
virtual void setSolution(const QVariant &solution)=0
Practice::AbstractBackendMode::m_frontend
AbstractFrontend * m_frontend
Definition: abstractbackendmode.h:121
QList::append
void append(const T &value)
Practice::AbstractBackendMode::m_current
TestEntry * m_current
Definition: abstractbackendmode.h:122
Practice::AbstractFrontend::userInput
virtual QVariant userInput()=0
Enables access to the input of the user.
QObject
Practice::AbstractFrontend::setQuestionPronunciation
virtual void setQuestionPronunciation(const QString &pronunciationText)=0
Practice::AbstractFrontend::setFeedback
virtual void setFeedback(const QVariant &feedback)=0
QStringList
TestEntry::statisticBadCount
int statisticBadCount()
Definition: testentry.cpp:54
QDateTime::currentDateTime
QDateTime currentDateTime()
QVariant::toStringList
QStringList toStringList() const
Practice::AbstractBackendMode::answerWrongShowSolution
void answerWrongShowSolution()
Practice::AbstractFrontend::setSolutionSound
virtual void setSolutionSound(const KUrl &soundUrl)=0
TestEntry::languageFrom
int languageFrom() const
Definition: testentry.cpp:109
Practice::AbstractBackendMode
Definition: abstractbackendmode.h:26
Practice::AbstractFrontend
Definition: abstractfrontend.h:26
Practice::AbstractBackendMode::answerWrongRetry
void answerWrongRetry()
TestEntry::languageTo
int languageTo() const
Definition: testentry.cpp:114
Practice::AbstractFrontend::setQuestionSound
virtual void setQuestionSound(const KUrl &soundUrl)=0
Practice::SessionManagerBase
Definition: sessionmanagerbase.h:40
comparisonbackendmode.h
Practice::ComparisonBackendMode::checkAnswer
void checkAnswer()
Check if the current answer is right.
Definition: comparisonbackendmode.cpp:56
Practice::ComparisonBackendMode::updateGrades
virtual void updateGrades()
Change the grades for the current entry.
Definition: comparisonbackendmode.cpp:98
Practice::AbstractFrontend::setSolutionPronunciation
virtual void setSolutionPronunciation(const QString &pronunciationText)=0
Practice::ComparisonBackendMode::setTestEntry
virtual bool setTestEntry(TestEntry *current)
start practicing a new word.
Definition: comparisonbackendmode.cpp:32
TestEntry
Definition: testentry.h:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal