• 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
abstractbackendmode.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 "abstractbackendmode.h"
16 #include "prefs.h"
17 #include <kdebug.h>
18 
19 using namespace Practice;
20 
21 AbstractBackendMode::AbstractBackendMode(Practice::AbstractFrontend* frontend, QObject *parent)
22  : QObject(parent)
23  , m_frontend(frontend)
24  , m_current(0)
25 {
26 }
27 
28 bool AbstractBackendMode::setTestEntry(TestEntry* current)
29 {
30  m_current = current;
31  // this default implementation sets up the frontend with the normal word
32  KEduVocTranslation *translation = m_current->entry()->translation(m_current->languageFrom());
33  if (!translation->text().isEmpty()) {
34  m_frontend->setQuestion(translation->text());
35  } else if (!translation->imageUrl().isEmpty()) {
36  m_frontend->setQuestion(translation->imageUrl());
37  }
38  m_frontend->setSolution(m_current->entry()->translation(m_current->languageTo())->text());
39  if (Prefs::practiceSoundEnabled() == true) {
40  m_frontend->setQuestionSound(
41  m_current->entry()-> translation(m_current->languageFrom())->soundUrl());
42  m_frontend->setSolutionSound(
43  m_current->entry()->translation(m_current->languageTo())->soundUrl());
44  }
45  m_frontend->setQuestionPronunciation(
46  m_current->entry()->translation(m_current->languageFrom())->pronunciation());
47  m_frontend->setSolutionPronunciation(
48  m_current->entry()->translation(m_current->languageTo())->pronunciation());
49 
50  return true;
51 }
52 
53 grade_t Practice::AbstractBackendMode::currentPreGradeForEntry() const
54 {
55  return m_current->entry()->translation(m_current->languageTo())->preGrade();
56 }
57 
58 grade_t Practice::AbstractBackendMode::currentGradeForEntry() const
59 {
60  return m_current->entry()->translation(m_current->languageTo())->grade();
61 }
62 
63 void Practice::AbstractBackendMode::updateGrades()
64 {
65  KEduVocTranslation* translation = m_current->entry()->translation(m_current->languageTo());
66  //kDebug() << "Update Grades Default Implementation: " << m_frontend->resultState()
67  // << " for " << translation->text()
68  // << " grade: " << m_current->entry()->translation(m_current->languageTo())->grade();
69 
70  translation->incPracticeCount();
71  translation->setPracticeDate(QDateTime::currentDateTime());
72 
73  updateGrade(*translation, m_frontend->resultState() == AbstractFrontend::AnswerCorrect,
74  m_current->statisticBadCount() == 0);
75 
76  //kDebug() << "new grade: " << m_current->entry()->translation(m_current->languageTo())->grade();
77 }
78 
79 
80 // ----------------------------------------------------------------
81 // protected methods
82 
83 
84 void Practice::AbstractBackendMode::updateGrade(KEduVocText &text, bool isCorrectAnswer,
85  bool hasNoPreviousBadAnswers)
86 {
87  if (isCorrectAnswer) {
88  if (hasNoPreviousBadAnswers) {
89  if (text.grade() == KV_NORM_GRADE) {
90  if (text.preGrade() == KV_NORM_GRADE) {
91  // If the word was new and correct answer, then
92  // set it to grade, pregrade 2, 0. This is so
93  // that the user doesn't have to go through all
94  // the pregrade levels with words that s/he
95  // already knows well.
96  text.setPreGrade(KV_NORM_GRADE);
97  text.setGrade(KV_LEV2_GRADE);
98  }
99  else if (text.preGrade() == KV_MAX_GRADE) {
100  // If correct answer and last pregrade level, then
101  // set new grade, pregrade to 1, 0.
102  text.setPreGrade(KV_NORM_GRADE);
103  text.setGrade(KV_LEV1_GRADE);
104  }
105  else {
106  // otherwise just increase the pregrade.
107  text.setPreGrade(text.preGrade() + 1); // FIXME: Implement incPreGrade() in the library.
108  }
109  }
110  else {
111  // If grade was > 0 then just increase it.
112  text.incGrade();
113  }
114  }
115  } else {
116  // If the answer was wrong, reset the grade, pregrade to 0, 1.
117  text.setPreGrade(KV_LEV1_GRADE);
118  text.setGrade(KV_NORM_GRADE);
119  text.incBadCount();
120  }
121 
122  //kDebug() << "new pregrade, grade: " << text.preGrade() << text.grade();
123 }
124 
125 
126 
127 #include "abstractbackendmode.moc"
TestEntry::entry
KEduVocExpression * entry() const
Definition: testentry.cpp:149
Practice::AbstractFrontend::setQuestion
virtual void setQuestion(const QVariant &question)=0
Prefs::practiceSoundEnabled
static bool practiceSoundEnabled()
Get Enable sound playback in the practice dialogs.
Definition: prefs.h:716
Practice::AbstractBackendMode::updateGrade
void updateGrade(KEduVocText &text, bool isCorrectAnswer, bool hasNoPreviousBadAnswers)
Update the grade for the current entry.
Definition: abstractbackendmode.cpp:84
prefs.h
Practice::AbstractFrontend::setSolution
virtual void setSolution(const QVariant &solution)=0
Practice::AbstractBackendMode::m_frontend
AbstractFrontend * m_frontend
Definition: abstractbackendmode.h:121
Practice::AbstractBackendMode::m_current
TestEntry * m_current
Definition: abstractbackendmode.h:122
QObject
Practice::AbstractFrontend::setQuestionPronunciation
virtual void setQuestionPronunciation(const QString &pronunciationText)=0
abstractbackendmode.h
Practice::AbstractBackendMode::updateGrades
virtual void updateGrades()
Change the grades for the current entry.
Definition: abstractbackendmode.cpp:63
Practice::AbstractBackendMode::setTestEntry
virtual bool setTestEntry(TestEntry *current)
start practicing a new word.
Definition: abstractbackendmode.cpp:28
Practice::AbstractFrontend::AnswerCorrect
Definition: abstractfrontend.h:43
QDateTime::currentDateTime
QDateTime currentDateTime()
Practice::AbstractFrontend::setSolutionSound
virtual void setSolutionSound(const KUrl &soundUrl)=0
TestEntry::languageFrom
int languageFrom() const
Definition: testentry.cpp:109
Practice::AbstractBackendMode::currentGradeForEntry
virtual grade_t currentGradeForEntry() const
The grade of the current entry - this has a default implementation to return the grade for the curren...
Definition: abstractbackendmode.cpp:58
Practice::AbstractFrontend
Definition: abstractfrontend.h:26
Practice::AbstractBackendMode::AbstractBackendMode
AbstractBackendMode(AbstractFrontend *frontend, QObject *parent)
Definition: abstractbackendmode.cpp:21
TestEntry::languageTo
int languageTo() const
Definition: testentry.cpp:114
Practice::AbstractFrontend::setQuestionSound
virtual void setQuestionSound(const KUrl &soundUrl)=0
Practice::AbstractFrontend::setSolutionPronunciation
virtual void setSolutionPronunciation(const QString &pronunciationText)=0
Practice::AbstractBackendMode::currentPreGradeForEntry
virtual grade_t currentPreGradeForEntry() const
The pregrade of the current entry - this has a default implementation to return the pregrade for the ...
Definition: abstractbackendmode.cpp:53
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