Commit 96f1cac3 authored by Laurent Montel's avatar Laurent Montel 😁

Parse color and suggestion

parent bd9ebf77
......@@ -18,7 +18,9 @@
*/
#include "grammalectegrammarerror.h"
#include "grammalecteplugin_debug.h"
#include <QJsonArray>
#include <QJsonObject>
GrammalecteGrammarError::GrammalecteGrammarError()
......@@ -105,17 +107,37 @@ void GrammalecteGrammarError::parse(const QJsonObject &obj, int blockindex)
mEnd = obj[QStringLiteral("nEnd")].toInt();
mBegin = obj[QStringLiteral("nStart")].toInt();
mError = obj[QStringLiteral("sMessage")].toString();
mColor = parseColor(obj);
mSuggestions = parseSuggestion(obj);
//TODO
}
QStringList GrammalecteGrammarError::parseSuggestion()
{
return {};
}
QColor GrammalecteGrammarError::parseColor()
{
return {};
QStringList GrammalecteGrammarError::parseSuggestion(const QJsonObject &obj)
{
QStringList lst;
const QJsonArray array = obj[QStringLiteral("aSuggestions")].toArray();
const QVariantList list = array.toVariantList();
for (const QVariant &v : list) {
qDebug() << " v" << v.toString();
lst.append(v.toString());
}
return lst;
}
QColor GrammalecteGrammarError::parseColor(const QJsonObject &obj)
{
QColor col;
const QJsonArray array = obj[QStringLiteral("aColor")].toArray();
if (array.count() == 3) {
const QVariantList list = array.toVariantList();
// for (const QVariant &v : list) {
// qDebug() << " v" << v.toInt();
// }
col = QColor(array.at(0).toInt(), array.at(1).toInt(), array.at(2).toInt());
} else {
qCWarning(KMAIL_EDITOR_GRAMMALECTE_PLUGIN_LOG) << "Parsing color: Array is not correct:" << array;
}
return col;
}
QDebug operator <<(QDebug d, const GrammalecteGrammarError &t)
......
......@@ -24,6 +24,7 @@
#include <QColor>
#include <QString>
#include <QDebug>
#include <QJsonObject>
#include "libgrammalect_private_export.h"
class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammalecteGrammarError
{
......@@ -53,8 +54,8 @@ public:
void parse(const QJsonObject &obj, int blockindex);
private:
static QColor parseColor();
static QStringList parseSuggestion();
static QColor parseColor(const QJsonObject &obj);
static QStringList parseSuggestion(const QJsonObject &obj);
QStringList mSuggestions;
QString mError;
QColor mColor;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment