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

parley

  • sources
  • kde-4.12
  • 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(const PracticeOptions& practiceOptions,
24  AbstractFrontend* frontend, QObject* parent, Practice::TestEntryManager* testEntryManager, KEduVocDocument* doc)
25 : AbstractBackendMode(practiceOptions, frontend, parent)
26 ,m_testEntryManager(testEntryManager)
27 ,m_doc(doc)
28 {
29 }
30 
31 bool ComparisonBackendMode::setTestEntry(TestEntry* current)
32 {
33  m_current = current;
34  m_lastAnswers.clear();
35 
36  int languageTo = m_practiceOptions.languageTo();
37  int languageFrom = m_practiceOptions.languageFrom();
38 
39  m_frontend->setQuestion(m_current->entry()->translation(languageFrom)->text());
40  QStringList answers;
41  answers.append(m_current->entry()->translation(languageTo)->text());
42  answers.append(m_current->entry()->translation(languageTo)->comparative());
43  answers.append(m_current->entry()->translation(languageTo)->superlative());
44  m_frontend->setSolution(answers);
45 
46  m_frontend->setQuestionSound(m_current->entry()->translation(m_practiceOptions.languageFrom())->soundUrl());
47  m_frontend->setSolutionSound(m_current->entry()->translation(m_practiceOptions.languageTo())->soundUrl());
48  m_frontend->setQuestionPronunciation(m_current->entry()->translation(m_practiceOptions.languageFrom())->pronunciation());
49  m_frontend->setSolutionPronunciation(m_current->entry()->translation(m_practiceOptions.languageTo())->pronunciation());
50  m_frontend->setResultState(AbstractFrontend::QuestionState);
51  m_frontend->showQuestion();
52  return true;
53 }
54 
55 void ComparisonBackendMode::checkAnswer()
56 {
57  QStringList answers = m_frontend->userInput().toStringList();
58 
59  if (answers == m_lastAnswers) {
60  emit answerWrongShowSolution();
61  return;
62  }
63 
64  bool absoluteCorrect = answers.at(0) == m_current->entry()->translation(Prefs::solutionLanguage())->text();
65  bool comparativeCorrect = answers.at(1) == m_current->entry()->translation(Prefs::solutionLanguage())->comparative();
66  bool superlativeCorrect = answers.at(2) == m_current->entry()->translation(Prefs::solutionLanguage())->superlative();
67 
68  if (absoluteCorrect && comparativeCorrect && superlativeCorrect) {
69  m_frontend->setFeedback(i18n("All comparison forms were right."));
70  emit answerRight();
71  } else {
72  if (!absoluteCorrect) {
73  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)",
74  "\"%1\" is the wrong word.", answers.at(0)));
75  } else {
76  if ((!comparativeCorrect) && (!superlativeCorrect)) {
77  m_frontend->setFeedback(i18nc("the user entered the wrong comparison forms when practicing comparison forms of adjectives (good, better, best)",
78  "Both comparison forms (comparative and superlative) are wrong."));
79  } else if (!comparativeCorrect) {
80  m_frontend->setFeedback(i18nc("the user entered the wrong comparison forms when practicing comparison forms of adjectives (second form wrong - better)",
81  "The comparative is wrong."));
82  } else if (!superlativeCorrect) {
83  m_frontend->setFeedback(i18nc("the user entered the wrong comparison forms when practicing comparison forms of adjectives (third form wrong - best)",
84  "The superlative is wrong."));
85  }
86  }
87  emit answerWrongRetry();
88  }
89  m_lastAnswers = answers;
90 }
91 
92 void ComparisonBackendMode::hintAction()
93 {
94  // FIXME
95 }
96 
97 void ComparisonBackendMode::updateGrades()
98 {
99  QStringList answers = m_frontend->userInput().toStringList();
100 
101  bool absoluteCorrect = answers.at(0) == m_current->entry()->translation(Prefs::solutionLanguage())->text();
102  bool comparativeCorrect = answers.at(1) == m_current->entry()->translation(Prefs::solutionLanguage())->comparative();
103  bool superlativeCorrect = answers.at(2) == m_current->entry()->translation(Prefs::solutionLanguage())->superlative();
104 
105  // TODO way too much duplicated code here
106 
107  KEduVocTranslation* translation = m_current->entry()->translation(m_practiceOptions.languageTo());
108 
109  translation->incPracticeCount();
110  translation->setPracticeDate( QDateTime::currentDateTime() );
111 
112  if (absoluteCorrect) {
113  if (m_current->statisticBadCount() == 0) {
114  translation->incGrade();
115  }
116  } else {
117  translation->setGrade(KV_LEV1_GRADE);
118  translation->incBadCount();
119  }
120 
121  KEduVocText comp = translation->comparativeForm();
122 
123  comp.incPracticeCount();
124  comp.setPracticeDate( QDateTime::currentDateTime() );
125 
126  if (comparativeCorrect) {
127  if (m_current->statisticBadCount() == 0) {
128  comp.incGrade();
129  }
130  } else {
131  comp.setGrade(KV_LEV1_GRADE);
132  comp.incBadCount();
133  }
134  translation->setComparativeForm(comp);
135 
136  KEduVocText super = translation->superlativeForm();
137 
138  super.incPracticeCount();
139  super.setPracticeDate( QDateTime::currentDateTime() );
140 
141  if (superlativeCorrect) {
142  if (m_current->statisticBadCount() == 0) {
143  super.incGrade();
144  }
145  } else {
146  super.setGrade(KV_LEV1_GRADE);
147  super.incBadCount();
148  }
149  translation->setSuperlativeForm(super);
150 }
151 
152 
153 
154 #include "comparisonbackendmode.moc"
Practice::PracticeOptions
Definition: practiceoptions.h:22
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...
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:92
Practice::AbstractBackendMode::answerRight
void answerRight()
Practice::PracticeOptions::languageFrom
int languageFrom() const
Definition: practiceoptions.h:27
documentsettings.h
Practice::AbstractFrontend::QuestionState
Definition: abstractfrontend.h:40
Practice::TestEntryManager
Definition: testentrymanager.h:31
Practice::AbstractFrontend::setSolution
virtual void setSolution(const QVariant &solution)=0
QObject
Practice::AbstractBackendMode::m_frontend
AbstractFrontend * m_frontend
Definition: abstractbackendmode.h:83
Practice::AbstractBackendMode::m_current
TestEntry * m_current
Definition: abstractbackendmode.h:84
Practice::AbstractFrontend::userInput
virtual QVariant userInput()=0
Enables access to the input of the user.
Practice::AbstractFrontend::setQuestionPronunciation
virtual void setQuestionPronunciation(const QString &pronunciationText)=0
Practice::AbstractFrontend::setFeedback
virtual void setFeedback(const QVariant &feedback)=0
Practice::PracticeOptions::languageTo
int languageTo() const
Definition: practiceoptions.h:28
TestEntry::statisticBadCount
int statisticBadCount()
Definition: testentry.cpp:54
Practice::AbstractBackendMode::answerWrongShowSolution
void answerWrongShowSolution()
Practice::AbstractFrontend::setSolutionSound
virtual void setSolutionSound(const KUrl &soundUrl)=0
Practice::ComparisonBackendMode::ComparisonBackendMode
ComparisonBackendMode(const PracticeOptions &PracticeOptions, AbstractFrontend *frontend, QObject *parent, Practice::TestEntryManager *testEntryManager, KEduVocDocument *doc)
Definition: comparisonbackendmode.cpp:23
Practice::AbstractBackendMode
Definition: abstractbackendmode.h:26
Practice::AbstractFrontend
Definition: abstractfrontend.h:25
Practice::AbstractBackendMode::m_practiceOptions
PracticeOptions m_practiceOptions
Definition: abstractbackendmode.h:82
Practice::AbstractBackendMode::answerWrongRetry
void answerWrongRetry()
Practice::AbstractFrontend::setQuestionSound
virtual void setQuestionSound(const KUrl &soundUrl)=0
comparisonbackendmode.h
Practice::ComparisonBackendMode::checkAnswer
void checkAnswer()
Check if the current answer is right.
Definition: comparisonbackendmode.cpp:55
Practice::ComparisonBackendMode::updateGrades
virtual void updateGrades()
Change the grades for the current entry.
Definition: comparisonbackendmode.cpp:97
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:31
Prefs::solutionLanguage
static int solutionLanguage()
Get The language in which the user has to answer.
Definition: prefs.h:1186
TestEntry::entry
KEduVocExpression * entry()
Definition: testentry.cpp:134
TestEntry
Definition: testentry.h:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:05 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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