[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdeedu/kiten
From: Anne-Marie Mahfouf <annma () kde ! org>
Date: 2005-01-27 14:18:18
Message-ID: 20050127141818.BC23D18FC3 () office ! kde ! org
[Download RAW message or body]
CVS commit by annma:
Patch from Paul Temple, implementing wish #41083
BUG:41083
M +27 -8 learn.cpp 1.22
M +2 -0 learn.h 1.9
--- kdeedu/kiten/learn.cpp #1.21:1.22
@@ -38,4 +38,5 @@
#include <stdlib.h> // RAND_MAX
#include <cassert>
+#include <set>
#include "dict.h"
@@ -99,6 +100,4 @@ Learn::Learn(Dict::Index *parentDict, QW
List->setSelectionModeExt(KListView::Extended);
- List->header()->setClickEnabled(false);
-
connect(List, SIGNAL(executed(QListViewItem *)), SLOT(showKanji(QListViewItem *)));
connect(List, SIGNAL(selectionChanged()), this, SLOT(itemSelectionChanged()));
@@ -769,4 +768,12 @@ void Learn::qupdate()
}
+struct Learn::scoreCompare
+{
+ bool operator()(const QListViewItem* v1, const QListViewItem* v2)
+ {
+ return v1->text(4).toInt() < v2->text(4).toInt();
+ }
+};
+
void Learn::qnew() // new quiz kanji
{
@@ -784,4 +791,9 @@ void Learn::qnew() // new quiz kanji
return;
+ // the following lines calculate which kanji will be used next:
+ // use f(2) every third time, f(1) otherwise
+ // where f(1) = numberOfItems * rand[0..1]
+ // and f(2) = numberOfItems * rand[0..1] * rand[0..1]
+ // rand[0..1] = kapp->random() / RAND_MAX
float max = static_cast<float>(count) / (static_cast<float>(RAND_MAX) / kapp->random());
if (kapp->random() < (static_cast<float>(RAND_MAX) / 3.25))
@@ -793,14 +805,21 @@ void Learn::qnew() // new quiz kanji
max = count;
- QListViewItemIterator it(List);
- QListViewItemIterator tmp(List);
+ std::multiset<const QListViewItem*, scoreCompare> scores;
+ QListViewItemIterator sIt(List);
+
+ for (; sIt.current(); ++sIt)
+ scores.insert(sIt.current());
+
+ std::multiset<const QListViewItem*>::iterator it = scores.begin();
+ std::multiset<const QListViewItem*>::iterator tmp = scores.begin();
+
int i;
for (i = 2; i <= max; ++it)
{i++; ++tmp;}
- if (curItem->text(0) == it.current()->text(0)) // same, don't use
+ if (curItem->text(0) == (*it)->text(0)) // same, don't use
{
++it;
- if (!it.current())
+ if (it == scores.end())
{
tmp--;
@@ -809,5 +828,5 @@ void Learn::qnew() // new quiz kanji
}
- if (!it.current())
+ if (it == scores.end())
{
return;
@@ -815,5 +834,5 @@ void Learn::qnew() // new quiz kanji
prevItem = curItem;
- curItem = it.current();
+ curItem = const_cast<QListViewItem*>(*it);
qKanji->setFocus();
--- kdeedu/kiten/learn.h #1.8:1.9
@@ -54,4 +54,6 @@ class Learn : public KMainWindow
bool closeWindow();
+ struct scoreCompare;
+
signals:
void destroyed(Learn *);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic