• 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
conjugationbackendmode.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 "conjugationbackendmode.h"
16 
17 #include <KLocalizedString>
18 
19 #include <keduvocdocument.h>
20 
21 #include "conjugationdata.h"
22 #include "documentsettings.h"
23 
24 using namespace Practice;
25 
26 ConjugationBackendMode::ConjugationBackendMode(const PracticeOptions& practiceOptions,
27  AbstractFrontend* frontend, QObject* parent, Practice::TestEntryManager* testEntryManager, KEduVocDocument* doc)
28 : AbstractBackendMode(practiceOptions, frontend, parent)
29 ,m_testEntryManager(testEntryManager)
30 ,m_doc(doc)
31 {
32 }
33 
34 bool ConjugationBackendMode::setTestEntry(TestEntry* current)
35 {
36  ConjugationData data;
37  m_current = current;
38  m_lastAnswers.clear();
39 
40  m_currentTense = m_current->conjugationTense();
41 
42  if (!m_current->entry()->translation(m_practiceOptions.languageTo())->conjugationTenses().contains(m_currentTense)) {
43  kDebug() << "invalid tense for entry - " << m_currentTense;
44  kDebug() << "tenses: " << m_current->entry()->translation(m_practiceOptions.languageTo())->conjugationTenses();
45  }
46 
47  data.tense = m_currentTense;
48  m_conjugation = m_current->entry()->translation(m_practiceOptions.languageTo())->conjugation(m_currentTense);
49  m_pronounFlags = current->conjugationPronouns();
50 
51  data.questionInfinitive = m_current->entry()->translation(m_practiceOptions.languageFrom())->text();
52  data.solutionInfinitive = m_current->entry()->translation(m_practiceOptions.languageTo())->text();
53 
54  data.personalPronouns = validPersonalPronouns();
55 
56  m_frontend->setQuestion(qVariantFromValue<ConjugationData>(data));
57  QStringList answers;
58  foreach (const KEduVocWordFlags& key, m_pronounFlags) {
59  answers.append(m_conjugation.conjugation(key).text());
60  }
61  m_frontend->setSolution(answers);
62 
63  m_frontend->setQuestionSound(m_current->entry()->translation(m_practiceOptions.languageFrom())->soundUrl());
64  m_frontend->setSolutionSound(m_current->entry()->translation(m_practiceOptions.languageTo())->soundUrl());
65  m_frontend->setQuestionPronunciation(m_current->entry()->translation(m_practiceOptions.languageFrom())->pronunciation());
66  m_frontend->setSolutionPronunciation(m_current->entry()->translation(m_practiceOptions.languageTo())->pronunciation());
67  m_frontend->setResultState(AbstractFrontend::QuestionState);
68  m_frontend->showQuestion();
69  return true;
70 }
71 
72 QStringList ConjugationBackendMode::validPersonalPronouns()
73 {
74  QStringList pp;
75  foreach (const KEduVocWordFlags& person, m_pronounFlags) {
76  pp.append(m_doc->identifier(m_practiceOptions.languageTo()).personalPronouns().personalPronoun(person));
77  }
78  kDebug() << "PP: " << pp.size() << pp;
79  return pp;
80 }
81 
82 void ConjugationBackendMode::checkAnswer()
83 {
84  QStringList answers = m_frontend->userInput().toStringList();
85 
86  bool allCorrect = true;
87  int numRight = 0;
88  int i=0;
89  foreach(const KEduVocWordFlags& key, m_pronounFlags) {
90  if (answers.at(i) == m_conjugation.conjugation(key).text()) {
91  ++numRight;
92  } else {
93  kDebug() << "dec grade for " << m_conjugation.conjugation(key).text();
94  allCorrect = false;
95  }
96  ++i;
97  }
98 
99  kDebug() << "answers: " << answers;
100 
101  if (allCorrect) {
102  m_frontend->setFeedback(i18n("All conjugation forms were right."));
103  emit answerRight();
104  } else {
105  m_frontend->setFeedback(i18ncp("You did not get the conjugation forms right.", "You answered %1 conjugation form correctly.", "You answered %1 conjugation forms correctly.", numRight));
106 
107  if (answers == m_lastAnswers) {
108  emit answerWrongShowSolution();
109  } else {
110  emit answerWrongRetry();
111  }
112  m_lastAnswers = answers;
113  }
114 }
115 
116 grade_t ConjugationBackendMode::currentGradeForEntry()
117 {
118  Q_ASSERT(m_current != 0);
119  KEduVocTranslation* trans = m_current->entry()->translation(m_practiceOptions.languageTo());
120  KEduVocConjugation& conj = trans->conjugation(m_current->conjugationTense());
121  QList<KEduVocWordFlags> keys = conj.keys();
122 
123  grade_t min_grade = KV_MAX_GRADE;
124  foreach(KEduVocWordFlags key, keys) {
125  min_grade = qMin(conj.conjugation(key).grade(), min_grade);
126  }
127 
128  return min_grade;
129 }
130 
131 void ConjugationBackendMode::updateGrades()
132 {
133  kDebug() << "Grading conjugations";
134 
135  foreach(const KEduVocWordFlags& key, m_pronounFlags) {
136  KEduVocText& text = m_current->entry()->translation(Prefs::solutionLanguage())->
137  conjugation(m_currentTense).conjugation(key);
138 
139  text.incPracticeCount();
140  text.setPracticeDate(QDateTime::currentDateTime());
141 
142  if (m_frontend->resultState() == AbstractFrontend::AnswerCorrect) {
143  if (m_current->statisticBadCount() == 0) {
144  text.incGrade();
145  }
146  } else {
147  text.setGrade(KV_LEV1_GRADE);
148  text.incBadCount();
149  }
150  }
151 }
152 
153 void ConjugationBackendMode::hintAction()
154 {
155  // FIXME
156 }
157 
158 #include "conjugationbackendmode.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::AbstractBackendMode::answerRight
void answerRight()
Practice::ConjugationBackendMode::ConjugationBackendMode
ConjugationBackendMode(const PracticeOptions &PracticeOptions, AbstractFrontend *frontend, QObject *parent, Practice::TestEntryManager *testEntryManager, KEduVocDocument *doc)
Definition: conjugationbackendmode.cpp:26
Practice::PracticeOptions::languageFrom
int languageFrom() const
Definition: practiceoptions.h:27
documentsettings.h
Practice::ConjugationBackendMode::hintAction
virtual void hintAction()
Definition: conjugationbackendmode.cpp:153
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::ConjugationData::tense
QString tense
Definition: conjugationdata.h:29
TestEntry::conjugationTense
QString conjugationTense() const
In conjugation mode, use this tense for the entry.
Definition: testentry.cpp:139
Practice::AbstractBackendMode::m_frontend
AbstractFrontend * m_frontend
Definition: abstractbackendmode.h:83
Practice::AbstractBackendMode::m_current
TestEntry * m_current
Definition: abstractbackendmode.h:84
Practice::ConjugationData::personalPronouns
QStringList personalPronouns
Definition: conjugationdata.h:30
Practice::ConjugationData::questionInfinitive
QString questionInfinitive
Definition: conjugationdata.h:27
Practice::AbstractFrontend::userInput
virtual QVariant userInput()=0
Enables access to the input of the user.
Practice::ConjugationBackendMode::setTestEntry
virtual bool setTestEntry(TestEntry *current)
start practicing a new word.
Definition: conjugationbackendmode.cpp:34
Practice::AbstractFrontend::setQuestionPronunciation
virtual void setQuestionPronunciation(const QString &pronunciationText)=0
TestEntry::conjugationPronouns
QList< KEduVocWordFlags > conjugationPronouns() const
In conjugation mode, use these pronouns for the entry.
Definition: testentry.cpp:149
Practice::AbstractFrontend::setFeedback
virtual void setFeedback(const QVariant &feedback)=0
Practice::ConjugationBackendMode::updateGrades
virtual void updateGrades()
Change the grades for the current entry.
Definition: conjugationbackendmode.cpp:131
Practice::PracticeOptions::languageTo
int languageTo() const
Definition: practiceoptions.h:28
conjugationbackendmode.h
Practice::ConjugationBackendMode::checkAnswer
virtual void checkAnswer()
Definition: conjugationbackendmode.cpp:82
Practice::AbstractFrontend::AnswerCorrect
Definition: abstractfrontend.h:41
TestEntry::statisticBadCount
int statisticBadCount()
Definition: testentry.cpp:54
Practice::AbstractBackendMode::answerWrongShowSolution
void answerWrongShowSolution()
Practice::AbstractFrontend::setSolutionSound
virtual void setSolutionSound(const KUrl &soundUrl)=0
Practice::AbstractBackendMode
Definition: abstractbackendmode.h:26
Practice::ConjugationBackendMode::currentGradeForEntry
virtual grade_t currentGradeForEntry()
Return the worst grade for any pronoun of the current entry.
Definition: conjugationbackendmode.cpp:116
conjugationdata.h
Practice::AbstractFrontend
Definition: abstractfrontend.h:25
Practice::ConjugationData::solutionInfinitive
QString solutionInfinitive
Definition: conjugationdata.h:28
Practice::AbstractBackendMode::m_practiceOptions
PracticeOptions m_practiceOptions
Definition: abstractbackendmode.h:82
Practice::AbstractBackendMode::answerWrongRetry
void answerWrongRetry()
Practice::ConjugationData
Definition: conjugationdata.h:26
Practice::AbstractFrontend::setQuestionSound
virtual void setQuestionSound(const KUrl &soundUrl)=0
Practice::AbstractFrontend::setSolutionPronunciation
virtual void setSolutionPronunciation(const QString &pronunciationText)=0
Practice::AbstractFrontend::resultState
virtual ResultState resultState()=0
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