| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2013-2016 Andreas Cord-Landwehr <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef STORAGE_H |
| 8 |
#define STORAGE_H |
| 9 |
|
| 10 |
#include <QObject> |
| 11 |
|
| 12 |
class QSqlError; |
| 13 |
class QSqlDatabase; |
| 14 |
|
| 15 |
namespace LearnerProfile |
| 16 |
{ |
| 17 |
class Learner; |
| 18 |
class LearningGoal; |
| 19 |
|
| 20 |
/** |
| 21 |
* \class Storage |
| 22 |
* Database storage for learner information database. |
| 23 |
*/ |
| 24 |
class Storage : public QObject |
| 25 |
{ |
| 26 |
Q_OBJECT |
| 27 |
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) |
| 28 |
|
| 29 |
public: |
| 30 |
/** |
| 31 |
* Default constructor, which sets a default database path at |
| 32 |
* DataLocation + learnerdata.db |
| 33 |
*/ |
| 34 |
explicit Storage(QObject *parent = nullptr); |
| 35 |
/** |
| 36 |
* \note this constructor is tailored for unit tests |
| 37 |
*/ |
| 38 |
explicit Storage(const QString &databasePath, QObject *parent = nullptr); |
| 39 |
QString errorMessage() const; |
| 40 |
|
| 41 |
/** |
| 42 |
* Store profile in database. This can either be a new or an existing profile. |
| 43 |
* If it is an existing profile, the corresponding values are updated. |
| 44 |
*/ |
| 45 |
bool storeProfile(Learner *learner); |
| 46 |
bool removeProfile(Learner *learner); |
| 47 |
bool removeRelation(Learner *learner, LearningGoal *goal); |
| 48 |
QList<Learner *> loadProfiles(QList<LearnerProfile::LearningGoal *> goals); |
| 49 |
bool storeGoal(LearningGoal *goal); |
| 50 |
QList<LearningGoal *> loadGoals(); |
| 51 |
bool storeProgressLog(Learner *learner, LearningGoal *goal, const QString &container, const QString &item, int payload, const QDateTime &time); |
| 52 |
/** |
| 53 |
* Load list of progress values for specified item |
| 54 |
* \return list of date/payload values for this item |
| 55 |
*/ |
| 56 |
QList<QPair<QDateTime, int>> readProgressLog(Learner *learner, LearningGoal *goal, const QString &container, const QString &item); |
| 57 |
bool storeProgressValue(Learner *learner, LearningGoal *goal, const QString &container, const QString &item, int payload); |
| 58 |
/** |
| 59 |
* Load list of progress values for specified container |
| 60 |
* \return list of item/payload values for all items in container |
| 61 |
*/ |
| 62 |
QHash<QString, int> readProgressValues(Learner *learner, LearningGoal *goal, const QString &container); |
| 63 |
/** |
| 64 |
* Load payload value of specified item. If no value is found, \return -1 |
| 65 |
*/ |
| 66 |
int readProgressValue(Learner *learner, LearningGoal *goal, const QString &container, const QString &item); |
| 67 |
|
| 68 |
Q_SIGNALS: |
| 69 |
void errorMessageChanged(); |
| 70 |
|
| 71 |
protected: |
| 72 |
QSqlDatabase database(); |
| 73 |
void raiseError(const QSqlError &error); |
| 74 |
|
| 75 |
private: |
| 76 |
bool updateSchema(); |
| 77 |
const QString m_databasePath; |
| 78 |
QString m_errorMessage; |
| 79 |
}; |
| 80 |
} |
| 81 |
|
| 82 |
#endif // STORAGE_H |