Open-Typer
Open source typewriting tutor program
Loading...
Searching...
No Matches
PackEditorModel.h
1/*
2 * PackEditorModel.h
3 * This file is part of Open-Typer
4 *
5 * Copyright (C) 2023 - adazem009
6 *
7 * Open-Typer is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * Open-Typer is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Open-Typer. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef PACKEDITORMODEL_H
22#define PACKEDITORMODEL_H
23
24#include <QObject>
25#include "lessonpack/IConfigParser.h"
26#include "translations/ILanguageManager.h"
27
28class PackEditorModel : public QObject
29{
30 Q_OBJECT
31 INJECT(IConfigParser, configParser)
32 INJECT(ILanguageManager, languageManager)
33 Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
34 Q_PROPERTY(bool opened READ opened NOTIFY openedChanged)
35 Q_PROPERTY(bool saved READ saved NOTIFY savedChanged)
36 Q_PROPERTY(bool readOnly READ readOnly NOTIFY readOnlyChanged)
37 Q_PROPERTY(int lesson READ lesson WRITE setLesson NOTIFY lessonChanged)
38 Q_PROPERTY(int sublesson READ sublesson WRITE setSublesson NOTIFY sublessonChanged)
39 Q_PROPERTY(int exercise READ exercise WRITE setExercise NOTIFY exerciseChanged)
40 Q_PROPERTY(QStringList lessonList READ lessonList NOTIFY lessonListChanged)
41 Q_PROPERTY(QStringList sublessonList READ sublessonList NOTIFY sublessonListChanged)
42 Q_PROPERTY(QStringList exerciseList READ exerciseList NOTIFY exerciseListChanged)
43 Q_PROPERTY(QString currentText READ currentText NOTIFY currentTextChanged)
44 Q_PROPERTY(QString currentRawText READ currentRawText WRITE setCurrentRawText NOTIFY currentRawTextChanged)
45 Q_PROPERTY(QString currentRepeatType READ currentRepeatType WRITE setCurrentRepeatType NOTIFY currentRepeatTypeChanged)
46 Q_PROPERTY(int currentLengthLimit READ currentLengthLimit WRITE setCurrentLengthLimit NOTIFY currentLengthLimitChanged)
47 Q_PROPERTY(int currentLineLength READ currentLineLength WRITE setCurrentLineLength NOTIFY currentLineLengthChanged)
48 Q_PROPERTY(QString currentLessonDescription READ currentLessonDescription WRITE setCurrentLessonDescription NOTIFY currentLessonDescriptionChanged)
49 Q_PROPERTY(QList<int> unusedSublessons READ unusedSublessons NOTIFY unusedSublessonsChanged)
50 Q_PROPERTY(bool canRemove READ canRemove NOTIFY canRemoveChanged)
51 public:
52 explicit PackEditorModel(QObject *parent = nullptr);
54
55 const QString &fileName() const;
56 void setFileName(const QString &newFileName);
57
58 bool opened() const;
59
60 bool saved() const;
61
62 bool readOnly() const;
63
64 int lesson() const;
65 void setLesson(int newLesson);
66
67 int sublesson() const;
68 void setSublesson(int newSublesson);
69
70 int exercise() const;
71 void setExercise(int newExercise);
72
73 const QStringList &lessonList() const;
74
75 const QStringList &sublessonList() const;
76
77 const QStringList &exerciseList() const;
78
79 QString currentText() const;
80
81 QString currentRawText() const;
82 void setCurrentRawText(const QString &newRawText);
83
84 QString currentRepeatType() const;
85 void setCurrentRepeatType(const QString &newRepeatType);
86
87 int currentLengthLimit() const;
88 void setCurrentLengthLimit(int newLengthLimit);
89
90 int currentLineLength() const;
91 void setCurrentLineLength(int newLineLength);
92
93 QString currentLessonDescription() const;
94 void setCurrentLessonDescription(const QString &newLessonDescription);
95
96 QList<int> unusedSublessons() const;
97
98 bool canRemove() const;
99
100 Q_INVOKABLE void newFile();
101 Q_INVOKABLE void open();
102 Q_INVOKABLE bool save();
103 Q_INVOKABLE bool saveAs(const QString &fileName);
104
105 Q_INVOKABLE void nextExercise();
106 Q_INVOKABLE void previousExercise();
107
108 Q_INVOKABLE QString sublessonName(int id);
109
110 Q_INVOKABLE void addLesson();
111 Q_INVOKABLE void addSublesson(int id);
112 Q_INVOKABLE void addExercise();
113
114 Q_INVOKABLE void removeCurrentExercise();
115
116 private:
117 void init();
118 void nextSublesson();
119 void previousSublesson();
120 void nextLesson(bool updateExList = true);
121 void previousLesson(bool updateExList = true);
122 void updateLists();
123 void updateLessonList();
124 void updateSublessonList();
125 void updateExerciseList();
126 void updateAbsoluteSublesson();
127 void setAbsoluteSublesson(int absoluteSublesson);
128 void deleteExerciseLine(int lesson, int sublesson, int exercise);
129 void editExercise(bool repeat, const QString &repeatType, int repeatLimit, int lineLength, const QString &desc, const QString &rawText);
130 void moveExercise(int lesson, int sublesson, int exercise, int newLesson, int newSublesson, int newExercise);
131 void moveLesson(int lesson, int newLesson);
132
133 std::shared_ptr<IConfigParser> m_parser = nullptr;
134 QString m_fileName;
135 bool m_opened = false;
136 bool m_saved = false;
137 bool m_readOnly = false;
138 int m_lesson = 0;
139 int m_sublesson = 0;
140 int m_absoluteSublesson = 0;
141 int m_exercise = 0;
142 QStringList m_lessonList;
143 QStringList m_sublessonList;
144 QStringList m_exerciseList;
145
146 signals:
147 void openedChanged();
148 void fileNameChanged();
149 void savedChanged();
150 void readOnlyChanged();
151 void lessonChanged();
152 void sublessonChanged();
153 void exerciseChanged();
154 void lessonListChanged();
155 void sublessonListChanged();
156 void exerciseListChanged();
157 void currentTextChanged();
158 void currentRawTextChanged();
159 void currentRepeatTypeChanged();
160 void currentLengthLimitChanged();
161 void currentLineLengthChanged();
162 void currentLessonDescriptionChanged();
163 void unusedSublessonsChanged();
164 void canRemoveChanged();
165};
166
167#endif // PACKEDITORMODEL_H
Definition IConfigParser.h:27
Definition ILanguageManager.h:28
Definition PackEditorModel.h:29