source: SMSSender/gateways/Schoolnet/src/ui/models/questionsortmodel.cpp @ 220:88f1d19f209a

Last change on this file since 220:88f1d19f209a was 220:88f1d19f209a, checked in by Sämy Zehnder <saemy.zehnder@…>, 7 years ago
  • Waiting for all tasks to finish at application close to ensure no one tries to do some sql stuff in a thread after the database is already closed.
  • Added ensureLoggedin() to IAccount.
  • Added missing config option "shared" to datatypes.pro
  • VersionedStorage? does not use a table for the version storage anymore but stores the version into the user_version pragma of sqlite.
  • Replaced SMAKE_VISIBLE by DATATYPES_SHARED_EXPORT.
  • Using haltIfCancelRequested() in STask now; this enables cancelling tasks.
  • Moved EAbortException into STask.
  • Added Info.plist which is used when deploying for mac.
  • Added -fvisibility=hidden flag for all projects.
  • Showing the minimum progress instead the mean progress if different task are running. This avoids progress jumps.

Schoolnet:

  • Moved status away from the question into a QuestionManager? where it is account dependent now (also affects db).
  • Added AnsweredAtSchoolnet? status for a question.
  • Improved schoolnet question list a lot.
File size: 1.8 KB
Line 
1#include "questionsortmodel.h"
2
3namespace Schoolnet {
4
5QuestionSortModel::QuestionSortModel(QuestionTreeModel *srcModel, QObject *parent)
6    : QSortFilterProxyModel(parent)
7{
8    setSourceModel(srcModel);
9
10    sortOrder_.insert(QuestionTreeModel::qsCanBeAnswered, 0);
11    sortOrder_.insert(QuestionTreeModel::qsLoading, 0);
12    sortOrder_.insert(QuestionTreeModel::qsAnsweredCorrect, 1);
13    sortOrder_.insert(QuestionTreeModel::qsAnsweredWrong, 2);
14    sortOrder_.insert(QuestionTreeModel::qsCanNotBeAnsweredAnymore, 3);
15}
16
17/**
18 * Sort the items so that the unanswered questions appear first.
19 */
20bool QuestionSortModel::lessThan(const QModelIndex& left, const QModelIndex& right) const {
21    QuestionTreeModel::TreeNode *leftN = sourceModel()->dataObject(left);
22    QuestionTreeModel::TreeNode *rightN = sourceModel()->dataObject(right);
23
24    Q_ASSERT((leftN->isQuestion() && rightN->isQuestion()) || (leftN->isAnswer() && rightN->isAnswer())); // Same type
25
26    if (leftN->isQuestion()) {
27        // Questions
28        Question leftQ = leftN->question();
29        Question rightQ = rightN->question();
30
31        QuestionTreeModel::QuestionStatus leftStatus = sourceModel()->questionStatus(leftQ);
32        QuestionTreeModel::QuestionStatus rightStatus = sourceModel()->questionStatus(rightQ);
33
34        if (sortOrder_[leftStatus] != sortOrder_[rightStatus]) {
35            return sortOrder_[leftStatus] < sortOrder_[rightStatus];
36        }
37
38        if (leftQ.language() != rightQ.language()) {
39            return leftQ.language() < rightQ.language();
40        }
41
42        return leftQ.text() < rightQ.text();
43    } else {
44        // Answers
45        return leftN->answer().id() < rightN->answer().id();
46    }
47}
48
49QuestionTreeModel * QuestionSortModel::sourceModel() const {
50    return static_cast<QuestionTreeModel *>(QSortFilterProxyModel::sourceModel());
51}
52
53}
Note: See TracBrowser for help on using the repository browser.