Commit 71487a63 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Port away from KRandomSequence

parent d694ecc7
......@@ -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.randomize(ls);
KRandom::shuffle(ls, QRandomGenerator::global());
return ls;
}
......
......@@ -6,7 +6,7 @@
#include "kwqsortfiltermodel.h"
#include "kwqtablemodel.h"
#include <KRandomSequence>
#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();
......
......@@ -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_randomSequence->getLong(m_tutorDoc->lesson()->entryCount(KEduVocLesson::Recursive) - 1));
showFlashcard(QRandomGenerator::global()->bounded(m_tutorDoc->lesson()->entryCount(KEduVocLesson::Recursive) - 1));
}
void KWQTutor::startStopPressed()
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment