Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
KWordQuiz
Commits
71487a63
Commit
71487a63
authored
Oct 26, 2022
by
Nicolas Fella
Browse files
Port away from KRandomSequence
parent
d694ecc7
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/kwqquizmodel.cpp
View file @
71487a63
...
...
@@ -10,6 +10,10 @@
#include
"kwqsortfiltermodel.h"
#include
"kwqtablemodel.h"
#include
<QRandomGenerator>
#include
<KRandom>
KWQQuizModel
::
KWQQuizModel
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{
m_sourceModel
=
0
;
...
...
@@ -124,8 +128,7 @@ void KWQQuizModel::activateBaseList()
m_list
.
append
(
l
);
if
(
m_quizMode
>
2
)
{
KRandomSequence
rs
;
rs
.
randomize
(
m_list
);
KRandom
::
shuffle
(
m_list
,
QRandomGenerator
::
global
());
};
m_questionCount
=
m_list
.
count
();
...
...
@@ -203,16 +206,15 @@ bool KWQQuizModel::checkAnswer(const QString & a)
QStringList
KWQQuizModel
::
multiOptions
()
{
QStringList
ls
;
KRandomSequence
rs
;
int
a
=
-
1
;
int
b
=
-
1
;
do
a
=
rs
.
getLong
(
m_questionCount
);
a
=
QRandomGenerator
::
global
()
->
bounded
(
m_questionCount
);
while
(
a
==
m_currentQuestion
);
do
b
=
rs
.
getLong
(
m_questionCount
);
b
=
QRandomGenerator
::
global
()
->
bounded
(
m_questionCount
);
while
(
b
==
m_currentQuestion
||
b
==
a
);
int
row
=
m_list
.
at
(
m_currentQuestion
);
...
...
@@ -234,7 +236,7 @@ QStringList KWQQuizModel::multiOptions()
}
}
rs
.
r
andom
ize
(
ls
);
KR
andom
::
shuffle
(
ls
,
QRandomGenerator
::
global
()
);
return
ls
;
}
...
...
src/kwqsortfiltermodel.cpp
View file @
71487a63
...
...
@@ -6,7 +6,7 @@
#include
"kwqsortfiltermodel.h"
#include
"kwqtablemodel.h"
#include
<KRandom
Sequence
>
#include
<KRandom>
KWQSortFilterModel
::
KWQSortFilterModel
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{
...
...
@@ -54,8 +54,7 @@ void KWQSortFilterModel::shuffle()
for
(
int
i
=
0
;
i
<
rowCount
(
QModelIndex
());
++
i
)
m_shuffleList
.
append
(
i
);
KRandomSequence
rs
;
rs
.
randomize
(
m_shuffleList
);
KRandom
::
shuffle
(
m_shuffleList
,
QRandomGenerator
::
global
());
m_shuffle
=
true
;
sort
(
0
,
Qt
::
AscendingOrder
);
invalidate
();
...
...
src/kwqtutor.cpp
View file @
71487a63
...
...
@@ -10,6 +10,7 @@
#include
<QMenu>
#include
<QPointer>
#include
<QTimer>
#include
<QRandomGenerator>
#include
<KLocalizedString>
#include
<KMessageBox>
...
...
@@ -66,7 +67,6 @@ KWQTutor::KWQTutor(const QUrl &fileToOpen, QWidget *parent) : KStatusNotifierIte
m_timer
=
new
QTimer
;
connect
(
m_timer
,
&
QTimer
::
timeout
,
this
,
&
KWQTutor
::
updateTimer
);
m_randomSequence
=
new
KRandomSequence
();
m_flashcard
=
new
KWQTutorFlashCard
();
m_tutorDoc
=
new
KEduVocDocument
();
...
...
@@ -84,7 +84,6 @@ KWQTutor::KWQTutor(const QUrl &fileToOpen, QWidget *parent) : KStatusNotifierIte
KWQTutor
::~
KWQTutor
()
{
delete
m_randomSequence
;
}
void
KWQTutor
::
updateTimer
()
...
...
@@ -93,14 +92,12 @@ void KWQTutor::updateTimer()
if
(
Prefs
::
tutorTiming
()
==
Prefs
::
EnumTutorTiming
::
FixedInterval
)
interval
=
Prefs
::
tutorEvery
();
else
if
(
Prefs
::
tutorTiming
()
==
Prefs
::
EnumTutorTiming
::
RandomInterval
)
{
do
interval
=
m_randomSequence
->
getLong
(
Prefs
::
tutorMax
());
while
(
interval
<
Prefs
::
tutorMin
());
interval
=
QRandomGenerator
::
global
()
->
bounded
(
Prefs
::
tutorMin
(),
Prefs
::
tutorMax
());
}
qDebug
()
<<
interval
;
m_timer
->
start
(
1000
*
60
*
interval
);
if
(
!
m_flashcard
->
isVisible
())
showFlashcard
(
m_r
andom
Sequence
->
getLong
(
m_tutorDoc
->
lesson
()
->
entryCount
(
KEduVocLesson
::
Recursive
)
-
1
));
showFlashcard
(
QR
andom
Generator
::
global
()
->
bounded
(
m_tutorDoc
->
lesson
()
->
entryCount
(
KEduVocLesson
::
Recursive
)
-
1
));
}
void
KWQTutor
::
startStopPressed
()
...
...
src/kwqtutor.h
View file @
71487a63
...
...
@@ -6,7 +6,6 @@
#ifndef KWQTUTOR_H
#define KWQTUTOR_H
#include
<KRandomSequence>
#include
<KActionCollection>
#include
<KStatusNotifierItem>
...
...
@@ -44,7 +43,6 @@ class KWQTutor : public KStatusNotifierItem
private:
/* random number generator*/
KRandomSequence
*
m_randomSequence
;
/* an entry of KEduVocDocument which is currently being displayed in flashcard */
int
m_currentEntry
;
int
m_currentColumn
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment