LibKEduVocDocument

keduvoccsvreader.cpp
1/*
2 * create a KEduVocDocument from a text file
3 * SPDX-FileCopyrightText: 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
4 * SPDX-FileCopyrightText: 2005, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#include "keduvoccsvreader.h"
9
10#include <KLocalizedString>
11#include <QIODevice>
12#include <QTextStream>
13
14#include "keduvocexpression.h"
15#include "keduvoclesson.h"
16
18{
19 // the file must be already open
20 m_inputFile = &file;
21
22 m_errorMessage = QLatin1String("");
23}
24
29
31{
32 m_doc = &doc;
33
34 QString separator = m_doc->csvDelimiter();
35
36 QTextStream inputStream(m_inputFile);
37 inputStream.setAutoDetectUnicode(true);
38 inputStream.seek(0);
39
40 int languageCount = 0;
41
42 KEduVocLesson *lesson = new KEduVocLesson(i18n("Vocabulary"), m_doc->lesson());
43 m_doc->lesson()->appendChildContainer(lesson);
44
45 while (!inputStream.atEnd()) {
46 QString s = inputStream.readLine();
47
48 if (!s.simplified().isEmpty()) {
49 KEduVocExpression *expression = new KEduVocExpression(s.split(separator));
50 languageCount = qMax(languageCount, expression->translationIndices().count());
51 lesson->appendEntry(expression);
52 }
53 }
54
55 for (int j = 0; j < languageCount; j++) {
56 m_doc->appendIdentifier();
57 }
58
60}
KEduVocDocument::FileType fileTypeHandled() override
returns the KEduVocDocument::FileType that this reader handles
KEduVocDocument::ErrorCode read(KEduVocDocument &doc) override
Parse file and write into doc.
KEduVocCsvReader(QIODevice &dev)
constructor
The primary entry point to the hierarchy of objects describing vocabularies.
int appendIdentifier(const KEduVocIdentifier &identifier=KEduVocIdentifier())
Appends a new identifier (usually a language)
KEduVocLesson * lesson()
Get the lesson root object.
ErrorCode
the return code when opening/saving
QString csvDelimiter() const
Returns the delimiter (separator) used for csv import and export.
FileType
known vocabulary file types
@ Csv
Command separated values.
This class contains one vocabulary expression as an original with one or more translations.
class to store information about a lesson
void appendEntry(KEduVocExpression *entry)
append an entry to the lesson
QString i18n(const char *text, const TYPE &arg...)
qsizetype count() const const
bool isEmpty() const const
QString simplified() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool atEnd() const const
QString readLine(qint64 maxlen)
bool seek(qint64 pos)
void setAutoDetectUnicode(bool enabled)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.