Open-Typer
Open source typewriting tutor program
|
The ConfigParser class provides functions for the pack file format. More...
#include "framework/lessonpack/internal/ConfigParser.h"
Public Member Functions | |
ConfigParser (QObject *parent=nullptr) | |
std::shared_ptr< IConfigParser > | createInstance () const override |
Q_INVOKABLE bool | open (const QString fileName) override |
Q_INVOKABLE void | loadToBuffer (const QByteArray content) override |
Q_INVOKABLE QByteArray | data (void) override |
Q_INVOKABLE bool | bufferOpened (void) override |
Q_INVOKABLE void | close (void) override |
QString | fileName (void) override |
Q_INVOKABLE int | lessonCount (void) override |
Q_INVOKABLE int | sublessonCount (int lesson) override |
Q_INVOKABLE int | exerciseCount (int lesson, int sublesson) override |
Q_INVOKABLE int | exerciseLine (int lesson, int sublesson, int exercise) override |
Q_INVOKABLE bool | exerciseRepeatBool (int lesson, int sublesson, int exercise) override |
Q_INVOKABLE QString | exerciseRepeatType (int lesson, int sublesson, int exercise) override |
Q_INVOKABLE int | exerciseRepeatLimit (int lesson, int sublesson, int exercise) override |
Q_INVOKABLE int | exerciseLineLength (int lesson, int sublesson, int exercise) override |
Q_INVOKABLE QString | lessonDesc (int lesson) override |
Q_INVOKABLE QString | parseDesc (QString desc) override |
Q_INVOKABLE QString | sublessonName (int id) override |
Q_INVOKABLE QString | lessonTr (int id) override |
Q_INVOKABLE QString | sublessonTr (int id) override |
Q_INVOKABLE QString | exerciseTr (int id) override |
Q_INVOKABLE QString | exerciseRawText (int lesson, int sublesson, int exercise) override |
Q_INVOKABLE QString | exerciseText (int lesson, int sublesson, int exercise) override |
Q_INVOKABLE QString | initExercise (QString exercise, int lineLength) override |
Q_INVOKABLE QString | initExercise (QString exercise, int lineLength, bool lineCountLimit, int currentLine) override |
Q_INVOKABLE QString | initText (QString rawText) override |
Q_INVOKABLE bool | addExercise (int lesson, int sublesson, int exercise, bool repeat, QString repeatType, int repeatLimit, int lineLength, QString desc, QString rawText) override |
Q_INVOKABLE int | defaultRepeatLimit (void) override |
Q_INVOKABLE int | defaultLineLength (void) override |
Q_INVOKABLE void | setCurrentLesson (int value) override |
Q_INVOKABLE int | currentLesson (void) override |
Q_INVOKABLE void | setCurrentSublesson (int value) override |
Q_INVOKABLE int | currentSublesson (void) override |
Q_INVOKABLE void | setCurrentExercise (int value) override |
Q_INVOKABLE int | currentExercise (void) override |
Static Public Member Functions | |
static std::shared_ptr< ConfigParser > | instance () |
Private Member Functions | |
bool | reopen (QIODevice::OpenMode mode) |
int | exerciseID (const QString line, const int part) |
QString | lineOf (int lesson, int sublesson, int exercise) |
bool | exerciseRepeatBool (const QString config) |
QString | exerciseRepeatType (const QString config) |
QString | exerciseRepeatConfig (const QString line) |
QString | exerciseAttribute (const QString config, const int id) |
QString | exerciseAttributes (const QString line) |
QString | exerciseRawText (const QString line) |
Static Private Member Functions | |
static QString | generateText (QString rawText, bool repeat, QString repeatType, int repeatLimit) |
Private Attributes | |
QFile | configFile |
QBuffer | configBuffer |
QIODevice * | currentDevice |
Static Private Attributes | |
static std::shared_ptr< ConfigParser > | m_instance = std::make_shared<ConfigParser>() |
static const int | m_defaultRepeatLimit = 128 |
static const int | m_defaultLineLength = 100 |
The ConfigParser class provides functions for the pack file format.
Example usage:
|
explicit |
Constructs ConfigParser.
|
overridevirtual |
Adds an exercise to the opened pack file.
[in] | lesson | Lesson ID. |
[in] | sublesson | Sublesson ID. |
[in] | exercise | Exercise ID. |
[in] | repeat | Whether to enable repeating. |
[in] | repeatType | Repeat type string. |
[in] | repeatLimit | Maximum number of characters (if repeating is enabled). |
[in] | lineLength | Maximum number of characters in one line. |
[in] | desc | Lesson description. Should be used only in the first exercise of the lesson. |
[in] | rawText | Exercise raw text. |
Implements IConfigParser.
|
overridevirtual |
Returns true if there's a buffer opened.
Implements IConfigParser.
|
overridevirtual |
Closes the opened pack file or buffer.
Implements IConfigParser.
|
overridevirtual |
Creates a new instance of ConfigParser. This is useful if you need more than one instance of ConfigParser.
Implements IConfigParser.
|
overridevirtual |
Returns selected exercise.
Implements IConfigParser.
|
overridevirtual |
Returns selected lesson.
Implements IConfigParser.
|
overridevirtual |
Returns selected sublesson.
Implements IConfigParser.
|
overridevirtual |
Returns current data in the opened file or buffer.
Implements IConfigParser.
|
overridevirtual |
Returns default line length.
Implements IConfigParser.
|
overridevirtual |
Returns default repeat limit (text length).
Implements IConfigParser.
|
private |
Gets a specific exercise attribute from a config string.
|
private |
Gets a config string from a line.
|
overridevirtual |
Returns the number of exercises in a sublesson.
Implements IConfigParser.
|
private |
Returns a part of the exercise ID (from a line).
Part 1 - lesson ID
Part 2 - sublesson ID
Part 3 - exercise ID
|
overridevirtual |
Returns the line the exercise is located in the pack file or buffer.
Implements IConfigParser.
|
overridevirtual |
Returns the exercise's maximum number of characters in one line.
Implements IConfigParser.
|
private |
Implementation of exerciseRawText() for a line.
|
overridevirtual |
Returns raw text of the exercise (no repeating or line wrapping).
Implements IConfigParser.
|
private |
Implementation of exerciseRepeatBool() for a config string.
|
overridevirtual |
Returns true if repeating is enabled in the exercise.
Implements IConfigParser.
|
private |
Gets config string from a line.
|
overridevirtual |
Returns the maximum number of characters of the exercise (if repeating is enabled).
Implements IConfigParser.
|
private |
Implementation of exerciseRepeatType() for a config string.
|
overridevirtual |
Returns repeat configuration of the exercise.
Implements IConfigParser.
|
overridevirtual |
Returns exercise text (with repeating and without line wrapping).
Implements IConfigParser.
|
overridevirtual |
Returns translated "Exercise (id)" string.
Implements IConfigParser.
|
overridevirtual |
Returns the file name of the opened pack file.
Implements IConfigParser.
|
staticprivate |
Adds repeating to a raw text.
|
overridevirtual |
Adds line wrapping to exercise text.
Implements IConfigParser.
|
overridevirtual |
Adds line wrapping to exercise text and (optionally) limits number of lines.
[in] | lineCountLimit | Whether to limit number of lines. |
[in] | currentLine | The line the shortened text starts at. Note that lines start by 0 in this function. |
Implements IConfigParser.
|
overridevirtual |
Generates text without line wrapping nor repeating.
Implements IConfigParser.
|
static |
Returns the static instance of ConfigParser.
|
overridevirtual |
Returns the number of lessons in the pack file or buffer.
Implements IConfigParser.
|
overridevirtual |
Returns the description of a lesson (what new characters are learned in it).
Implements IConfigParser.
|
overridevirtual |
Returns translated "Lesson (id)" string.
Implements IConfigParser.
|
private |
Returns line string of the exercise.
|
overridevirtual |
Closes opened file and loads pack content to the buffer.
Implements IConfigParser.
|
overridevirtual |
|
overridevirtual |
Converts a lesson description into a human-readable description.
For example:
dfjk
-> {dfjk}
%r
-> Revision
%s
-> Shift
sl%be
-> {sl}{e}
Implements IConfigParser.
|
private |
ConfigParser provides read and write support. The pack file or buffer is opened for reading by default, so it must be reopened for writing while performing write operations.
This function reopens the opened file or buffer in a new mode.
Returns true if successful.
[in] | mode | Open mode, like in the QIODevice::open() function. |
|
overridevirtual |
Sets selected exercise (should only be used in QML).
Implements IConfigParser.
|
overridevirtual |
Sets selected lesson (should only be used in QML).
Implements IConfigParser.
|
overridevirtual |
Sets selected sublesson (should only be used in QML).
Implements IConfigParser.
|
overridevirtual |
Returns the number of sublessons in a lesson.
Note: Empty sublessons are allowed and will not be counted by this function. The exerciseCount() function can be used to detect an empty sublesson.
Implements IConfigParser.
|
overridevirtual |
Returns the name of a sublesson.
For example:
1 -> Touch
Implements IConfigParser.
|
overridevirtual |
Returns translated "Sublesson (id)" string.
Implements IConfigParser.