source: SMSSender/gateways/Schoolnet/gui/ui/models/questiontreemodel.h @ 319:1ec456878bcb

separation-frontend-backend
Last change on this file since 319:1ec456878bcb was 319:1ec456878bcb, checked in by Sämy Zehnder <saemy.zehnder@…>, 8 years ago
  • Adjusts header guards to follow common pattern based on the filename.
File size: 4.6 KB
Line 
1/*
2 Schoolnet gateway plugin - The smssender plugin for the Schoolnet sms platform.
3 Copyright (C) 2010-2014, gorrión. See http://smssender.gorrion.ch
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifndef SCHOOLNET_GUI_UI_MODELS_QUESTIONTREEMODEL_H
19#define SCHOOLNET_GUI_UI_MODELS_QUESTIONTREEMODEL_H
20
21#include <QMap>
22#include <QAbstractItemModel>
23
24#include "common/business/iintegration.h"
25#include "gateways/Schoolnet/business/deepthought/datatypes.h"
26
27class IAccount;
28class STask;
29
30namespace Schoolnet {
31class Account;
32class Gateway;
33
34namespace DeepThought {
35class DeepThoughtHelper;
36class QuestionManager;
37
38namespace UI {
39
40class QuestionTreeModel: public QAbstractItemModel {
41    Q_OBJECT
42
43public:
44    class TreeNode {
45    public:
46        explicit TreeNode(Question *question);
47        explicit TreeNode(Answer *answer);
48        TreeNode(const TreeNode& other);
49
50    public:
51        Question *question() const;
52        Answer *answer() const;
53
54        bool isQuestion() const;
55        bool isAnswer() const;
56    private:
57        Question *m_question;
58        Answer *m_answer;
59    };
60
61public:
62    QuestionTreeModel(const IAccountIntegrationHelper *accountHelper, DeepThoughtHelper *deepThoughtHelper);
63
64    enum QuestionColumns {
65        ColQuestionText = 0,
66        ColStatus       = 1,
67
68        MaxQuestionCol = ColStatus
69    };
70
71    enum AnswerColumns {
72        ColAnswerText = 0,
73
74        MaxAnswerCol = ColAnswerText
75    };
76
77    QVariant      data(const QModelIndex& index, int role = Qt::DisplayRole) const;
78    TreeNode *    dataObject(const QModelIndex& index) const;
79    int           columnCount(const QModelIndex& parent = QModelIndex()) const;
80    int           rowCount(const QModelIndex& parent = QModelIndex()) const;
81    Qt::ItemFlags flags(const QModelIndex& index) const;
82    bool          setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
83    QModelIndex   index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
84    QModelIndex   parent(const QModelIndex& index = QModelIndex()) const;
85
86public:
87    enum QuestionStatus {
88        qsCanBeAnswered,          // No answer provided and question is open at some schoolnet account
89        qsLoading,                // An answer has been provided by the user, but correctness check not "through"
90        qsAnsweredWrong,          // This question has a wrong answer and is not open at any schoolnet account
91        qsAnsweredCorrect,        // This question has a correct answer
92        qsCanNotBeAnsweredAnymore // This question has no wrong answer but is not open at any schoolnet account
93    };
94    enum AnswerStatus {
95        asCanBeAnswered,          // unanswered an question open at some logged-in account
96        asLoading,                // this answer has been provided by the user, but correctness check not "through"
97        asAnsweredWrong,          // this answer is wrong
98        asAnsweredCorrect,        // this answer is correct
99        asCanNotBeAnsweredAnymore // this question has already been answered (another answer) and is not open at another logged-in account -> cannot give any answer anymore
100    };
101
102public:
103    QuestionStatus questionStatus(const Question &question) const;
104    AnswerStatus answerStatus(const Answer &answer) const;
105
106    bool isQuestionStatusAtSchoolnetCheckedAtSomeLoggedInAccount(const Question &question) const;
107    bool isQuestionUnansweredAtSomeLoggedInAccount(const Question &question) const;
108    QSet<Account *> getLoggedInSchoolnetAccounts() const;
109    Account *getAccountWhereUnanswered(const Question &question);
110
111private slots:
112    void reloadList();
113
114    void onAnswerProvidingTaskFinished(STask *task);
115    void onAccountInitStateChanged(IAccount *account);
116
117private:
118    const IAccountIntegrationHelper * const m_accountHelper;
119    DeepThoughtHelper * const m_deepThoughtHelper;
120
121    QList<Question*> items_;
122    bool hasLoggedInAccounts_;
123    QMap<STask*, const Answer*> loadingAnswers_;
124};
125
126} // namespace UI
127} // namespace DeepThought
128} // namespace Schoolnet
129
130#endif // SCHOOLNET_GUI_UI_MODELS_QUESTIONTREEMODEL_H
Note: See TracBrowser for help on using the repository browser.