diff options
author | Arno <arno@disconnect.de> | 2016-03-20 04:22:35 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2016-03-20 04:22:35 +0100 |
commit | 2844e586208fed423cbb81f269add2370231b780 (patch) | |
tree | 6ad665fa72ea3624a88190f7a71b80fd21582e5d /picfilesmodel.cpp | |
parent | 437b9246b38740fca30768e80baecfc91a4eb438 (diff) | |
download | SheMov-2844e586208fed423cbb81f269add2370231b780.tar.gz SheMov-2844e586208fed423cbb81f269add2370231b780.tar.bz2 SheMov-2844e586208fed423cbb81f269add2370231b780.zip |
Let std::shuffle do the randomization
Seems to be more random.
Also, this commit introduces c++11, yay!
Diffstat (limited to 'picfilesmodel.cpp')
-rw-r--r-- | picfilesmodel.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/picfilesmodel.cpp b/picfilesmodel.cpp index ec1b82d..482af09 100644 --- a/picfilesmodel.cpp +++ b/picfilesmodel.cpp @@ -10,11 +10,16 @@ #include <QFile> #include <QLocale> +#include <algorithm> +#include <random> +#include <chrono> + #include "picfilesmodel.h" #include "smglobals.h" #include "smtreeitem.h" #include "helper.h" + PicFilesModel::PicFilesModel(const QStringList &headers, QObject *parent) : SmTreeModel(headers, parent) { //conjure up model mMappingTreeModel = static_cast<MappingTreeModel*>(SmGlobals::instance()->model("MappingTree")); @@ -299,24 +304,28 @@ QList<int> PicFilesModel::mappingPIdsFromFiles(QList<int> fileIds) const{ void PicFilesModel::allPicIds(){ mAllPics.clear(); mCurrentBatch = 0; - QSqlQuery q("SELECT tfilename, cmd5sum, ipicsid FROM pics ORDER BY random()", mDb); + QSqlQuery q("SELECT tfilename, cmd5sum, ipicsid FROM pics", mDb); while(q.next()){ QList<QVariant> cur; cur << q.value(0) << q.value(1) << q.value(2); mAllPics << cur; } + unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); + std::shuffle(mAllPics.begin(), mAllPics.end(), std::default_random_engine(seed)); mCurrentPics = &mAllPics; } void PicFilesModel::recentPicIds(){ mRecentPics.clear(); mCurrentBatch = 0; - QSqlQuery q("SELECT tfilename, cmd5sum, ipicsid FROM pics WHERE dtadded > now() - interval '6 months' ORDER BY random()", mDb); + QSqlQuery q("SELECT tfilename, cmd5sum, ipicsid FROM pics WHERE dtadded > now() - interval '6 months'", mDb); while(q.next()){ QList<QVariant> cur; cur << q.value(0) << q.value(1) << q.value(2); mRecentPics << cur; } + unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); + std::shuffle(mRecentPics.begin(), mRecentPics.end(), std::default_random_engine(seed)); mCurrentPics = &mRecentPics; } |