-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataBase.h
115 lines (95 loc) · 3.07 KB
/
DataBase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Foreign Language Trainer is a program to study foreign languages through
* various exercises.
*
* Copyright (C) 2019 Sergey Kovalev
* https://github.com/skvl/flt
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DATABASE_H
#define DATABASE_H
#include <QDateTime>
#include <QFile>
#include <QObject>
#include <QTime>
#include <QTimer>
#include "Sentence.h"
class DataBase : public QObject
{
Q_OBJECT
Q_PROPERTY(int elapsed READ elapsed NOTIFY elapsedChanged)
Q_PROPERTY(QDateTime date READ date NOTIFY dateChanged)
Q_PROPERTY(QVariant data READ data NOTIFY dataChanged)
Q_PROPERTY(QString audio READ audio NOTIFY audioChanged)
Q_PROPERTY(QString wordFont READ wordFont CONSTANT)
Q_PROPERTY(QString translation READ translation NOTIFY translationChanged)
Q_PROPERTY(bool first READ first NOTIFY firstChanged)
Q_PROPERTY(bool last READ last NOTIFY lastChanged)
public:
DataBase(QString path = QString(), QObject *parent = nullptr);
~DataBase();
// Open DataBase.
void open();
// Get fonts
QString wordFont() const;
// Get current sentence
QString audio();
QVariant data();
QString translation();
bool first();
bool last();
// Get next sentece
Q_INVOKABLE void next();
// Get next sentece
Q_INVOKABLE void previous();
// Re-order sentences and start from begin
Q_INVOKABLE void flush();
// TODO Use Q_PROPERTY
// Get total number of sentences
Q_INVOKABLE int count() const;
// Get number of wrong sentences
Q_INVOKABLE int correctCount() const;
// Get list of wrong sentences
Q_INVOKABLE QVariantList allWrong();
// Time management
Q_INVOKABLE void timerStart();
Q_INVOKABLE void timerStop();
// Date and time of exercise start
QDateTime date() const;
// How much time elapsed from exercise start
int elapsed() const;
static Q_INVOKABLE QString elapsedToString(int elapsed);
signals:
void elapsedChanged();
void dateChanged();
void dataChanged();
void audioChanged();
void translationChanged();
void firstChanged();
void lastChanged();
private slots:
void tick();
private:
bool m_opened;
QFile* m_file;
QVector<Sentence*> m_data;
QVector<Sentence*>::iterator m_iterator;
QVector<Sentence*>::iterator m_wrong;
QString m_wordFont;
QDateTime m_date;
QTime m_time;
// TODO Use QObject timer instead
QTimer m_timer;
int m_elapsed;
Sentence* take();
};
#endif // DATABASE_H