• 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
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(AbstractFrontend* frontend, QObject* parent,
27  Practice::SessionManagerBase* sessionManager,
28  KEduVocDocument* doc)
29  : AbstractBackendMode(frontend, parent)
30  , m_sessionManager(sessionManager)
31  , m_doc(doc)
32 {
33 }
34 
35 bool ConjugationBackendMode::setTestEntry(TestEntry* current)
36 {
37  ConjugationData data;
38  m_current = current;
39  m_lastAnswers.clear();
40 
41  m_currentTense = m_current->conjugationTense();
42 
43  if (!m_current->entry()->translation(m_current->languageTo())->conjugationTenses().contains(m_currentTense)) {
44  kDebug() << "invalid tense for entry - " << m_currentTense;
45  kDebug() << "tenses: " << m_current->entry()->translation(m_current->languageTo())->conjugationTenses();
46  }
47 
48  data.tense = m_currentTense;
49  m_conjugation = m_current->entry()->translation(m_current->languageTo())->conjugation(m_currentTense);
50  m_pronounFlags = current->conjugationPronouns();
51 
52  data.questionInfinitive = m_current->entry()->translation(m_current->languageFrom())->text();
53  data.solutionInfinitive = m_current->entry()->translation(m_current->languageTo())->text();
54 
55  data.personalPronouns = validPersonalPronouns();
56 
57  m_frontend->setQuestion(qVariantFromValue<ConjugationData>(data));
58  QStringList answers;
59  foreach(const KEduVocWordFlags & key, m_pronounFlags) {
60  answers.append(m_conjugation.conjugation(key).text());
61  }
62  m_frontend->setSolution(answers);
63 
64  m_frontend->setQuestionSound(m_current->entry()->translation(m_current->languageFrom())->soundUrl());
65  m_frontend->setSolutionSound(m_current->entry()->translation(m_current->languageTo())->soundUrl());
66  m_frontend->setQuestionPronunciation(m_current->entry()->translation(m_current->languageFrom())->pronunciation());
67  m_frontend->setSolutionPronunciation(m_current->entry()->translation(m_current->languageTo())->pronunciation());
68  m_frontend->setResultState(AbstractFrontend::QuestionState);
69  m_frontend->showQuestion();
70  return true;
71 }
72 
73 QStringList ConjugationBackendMode::validPersonalPronouns()
74 {
75  QStringList pp;
76  foreach(const KEduVocWordFlags & person, m_pronounFlags) {
77  // FIXME: Used to be m_practiceOptions.languageTo()
78  pp.append(m_doc->identifier(Prefs::learningLanguage()).personalPronouns().personalPronoun(person));
79  }
80  kDebug() << "PP: " << pp.size() << pp;
81  return pp;
82 }
83 
84 void ConjugationBackendMode::checkAnswer()
85 {
86  QStringList answers = m_frontend->userInput().toStringList();
87 
88  bool allCorrect = true;
89  int numRight = 0;
90  int i = 0;
91  foreach(const KEduVocWordFlags & key, m_pronounFlags) {
92  if (answers.at(i) == m_conjugation.conjugation(key).text()) {
93  ++numRight;
94  } else {
95  kDebug() << "dec grade for " << m_conjugation.conjugation(key).text();
96  allCorrect = false;
97  }
98  ++i;
99  }
100 
101  kDebug() << "answers: " << answers;
102 
103  if (allCorrect) {
104  m_frontend->setFeedback(i18n("All conjugation forms were right."));
105  emit answerRight();
106  } else {
107  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));
108 
109  if (answers == m_lastAnswers) {
110  emit answerWrongShowSolution();
111  } else {
112  emit answerWrongRetry();
113  }
114  m_lastAnswers = answers;
115  }
116 }
117 
118 grade_t ConjugationBackendMode::currentPreGradeForEntry() const
119 {
120  Q_ASSERT(m_current != 0);
121  KEduVocTranslation* trans = m_current->entry()->translation(m_current->languageTo());
122  KEduVocConjugation& conj = trans->conjugation(m_current->conjugationTense());
123  QList<KEduVocWordFlags> keys = conj.keys();
124 
125  grade_t min_grade = KV_MAX_GRADE;
126  foreach(KEduVocWordFlags key, keys) {
127  min_grade = qMin(conj.conjugation(key).preGrade(), min_grade);
128  }
129 
130  return min_grade;
131 }
132 
133 grade_t ConjugationBackendMode::currentGradeForEntry() const
134 {
135  Q_ASSERT(m_current != 0);
136  KEduVocTranslation* trans = m_current->entry()->translation(m_current->languageTo());
137  KEduVocConjugation& conj = trans->conjugation(m_current->conjugationTense());
138  QList<KEduVocWordFlags> keys = conj.keys();
139 
140  grade_t min_grade = KV_MAX_GRADE;
141  foreach(KEduVocWordFlags key, keys) {
142  min_grade = qMin(conj.conjugation(key).grade(), min_grade);
143  }
144 
145  return min_grade;
146 }
147 
148 void ConjugationBackendMode::updateGrades()
149 {
150  kDebug() << "Grading conjugations";
151 
152  foreach(const KEduVocWordFlags & key, m_pronounFlags) {
153  KEduVocText& text = m_current->entry()->translation(m_current->languageTo())->
154  conjugation(m_currentTense).conjugation(key);
155 
156  text.incPracticeCount();
157  text.setPracticeDate(QDateTime::currentDateTime());
158 
159  updateGrade(text, m_frontend->resultState() == AbstractFrontend::AnswerCorrect,
160  m_current->statisticBadCount() == 0);
161  }
162 }
163 
164 void ConjugationBackendMode::hintAction()
165 {
166  // FIXME
167 }
168 
169 #include "conjugationbackendmode.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::ConjugationBackendMode::ConjugationBackendMode
ConjugationBackendMode(AbstractFrontend *frontend, QObject *parent, Practice::SessionManagerBase *sessionManager, KEduVocDocument *doc)
Definition: conjugationbackendmode.cpp:26
Practice::AbstractFrontend::showQuestion
virtual void showQuestion()=0
enter question mode - the user is asked to provide the solution
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::ConjugationBackendMode::hintAction
virtual void hintAction()
Definition: conjugationbackendmode.cpp:164
Practice::ConjugationBackendMode::currentGradeForEntry
virtual grade_t currentGradeForEntry() const
Return the worst grade for any pronoun of the current entry.
Definition: conjugationbackendmode.cpp:133
Practice::AbstractFrontend::QuestionState
Definition: abstractfrontend.h:42
Practice::AbstractFrontend::setSolution
virtual void setSolution(const QVariant &solution)=0
Practice::ConjugationData::tense
QString tense
Definition: conjugationdata.h:30
TestEntry::conjugationTense
QString conjugationTense() const
In conjugation mode, use this tense for the entry.
Definition: testentry.cpp:154
QList::size
int size() const
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::ConjugationData::personalPronouns
QStringList personalPronouns
Definition: conjugationdata.h:31
Practice::ConjugationData::questionInfinitive
QString questionInfinitive
Definition: conjugationdata.h:28
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:35
QObject
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:164
Practice::AbstractFrontend::setFeedback
virtual void setFeedback(const QVariant &feedback)=0
QList< KEduVocWordFlags >
QStringList
Practice::ConjugationBackendMode::updateGrades
virtual void updateGrades()
Change the grades for the current entry.
Definition: conjugationbackendmode.cpp:148
conjugationbackendmode.h
Practice::ConjugationBackendMode::checkAnswer
virtual void checkAnswer()
Definition: conjugationbackendmode.cpp:84
Practice::AbstractFrontend::AnswerCorrect
Definition: abstractfrontend.h:43
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
conjugationdata.h
Practice::AbstractFrontend
Definition: abstractfrontend.h:26
Practice::ConjugationData::solutionInfinitive
QString solutionInfinitive
Definition: conjugationdata.h:29
Practice::AbstractBackendMode::answerWrongRetry
void answerWrongRetry()
Prefs::learningLanguage
static int learningLanguage()
Get The language that you are learning.
Definition: prefs.h:1248
Practice::ConjugationData
Definition: conjugationdata.h:27
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
Practice::AbstractFrontend::setSolutionPronunciation
virtual void setSolutionPronunciation(const QString &pronunciationText)=0
Practice::AbstractFrontend::resultState
virtual ResultState resultState()=0
Practice::ConjugationBackendMode::currentPreGradeForEntry
virtual grade_t currentPreGradeForEntry() const
Return the worst pregrade for any pronoun of the current entry.
Definition: conjugationbackendmode.cpp:118
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