• 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
writtenbackendmode.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2009 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 "writtenbackendmode.h"
16 
17 #include <KLocalizedString>
18 
19 using namespace Practice;
20 
21 WrittenBackendMode::WrittenBackendMode(const Practice::PracticeOptions& practiceOptions, AbstractFrontend* frontend, QObject* parent, TestEntryManager* testEntryManager, KEduVocDocument* doc)
22 :AbstractBackendMode(practiceOptions, frontend, parent)
23 ,m_testEntryManager(testEntryManager)
24 ,m_doc(doc)
25 {
26  m_validator = new WrittenPracticeValidator(m_practiceOptions.languageTo(),doc);
27 }
28 
29 bool WrittenBackendMode::setTestEntry(TestEntry* current)
30 {
31  AbstractBackendMode::setTestEntry(current);
32  m_firstAttempt = true;
33  m_frontend->showQuestion();
34  m_lastAnswer.clear();
35  m_synonyms.clear();
36  m_currentHint.clear();
37  m_validator->setEntry(current);
38  return true;
39 }
40 
41 void WrittenBackendMode::checkAnswer()
42 {
43  kDebug() << "check";
44  QString answer = m_frontend->userInput().toString();
45 
46  // move on, the user has not changed anything or pressed enter with no answer
47  bool answerUnchanged = (answer == m_lastAnswer) || answer.isEmpty();
48  m_lastAnswer = answer;
49 
50  m_validator->validateAnswer(answer);
51 
52  bool isCorrect = m_current->lastErrors() & TestEntry::Correct;
53  bool isSynonym = m_current->lastErrors() & TestEntry::Synonym;
54 
55  QString feedbackString = getFeedbackString(m_current->lastErrors());
56  m_frontend->setFeedback(feedbackString);
57 
58  m_firstAttempt = m_firstAttempt && isSynonym; // don't count the answer as wrong if you only enter valid synonyms
59 
60  // first handle synonyms as they may be correct or not
61  if (isSynonym) {
62  addSynonym(answer);
63  m_frontend->setSynonym(answer);
64  m_frontend->showSynonym();
65 
66  if (Prefs::countSynonymsAsCorrect()) {
67  // any of the synonyms is automatically counted as right
68  // otherwise do nothing to give the user another chance
69  emit answerRight();
70  }
71  return;
72  }
73 
74  if (isCorrect) {
75  emit answerRight();
76  } else {
77  if(answerUnchanged) {
78  m_frontend->setFeedback(i18n("Your answer was wrong."));
79  emit answerWrongShowSolution();
80  } else {
81  m_current->addUserAnswer(answer);
82  emit answerWrongRetry();
83  }
84  }
85 }
86 
87 QString WrittenBackendMode::getFeedbackString(TestEntry::ErrorTypes error)
88 {
89  // The user entered a synonym
90  if (error & TestEntry::Synonym) {
91  if (!Prefs::countSynonymsAsCorrect()) {
92  return i18n("Your answer was a synonym. Please enter another word with the same translation.");
93  }
94  const QString answer = m_validator->getCorrectedAnswer();
95  if (m_synonyms.contains(answer)) {
96  return i18n("Your answer was an already entered synonym.");
97  } else {
98  if (error & TestEntry::CapitalizationMistake){
99  return i18n("Your answer was a synonym and your capitalization was wrong.");
100  } else if (error & TestEntry::AccentMistake){
101  return i18n("Your answer was a synonym and accents were wrong.");
102  } else {
103  return i18n("Your answer was a synonym.");
104  }
105  }
106  }
107 
108  // The answer was wrong
109  if (error & TestEntry::Wrong) {
110  if ((error & TestEntry::CapitalizationMistake) && !Prefs::ignoreCapitalizationMistakes()) {
111  return i18n("Your answer was wrong as capitalization mistakes are not accepted. Please try again.");
112  } else if ((error & TestEntry::AccentMistake) && !Prefs::ignoreAccentMistakes()){
113  return i18n("Your answer was wrong as accent mistakes are not accepted. Please try again.");
114  } else {
115  return i18n("Your answer was wrong. Please try again.");
116  }
117  }
118 
119  // The answer was right
120  if (m_firstAttempt) {
121  if ((error & TestEntry::CapitalizationMistake)){
122  return i18n("Your answer was right, but your capitalization was wrong.");
123  } else if ((error & TestEntry::AccentMistake)){
124  return i18n("Your answer was right, but accents were wrong.");
125  } else {
126  return i18n("Your answer was right.");
127  }
128  } else {
129  if ((error & TestEntry::CapitalizationMistake)){
130  return i18n("Your answer was right... but not on the first try and your capitalization was wrong.");
131  } else if ((error & TestEntry::AccentMistake)){
132  return i18n("Your answer was right... but not on the first try and accents were wrong.");
133  } else {
134  return i18n("Your answer was right... but not on the first try.");
135  }
136  }
137 }
138 
139 void WrittenBackendMode::hintAction()
140 {
141  QString solution = m_current->entry()->translation(m_practiceOptions.languageTo())->text();
142  m_currentHint = solution.left(m_currentHint.size() + 1);
143  if (m_currentHint.size() == solution.size()) {
144  // show solution
145  m_frontend->setFeedback(i18n("You revealed the answer by using too many hints."));
146  m_frontend->setResultState(AbstractFrontend::AnswerWrong);
147  if (m_frontend->userInput().toString() == m_current->entry()->translation(m_practiceOptions.languageTo())->text()) {
148  m_frontend->setFeedbackState(AbstractFrontend::AnswerCorrect);
149  } else {
150  m_frontend->setFeedbackState(AbstractFrontend::AnswerWrong);
151  }
152  m_frontend->showSolution();
153  } else {
154  m_frontend->setHint(i18n("The solution starts with: %1", m_currentHint));
155  }
156 
157  m_lastAnswer = m_frontend->userInput().toString();
158 }
159 
160 #include "writtenbackendmode.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::setHint
virtual void setHint(const QVariant &hint)=0
Practice::AbstractFrontend::showQuestion
virtual void showQuestion()=0
enter question mode - the user is asked to provide the solution
Practice::AbstractBackendMode::addSynonym
void addSynonym(const QString &entry)
add a new synonym to the list of shown/answered synonyms depending on which mode we are in...
Definition: abstractbackendmode.h:41
Practice::AbstractBackendMode::answerRight
void answerRight()
TestEntry::Wrong
< no error, solution was right
Definition: testentry.h:37
TestEntry::Synonym
< a false friend
Definition: testentry.h:32
TestEntry::lastErrors
ErrorTypes lastErrors()
Definition: testentry.cpp:119
Practice::TestEntryManager
Definition: testentrymanager.h:31
QObject
Practice::AbstractFrontend::showSynonym
virtual void showSynonym()=0
show the synonyms
Practice::WrittenBackendMode::setTestEntry
virtual bool setTestEntry(TestEntry *current)
start practicing a new word.
Definition: writtenbackendmode.cpp:29
Practice::WrittenBackendMode::checkAnswer
void checkAnswer()
Check if the current answer is right.
Definition: writtenbackendmode.cpp:41
Practice::AbstractBackendMode::m_frontend
AbstractFrontend * m_frontend
Definition: abstractbackendmode.h:83
TestEntry::AccentMistake
< capitalization error (whAt)
Definition: testentry.h:28
Practice::AbstractBackendMode::m_current
TestEntry * m_current
Definition: abstractbackendmode.h:84
TestEntry::Correct
< the part that was entered is right, but not complete
Definition: testentry.h:36
Practice::AbstractFrontend::AnswerWrong
Definition: abstractfrontend.h:43
Practice::AbstractFrontend::userInput
virtual QVariant userInput()=0
Enables access to the input of the user.
Practice::AbstractBackendMode::m_synonyms
QStringList m_synonyms
Definition: abstractbackendmode.h:85
Practice::WrittenBackendMode::WrittenBackendMode
WrittenBackendMode(const Practice::PracticeOptions &practiceOptions, Practice::AbstractFrontend *frontend, QObject *parent, Practice::TestEntryManager *testEntryManager, KEduVocDocument *doc)
Definition: writtenbackendmode.cpp:21
Practice::AbstractFrontend::setFeedback
virtual void setFeedback(const QVariant &feedback)=0
Practice::PracticeOptions::languageTo
int languageTo() const
Definition: practiceoptions.h:28
Practice::AbstractFrontend::setSynonym
virtual void setSynonym(const QString &entry)=0
set a new synonym that should be shown
Practice::AbstractBackendMode::setTestEntry
virtual bool setTestEntry(TestEntry *current)
start practicing a new word.
Definition: abstractbackendmode.cpp:27
Practice::WrittenBackendMode::hintAction
virtual void hintAction()
Definition: writtenbackendmode.cpp:139
Practice::AbstractFrontend::AnswerCorrect
Definition: abstractfrontend.h:41
writtenbackendmode.h
Prefs::countSynonymsAsCorrect
static bool countSynonymsAsCorrect()
Get When the synonym instead of the word was entered, does it count as correct?
Definition: prefs.h:673
Practice::AbstractBackendMode::answerWrongShowSolution
void answerWrongShowSolution()
Practice::WrittenPracticeValidator
Definition: writtenpracticevalidator.h:28
Prefs::ignoreAccentMistakes
static bool ignoreAccentMistakes()
Get Count answers as right when only the accentuation is wrong.
Definition: prefs.h:502
Practice::AbstractFrontend::showSolution
virtual void showSolution()=0
enter show solution mode - the solution is shown
Practice::AbstractBackendMode
Definition: abstractbackendmode.h:26
Practice::WrittenPracticeValidator::validateAnswer
void validateAnswer(const QString &answer)
Definition: writtenpracticevalidator.cpp:92
Practice::AbstractFrontend::setFeedbackState
virtual void setFeedbackState(ResultState feedbackState)=0
The feedback state tells the user if the currently entered word is correct (independent of whether th...
Practice::AbstractFrontend
Definition: abstractfrontend.h:25
TestEntry::addUserAnswer
void addUserAnswer(const QString &answer)
Definition: testentry.h:81
Practice::AbstractBackendMode::m_practiceOptions
PracticeOptions m_practiceOptions
Definition: abstractbackendmode.h:82
TestEntry::CapitalizationMistake
< misspelled
Definition: testentry.h:27
Practice::AbstractBackendMode::answerWrongRetry
void answerWrongRetry()
Practice::WrittenPracticeValidator::getCorrectedAnswer
QString getCorrectedAnswer()
Definition: writtenpracticevalidator.cpp:130
Prefs::ignoreCapitalizationMistakes
static bool ignoreCapitalizationMistakes()
Get Count answers as right when only the capitalization is wrong.
Definition: prefs.h:521
TestEntry::entry
KEduVocExpression * entry()
Definition: testentry.cpp:134
Practice::WrittenPracticeValidator::setEntry
void setEntry(TestEntry *entry)
Definition: writtenpracticevalidator.cpp:54
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:06 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