KTextAddons

grammalecteparser.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "grammalecteparser.h"
8using namespace Qt::Literals::StringLiterals;
9
10#include "grammalectegrammarerror.h"
11#include "textgrammarcheck_debug.h"
12#include <QJsonArray>
13#include <QJsonValue>
14
15using namespace TextGrammarCheck;
16
17GrammalecteParser::GrammalecteParser() = default;
18
19GrammalecteParser::~GrammalecteParser() = default;
20
21QVector<GrammarError> GrammalecteParser::parseResult(const QJsonObject &obj) const
22{
24 if (!obj.contains("grammalecte"_L1)) {
25 qCWarning(TEXTGRAMMARCHECK_LOG) << "Error in json " << obj;
26 return infos;
27 }
28 const QJsonArray array = obj.value("data"_L1).toArray();
29 for (const QJsonValue &current : array) {
30 if (current.type() == QJsonValue::Object) {
31 // Check lGrammarErrors
32 const QJsonObject grammaObject = current.toObject();
33 const int blockId = grammaObject.value(QStringLiteral("iParagraph")).toInt();
34 // qDebug() << " blockId " << blockId;
35 const QJsonArray grammarErrorArray = grammaObject.value("lGrammarErrors"_L1).toArray();
36 for (const QJsonValue &error : grammarErrorArray) {
37 // qDebug() << " grammarErrorArray"<<error;
38 TextGrammarCheck::GrammalecteGrammarError info;
39 if (error.type() == QJsonValue::Object) {
40 info.parse(error.toObject(), blockId);
41 if (info.isValid()) {
42 infos.append(std::move(info));
43 }
44 } else {
45 qCWarning(TEXTGRAMMARCHECK_LOG) << "Problem when parsing grammalecte error" << error;
46 }
47 }
48 } else {
49 qCWarning(TEXTGRAMMARCHECK_LOG) << "Problem when parsing grammalecte result" << current;
50 }
51 }
52 return infos;
53}
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
bool contains(QLatin1StringView key) const const
QJsonValue value(QLatin1StringView key) const const
QJsonArray toArray() const const
int toInt(int defaultValue) const const
void append(QList< T > &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:48:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.