LibKEduVocDocument

keduvockvtml2reader.h
1/*
2 * read a KEduVocDocument from a KVTML2 file
3 * SPDX-FileCopyrightText: 2007 Jeremy Whiting <jpwhiting@kde.org>
4 * SPDX-FileCopyrightText: 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#ifndef KEDUVOCKVTML2READER_H
9#define KEDUVOCKVTML2READER_H
10
11#include <QDomDocument>
12#include <QMap>
13
14#include "keduvocarticle.h"
15#include "keduvocdocument.h"
16#include "keduvocexpression.h"
17#include "keduvocmultiplechoice.h"
18#include "keduvocpersonalpronoun.h"
19#include "readerbase.h"
20
21class QIODevice;
22class KEduVocDocument;
23class KEduVocWordType;
24
25/**
26 * @brief class to read kvtml2 data files into keduvocdocument
27 * @author Jeremy Whiting
28 */
30{
32public:
33 /** constructor */
34 explicit KEduVocKvtml2Reader(QIODevice &file);
35 /**destructor*/
37
38 /** @brief Can this reader parse this file
39 *
40 Read a small portion of the header of the file
41 and decide if it is a suitable type.
42 @return true if parsable
43 */
44 bool isParsable() Q_DECL_OVERRIDE;
45
46 /** @brief returns the KEduVocDocument::FileType that this reader handles
47 @return KEduVocDocument::FileType handled
48 */
49 KEduVocDocument::FileType fileTypeHandled() Q_DECL_OVERRIDE;
50
51 /** @brief Parse file and write into doc
52 @param doc to be written
53 @return error status of the read.*/
54 KEduVocDocument::ErrorCode read(KEduVocDocument &doc) Q_DECL_OVERRIDE;
55
56 /** an error message.
57 @return the error message
58 */
59 QString errorMessage() const Q_DECL_OVERRIDE
60 {
61 return m_errorMessage;
62 }
63
64private:
65 /** read information entries
66 * @param informationElement QDomElement information
67 */
68 bool readInformation(QDomElement &informationElement);
69
70 /** read group elements: identifiers, entries, types, usages, lessons */
71 bool readGroups(QDomElement &domElementParent);
72
73 /** read an identifier
74 * @param identifierElement QDomElement for the identifier to read
75 */
76 bool readIdentifier(QDomElement &identifierElement);
77
78 /** read an identifiers articles
79 * @param articleElement QDomElement for the article group
80 * @param identifierNum number of the identifier this article is inside of
81 */
82 bool readArticle(QDomElement &articleElement, int identifierNum);
83
84 bool readPersonalPronoun(QDomElement &conjugElement, KEduVocPersonalPronoun &pronoun);
85
86 bool readPersonalPronounChild(QDomElement &personElement, KEduVocPersonalPronoun &pronoun, KEduVocWordFlags flags);
87
88 /** read the types
89 * @param typesElement QDomElement for the types group
90 */
91 bool readWordType(KEduVocWordType *parentContainer, QDomElement &typesElement);
92
93 /**
94 * Read a leitner box container.
95 * This is a grading system where the vocabulary are kept in boxes and promoted/demoted during the learning.
96 * Be aware that leitner boxes are a list only and no sub boxes will ever be read or written.
97 * While reusing the lesson class is quite easy for this a proper subclass of KEduVocContainer would be the better solution.
98 * @param parentContainer the parent to append the new leitner container to
99 * @param leitnerElement the element in the dom
100 * @return success
101 */
102 bool readLeitner(KEduVocLeitnerBox *parentContainer, QDomElement &leitnerElement);
103
104 /**
105 * Read all <container> tags within a word type definition.
106 * @param parentContainer
107 * @param lessonElement
108 * @return
109 */
110 bool readChildWordTypes(KEduVocWordType *parentContainer, QDomElement &lessonElement);
111
112 /** read the tenses
113 * @param tensesElement QDomElement for the tenses group
114 */
115 QStringList readTenses(QDomElement &tensesElement);
116
117 /** read the usages
118 * @param usagesElement QDomElement for the usages group
119 */
120 bool readUsages(QDomElement &usagesElement);
121
122 /** read an entry
123 * @param entryElement QDomElement for the entry to read
124 */
125 bool readEntry(QDomElement &entryElement);
126
127 /** read a translation
128 * @param translationElement QDomElement for the translation to read
129 */
130 bool readTranslation(QDomElement &translationElement, KEduVocExpression *expr, int index);
131
132 /** read a comparison
133 * @param comparisonElement comparison group element
134 * @param comp comparison object to read into
135 */
136 bool readComparison(QDomElement &comparisonElement, KEduVocTranslation *translation);
137
138 /** read a multiple choice group
139 * @param multipleChoiceElement element to read from
140 * @param mc KEduVocMultipleChoice object to read to
141 */
142 bool readMultipleChoice(QDomElement &multipleChoiceElement, KEduVocTranslation *translation);
143
144 /**
145 * Read <lesson> tags.
146 * @param parentLesson
147 * @param lessonElement
148 * @return
149 */
150 bool readChildLessons(KEduVocLesson *parentLesson, QDomElement &lessonElement);
151
152 /** read a lesson, and append it to the document
153 * @param lessonElement element to read from
154 */
155 bool readLesson(KEduVocLesson *parentLesson, QDomElement &lessonElement);
156
157 bool readSynonymsAntonymsFalseFriends(QDomElement &rootElement);
158
159 /** pre-opened QIODevice to read from */
160 QIODevice *m_inputFile;
161
162 /** KEduVocDocument to read to */
163 KEduVocDocument *m_doc;
164
165 /** because we read the entries first, we store them here temporarily.
166 * later we read the lessons and put the entries there based on the key (their id) */
168
169 /** error message */
170 QString m_errorMessage;
171};
172
173#endif
The primary entry point to the hierarchy of objects describing vocabularies.
This class contains one vocabulary expression as an original with one or more translations.
class to read kvtml2 data files into keduvocdocument
bool isParsable() override
Can this reader parse this file.
KEduVocDocument::ErrorCode read(KEduVocDocument &doc) override
Parse file and write into doc.
~KEduVocKvtml2Reader() override
destructor
KEduVocDocument::FileType fileTypeHandled() override
returns the KEduVocDocument::FileType that this reader handles
QString errorMessage() const override
an error message.
KEduVocKvtml2Reader(QIODevice &file)
constructor
Leitner Boxes are an alternative grading system.
class to store information about a lesson
The conjugation of a verb.
class to store translation word types
a base class for readers of various lexicon formats
Definition readerbase.h:20
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:55:29 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.