• 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
sessionmanagerfixed.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  copyright : (C) 2014 Inge Wallin <inge@lysator.liu.se>
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 #include "sessionmanagerfixed.h"
15 
16 // kdelibs
17 #include <klocale.h>
18 #include <kconfig.h>
19 #include <KDebug>
20 
21 // kdeedulibs
22 #include <keduvocexpression.h>
23 
24 // parley
25 #include <prefs.h>
26 
27 
28 using namespace Practice;
29 
30 SessionManagerFixed::SessionManagerFixed(QWidget* parent)
31  : SessionManagerBase(parent)
32 {
33 }
34 
35 SessionManagerFixed::~SessionManagerFixed()
36 {
37 }
38 
39 
40 void SessionManagerFixed::initializeTraining()
41 {
42  const int MaxEntries = Prefs::sessionMaxSize();
43  const int MaxNewWords = Prefs::sessionMaxNewWords();
44 
45  // We will never add anything to the session after it's initialized.
46  m_notAskedTestEntries.clear();
47 
48  // Pick N new words if there are any into the active set.
49  int numNewWords = 0;
50  int i = 0;
51  while (i < m_allTestEntries.count()
52  && numNewWords < MaxNewWords
53  && m_currentEntries.count() < MaxEntries)
54  {
55  TestEntry *it = m_allTestEntries.at(i);
56  if (it->entry()->translation(it->languageTo())->grade() == 0
57  && it->entry()->translation(it->languageTo())->preGrade() == 0) {
58  m_currentEntries.append(it);
59  numNewWords++;
60  }
61 
62  ++i;
63  }
64 
65  // Pick the rest of the words from the already practiced ones.
66  // Use higher graded entries before lower graded ones.
67  for (int grade = KV_MAX_GRADE; grade > 0 ; --grade) {
68  if (m_currentEntries.count() >= MaxEntries) {
69  break;
70  }
71 
72  // Step through all entries and collect those at the current
73  // grade until the session is filled.
74  foreach (TestEntry *entry, m_allTestEntries) {
75  if (entry->entry()->translation(entry->languageTo())->grade() == grade) {
76  m_currentEntries.append(entry);
77  }
78  if (m_currentEntries.count() >= MaxEntries) {
79  break;
80  }
81  }
82  }
83 
84  // If there is still room in the session, pick the rest of the
85  // words from the ones with pregrades. Also here, use higher
86  // graded entries before lower graded ones.
87  for (int preGrade = KV_MAX_GRADE; preGrade > 0 ; --preGrade) {
88  if (m_currentEntries.count() >= MaxEntries) {
89  break;
90  }
91 
92  // Step through all entries and collect those at the current
93  // grade until the session is filled.
94  foreach (TestEntry *entry, m_allTestEntries) {
95  if (entry->entry()->translation(entry->languageTo())->preGrade() == preGrade) {
96  m_currentEntries.append(entry);
97  }
98  if (m_currentEntries.count() >= MaxEntries) {
99  break;
100  }
101  }
102  }
103 
104  // Now we have decided exactly which ones to use.
105  // We need to keep this for statistics reporting at the end.
106  //
107  // FIXME: Seems to be a memory leak here.
108 
109  // m_allTestEntries owns all test entries and now it
110  // suddenly gets assigned a potentially smaller subset.
111  // Those which were pointed to by pointers inside
112  // m_allTestEntries but not also a pointer inside
113  // m_currentEntries are lost.
114  m_allTestEntries = m_currentEntries;
115 }
QList::clear
void clear()
QWidget
TestEntry::entry
KEduVocExpression * entry() const
Definition: testentry.cpp:149
sessionmanagerfixed.h
Practice::SessionManagerFixed::initializeTraining
virtual void initializeTraining()
Initialize the lists of entries that will be used in the training from the full set of available entr...
Definition: sessionmanagerfixed.cpp:40
QList::at
const T & at(int i) const
prefs.h
Practice::SessionManagerFixed::~SessionManagerFixed
virtual ~SessionManagerFixed()
destructor
Definition: sessionmanagerfixed.cpp:35
Practice::SessionManagerFixed::SessionManagerFixed
SessionManagerFixed(QWidget *parent)
Create a collection of entries to be practiced.
Definition: sessionmanagerfixed.cpp:30
Practice::SessionManagerBase::m_currentEntries
QList< TestEntry * > m_currentEntries
The list of entries that are being asked.
Definition: sessionmanagerbase.h:167
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
Practice::SessionManagerBase::m_notAskedTestEntries
QList< TestEntry * > m_notAskedTestEntries
All entries that have not been entered into the active set.
Definition: sessionmanagerbase.h:162
Practice::SessionManagerBase::m_allTestEntries
QList< TestEntry * > m_allTestEntries
All entries available in the document that fulfill the requirements set in the configuration and the ...
Definition: sessionmanagerbase.h:159
Prefs::sessionMaxNewWords
static int sessionMaxNewWords()
Get The maximum number of new (untrained) words that will be used in a training session.
Definition: prefs.h:773
Prefs::sessionMaxSize
static int sessionMaxSize()
Get The maximum number of words that will be practiced in a training session.
Definition: prefs.h:754
TestEntry::languageTo
int languageTo() const
Definition: testentry.cpp:114
Practice::SessionManagerBase
Definition: sessionmanagerbase.h:40
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