X-Git-Url: http://git.maemo.org/git/?p=impuzzle;a=blobdiff_plain;f=src%2Fstatistics.cpp;h=c979da0bb64f07e96e4b931f37eb5f28ecd171c9;hp=eb5043e7ef76eb7bfe43419ee309caa904af9891;hb=197445a53351096fc3d487eccfaaaa2fda10abc1;hpb=58ec0e286982cd15beff65303797420c2f913fcb diff --git a/src/statistics.cpp b/src/statistics.cpp index eb5043e..c979da0 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -6,6 +6,8 @@ #include #include +#include + Statistics *Statistics::instance_ = 0; Statistics::Statistics(QObject *parent) : @@ -47,7 +49,7 @@ qreal Statistics::averageMoves(Difficulty difficulty) const { qreal count = 0.0; if(games_.at(difficulty) > 0) { - count = moves_.at(difficulty) / static_cast(games_.at(difficulty)); + count = (moves_.at(difficulty) / games_.at(difficulty)); } return count; @@ -66,7 +68,7 @@ int Statistics::maxMoves(Difficulty difficulty) const void Statistics::addNewScore(int moves, Difficulty difficulty) { if(moves_.count() >= difficulty) { - moves_[difficulty] += (moves_[difficulty] + moves); + moves_[difficulty] += moves; } if(maxMoves_.count() >= difficulty) { @@ -99,6 +101,7 @@ void Statistics::readFile() .arg(STATS_FILE)); if(!file.exists()) { + qDebug() << __PRETTY_FUNCTION__ << "No settings file"; return; } @@ -126,6 +129,15 @@ void Statistics::readFile() void Statistics::saveFile() { + QDir dir(QString("%1/%2") + .arg(QDir::homePath()) + .arg(HOME_DIRECTORY)); + if(!dir.exists()) { + dir.mkpath(QString("%1/%2") + .arg(QDir::homePath()) + .arg(HOME_DIRECTORY)); + } + QFile file(QString("%1/%2/%3") .arg(QDir::homePath()) .arg(HOME_DIRECTORY) @@ -148,3 +160,18 @@ void Statistics::saveFile() file.close(); } + +void Statistics::resetStatistics() +{ + moves_.clear(); + minMoves_.clear(); + maxMoves_.clear(); + games_.clear(); + + moves_ << 0 << 0; + minMoves_ << 0 << 0; + maxMoves_ << 0 << 0; + games_ << 0 << 0; + + saveFile(); +}