Commit b05bf7ef authored by Pino Toscano's avatar Pino Toscano
Browse files

Change KGmap::getRandomDivision to return a division

A division pointer is what askers need anyway, so returning it saves
one extra lookup to get the division pointer from the name.

There should be no behaviour change.
parent 2f4bdcdf
......@@ -81,10 +81,13 @@ void askWidget::nextQuestion()
QString aux;
if (p_asked.count() < p_count)
{
aux = p_map -> getRandomDivision(askMode());
while (p_asked.indexOf(aux) != -1) aux = p_map -> getRandomDivision(askMode());
division *div;
do
{
div = p_map -> getRandomDivision(askMode());
aux = div -> getUntranslatedName();
} while (p_asked.indexOf(aux) != -1);
p_asked << aux;
const division *div = p_map -> getDivision(aux);
nextQuestionHook(div);
}
else emit questionsEnded();
......
......@@ -201,10 +201,12 @@ void boxAsker::nextQuestionHook(const division *div)
{
if (p_radioButtons[j] -> text().isNull() && p_radioButtons[j] -> icon().isNull())
{
otherDivision = p_map -> getRandomDivision(askMode());
while (auxList.contains(otherDivision))
otherDivision = p_map -> getRandomDivision(askMode());
const division *otherDiv = p_map -> getDivision(otherDivision);
division *otherDiv;
do
{
otherDiv = p_map -> getRandomDivision(askMode());
otherDivision = otherDiv -> getUntranslatedName();
} while (auxList.contains(otherDivision));
if (nextBoxAskerQuestionHook(otherDiv, j, false))
++j;
auxList << otherDivision;
......
......@@ -162,12 +162,12 @@ QString KGmap::getDivisionsString() const
else return p_divisionsString;
}
QString KGmap::getRandomDivision(division::askMode am) const
division *KGmap::getRandomDivision(division::askMode am) const
{
QList<division*> aux;
int i = (int)((float)p_divisions.size() * KRandom::random() / (RAND_MAX + 1.0));
if (!p_divisions[i] -> canAsk(am)) return getRandomDivision(am);
else return p_divisions[i] -> getUntranslatedName();
else return p_divisions[i];
}
QString KGmap::getWhatIs(QRgb c, bool all) const
......
......@@ -47,7 +47,7 @@ class KGmap
QString getMapFile() const;
QString getName() const;
QString getDivisionsString() const;
QString getRandomDivision(division::askMode am) const;
division *getRandomDivision(division::askMode am) const;
QString getWhatIs(QRgb c, bool all) const;
QString getAuthor() const;
QColor getColor(const QString &s) const;
......
Markdown is supported
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