KTextAddons

grammalectegrammarerror.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 "grammalectegrammarerror.h"
8using namespace Qt::Literals::StringLiterals;
9
10#include "textgrammarcheck_debug.h"
11
12#include <QJsonArray>
13
14using namespace TextGrammarCheck;
15
16GrammalecteGrammarError::GrammalecteGrammarError() = default;
17
18GrammalecteGrammarError::~GrammalecteGrammarError() = default;
19
20QStringList GrammalecteGrammarError::parseSuggestion(const QJsonObject &obj)
21{
22 QStringList lst;
23 const QJsonArray array = obj["aSuggestions"_L1].toArray();
24 const QVariantList list = array.toVariantList();
25 lst.reserve(list.count());
26 for (const QVariant &v : list) {
27 // qDebug() << " v" << v.toString();
28 lst.append(v.toString());
29 }
30 return lst;
31}
32
33QColor GrammalecteGrammarError::parseColor(const QJsonObject &obj)
34{
35 QColor col;
36 const QJsonArray array = obj["aColor"_L1].toArray();
37 if (array.isEmpty()) {
38 return col;
39 }
40 if (array.count() == 3) {
41 // const QVariantList list = array.toVariantList();
42 // for (const QVariant &v : list) {
43 // qDebug() << " v" << v.toInt();
44 // }
45 col = QColor(array.at(0).toInt(), array.at(1).toInt(), array.at(2).toInt());
46 } else {
47 qCWarning(TEXTGRAMMARCHECK_LOG) << "Parsing color: Array is not correct:" << array;
48 }
49 return col;
50}
51
52void GrammalecteGrammarError::parse(const QJsonObject &obj, int blockindex)
53{
54 const int end = obj["nEnd"_L1].toInt(-1);
55 mStart = obj["nStart"_L1].toInt(-1);
56 if (end != -1) {
57 mLength = end - mStart;
58 }
59 mError = obj["sMessage"_L1].toString();
60 if (mLength != -1) {
61 mBlockId = blockindex;
62 mColor = parseColor(obj);
63 mSuggestions = parseSuggestion(obj);
64 }
65 mRule = obj["sRuleId"_L1].toString();
66 mOption = obj["sType"_L1].toString();
67 mUrl = obj["URL"_L1].toString();
68}
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QJsonValue at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
QVariantList toVariantList() const const
int toInt(int defaultValue) const const
void append(QList< T > &&value)
qsizetype count() const const
void reserve(qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.