• 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
genderbackendmode.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 "genderbackendmode.h"
16 
17 #include <klocale.h>
18 
19 #include <keduvocdocument.h>
20 #include <keduvocwordtype.h>
21 
22 using namespace Practice;
23 
24 GenderBackendMode::GenderBackendMode(AbstractFrontend* frontend, QObject* parent,
25  Practice::SessionManagerBase* sessionManager,
26  KEduVocDocument* doc)
27  : MultipleChoiceBackendMode(frontend, parent, sessionManager)
28  , m_doc( *doc )
29 {
30 }
31 
32 bool GenderBackendMode::setTestEntry(TestEntry* current)
33 {
34  Practice::AbstractBackendMode::setTestEntry(current);
35 
36  m_articles = m_doc.identifier(m_current->languageTo()).article();
37 
38  KEduVocWordFlag::Flags singular = KEduVocWordFlag::Singular;
39  KEduVocWordFlag::Flags definite = KEduVocWordFlag::Definite;
40  KEduVocWordFlag::Flags indefinite = KEduVocWordFlag::Indefinite;
41  KEduVocWordFlag::Flags masculine = KEduVocWordFlag::Masculine;
42  KEduVocWordFlag::Flags feminine = KEduVocWordFlag::Feminine;
43  KEduVocWordFlag::Flags neuter = KEduVocWordFlag::Neuter;
44 
45  m_masculine = m_articles.article(singular | definite | masculine);
46  if (m_masculine.isEmpty()) {
47  m_masculine = m_articles.article(singular | indefinite | masculine);
48  }
49 
50  m_feminine = m_articles.article(singular | definite | feminine);
51  if (m_feminine.isEmpty()) {
52  m_feminine = m_articles.article(singular | indefinite | feminine);
53  }
54 
55  m_neuter = m_articles.article(singular | definite | neuter);
56  if (m_neuter.isEmpty()) {
57  m_neuter = m_articles.article(singular | indefinite | neuter);
58  }
59 
60  // best bet... if it is defined, it must exist, or if none of them is defined
61  m_neuterExists = (!m_neuter.isEmpty()) || (m_masculine.isEmpty() && m_feminine.isEmpty());
62 
63  prepareChoices(current);
64  populateFrontEnd();
65 
66  return true;
67 }
68 void GenderBackendMode::prepareChoices(TestEntry* entry)
69 {
70  Q_ASSERT(entry->entry()->translation(entry->languageTo())->wordType()->wordType() & KEduVocWordFlag::Noun);
71 
72  setQuestion(i18n("Choose the right article for \"%1\"", entry->entry()->translation(entry->languageFrom())->text()));
73 
74  // set the word (possibly without the article)
75  QString noun = entry->entry()->translation(m_current->languageTo())->text();
76 
77  // strip the article
78  QStringList qsl = noun.split(QRegExp("\\s"), QString::SkipEmptyParts);
79  QMutableStringListIterator qsli(qsl);
80  while (qsli.hasNext())
81  if (m_articles.isArticle(qsli.next()))
82  qsli.remove();
83 
84  noun = qsl.join(" ");
85 
86  QString solution(noun);
87 
88  // set the choices
89  QStringList choices;
90 
91  if (!m_masculine.isEmpty()) {
92  choices.append(m_masculine + ' ' + noun);
93  } else {
94  choices.append(i18nc("@label the gender of the word: masculine", "%1 is masculine", noun));
95  }
96  if (!m_feminine.isEmpty()) {
97  choices.append(m_feminine + ' ' + noun);
98  } else {
99  choices.append(i18nc("@label the gender of the word: feminine", "%1 is feminine", noun));
100  }
101  if (m_neuterExists && !m_neuter.isEmpty()) {
102  choices.append(m_neuter + ' ' + noun);
103  } else {
104  choices.append(i18nc("@label the gender of the word: neuter", "%1 is neuter", noun));
105  }
106 
107  setChoices(choices);
108 
109  kDebug() << entry->entry()->translation(entry->languageTo())->wordType()->wordType();
110  if (entry->entry()->translation(entry->languageTo())->wordType()->wordType() & KEduVocWordFlag::Masculine) {
111  setCorrectAnswer(0);
112  kDebug() << "male";
113  } else if (entry->entry()->translation(entry->languageTo())->wordType()->wordType() & KEduVocWordFlag::Feminine) {
114  setCorrectAnswer(1);
115  kDebug() << "female";
116  } else {
117  setCorrectAnswer(2);
118  kDebug() << "neuter";
119  }
120 }
121 
122 void GenderBackendMode::updateGrades()
123 {
124  KEduVocText articleGrade = m_current->entry()->translation(m_current->languageTo())->article();
125  articleGrade.incPracticeCount();
126  articleGrade.setPracticeDate(QDateTime::currentDateTime());
127  updateGrade(articleGrade, m_frontend->resultState() == AbstractFrontend::AnswerCorrect,
128  m_current->statisticBadCount() == 0);
129 
130  m_current->entry()->translation(m_current->languageTo())->setArticle(articleGrade);
131 }
132 
133 
134 #include "genderbackendmode.moc"
Practice::GenderBackendMode::GenderBackendMode
GenderBackendMode(AbstractFrontend *frontend, QObject *parent, Practice::SessionManagerBase *sessionManager, KEduVocDocument *doc)
Definition: genderbackendmode.cpp:24
Practice::MultipleChoiceBackendMode::setCorrectAnswer
void setCorrectAnswer(int index)
The correct solution, index of the choices.
Definition: multiplechoicebackendmode.cpp:90
TestEntry::entry
KEduVocExpression * entry() const
Definition: testentry.cpp:149
Practice::MultipleChoiceBackendMode::setChoices
void setChoices(const QStringList &choices)
This must include the correct answer.
Definition: multiplechoicebackendmode.cpp:85
Practice::MultipleChoiceBackendMode::populateFrontEnd
virtual void populateFrontEnd()
Configure the multiple choice front end.
Definition: multiplechoicebackendmode.cpp:58
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
Practice::AbstractBackendMode::updateGrade
void updateGrade(KEduVocText &text, bool isCorrectAnswer, bool hasNoPreviousBadAnswers)
Update the grade for the current entry.
Definition: abstractbackendmode.cpp:84
Practice::GenderBackendMode::updateGrades
virtual void updateGrades()
Change the grades for the current entry.
Definition: genderbackendmode.cpp:122
QStringList::join
QString join(const QString &separator) const
genderbackendmode.h
Practice::AbstractBackendMode::m_frontend
AbstractFrontend * m_frontend
Definition: abstractbackendmode.h:121
QRegExp
QList::append
void append(const T &value)
Practice::AbstractBackendMode::m_current
TestEntry * m_current
Definition: abstractbackendmode.h:122
QObject
QString::isEmpty
bool isEmpty() const
Practice::MultipleChoiceBackendMode
Definition: multiplechoicebackendmode.h:24
QString
QStringList
Practice::AbstractBackendMode::setTestEntry
virtual bool setTestEntry(TestEntry *current)
start practicing a new word.
Definition: abstractbackendmode.cpp:28
Practice::AbstractFrontend::AnswerCorrect
Definition: abstractfrontend.h:43
TestEntry::statisticBadCount
int statisticBadCount()
Definition: testentry.cpp:54
QDateTime::currentDateTime
QDateTime currentDateTime()
TestEntry::languageFrom
int languageFrom() const
Definition: testentry.cpp:109
Practice::AbstractFrontend
Definition: abstractfrontend.h:26
Practice::GenderBackendMode::setTestEntry
virtual bool setTestEntry(TestEntry *current)
Start practicing a new word.
Definition: genderbackendmode.cpp:32
TestEntry::languageTo
int languageTo() const
Definition: testentry.cpp:114
Practice::SessionManagerBase
Definition: sessionmanagerbase.h:40
Practice::MultipleChoiceBackendMode::setQuestion
void setQuestion(const QString &question)
Set the question/original language.
Definition: multiplechoicebackendmode.cpp:75
Practice::GenderBackendMode::prepareChoices
virtual void prepareChoices(TestEntry *current)
set the list of possible answers.
Definition: genderbackendmode.cpp:68
Practice::AbstractFrontend::resultState
virtual ResultState resultState()=0
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