Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 680b547a authored by Laurent Montel's avatar Laurent Montel 😁

Create a common lib

parent 08df9d65
......@@ -18,7 +18,7 @@
*/
#include "grammalectegrammarerrortest.h"
#include "grammalectegrammarerror.h"
#include "grammarerror.h"
#include <QJsonDocument>
#include <QStandardPaths>
#include <QTest>
......@@ -32,9 +32,9 @@ GrammalecteGrammarErrorTest::GrammalecteGrammarErrorTest(QObject *parent)
void GrammalecteGrammarErrorTest::shouldHaveDefaultValue()
{
GrammalecteGrammarError info;
GrammarError info;
QCOMPARE(info.end(), -1);
QCOMPARE(info.begin(), -1);
QCOMPARE(info.start(), -1);
QCOMPARE(info.blockId(), -1);
QVERIFY(info.error().isEmpty());
QVERIFY(info.suggestions().isEmpty());
......@@ -46,11 +46,11 @@ void GrammalecteGrammarErrorTest::shouldParseJson_data()
{
QTest::addColumn<QString>("fileName");
QTest::addColumn<int>("nbBlock");
QTest::addColumn<GrammalecteGrammarError>("error");
QTest::newRow("empty-error") << QStringLiteral("empty-error") << 1 << GrammalecteGrammarError();
GrammalecteGrammarError err;
QTest::addColumn<GrammarError>("error");
QTest::newRow("empty-error") << QStringLiteral("empty-error") << 1 << GrammarError();
GrammarError err;
err.setBlockId(1);
err.setBegin(15);
err.setStart(15);
err.setEnd(20);
err.setColor(QColor(217, 128, 38));
err.setSuggestions(QStringList() << QStringLiteral("Alors"));
......@@ -66,7 +66,7 @@ void GrammalecteGrammarErrorTest::shouldParseJson()
{
QFETCH(QString, fileName);
QFETCH(int, nbBlock);
QFETCH(GrammalecteGrammarError, error);
QFETCH(GrammarError, error);
const QString originalJsonFile = QLatin1String(GRAMMALECTE_DATA_DIR) + QLatin1Char('/') + fileName + QStringLiteral(".json");
QFile f(originalJsonFile);
QVERIFY(f.open(QIODevice::ReadOnly));
......@@ -74,7 +74,7 @@ void GrammalecteGrammarErrorTest::shouldParseJson()
f.close();
const QJsonDocument doc = QJsonDocument::fromJson(content);
const QJsonObject fields = doc.object();
GrammalecteGrammarError parser;
GrammarError parser;
parser.parse(fields, nbBlock);
const bool compare = (parser == error);
if (!compare) {
......
set(kmailgrammalecte_SRCS
grammalecteparser.cpp
grammarresultwidget.cpp
grammarresulttextedit.cpp
grammalectegrammarerror.cpp
grammarresultjob.cpp
grammalecteconfigwidget.cpp
grammalectegenerateconfigoptionjob.cpp
grammalecteconfigdialog.cpp
grammalectemanager.cpp
grammarresultwidget.cpp
)
ecm_qt_declare_logging_category(kmailgrammalecte_SRCS HEADER libgrammalecte_debug.h IDENTIFIER LIBGRAMMALECTE_PLUGIN_LOG CATEGORY_NAME org.kde.pim.libgrammalecteplugin)
......@@ -22,6 +20,7 @@ target_link_libraries(kmailgrammalecte
KF5::WidgetsAddons
KF5::KIOWidgets
KF5::MessageComposer
grammarcommon
)
set_target_properties(kmailgrammalecte
......
......@@ -31,9 +31,9 @@ GrammalecteParser::~GrammalecteParser()
{
}
QVector<GrammalecteGrammarError> GrammalecteParser::parseResult(const QJsonObject &obj) const
QVector<GrammarError> GrammalecteParser::parseResult(const QJsonObject &obj) const
{
QVector<GrammalecteGrammarError> infos;
QVector<GrammarError> infos;
if (!obj.contains(QLatin1String("grammalecte"))) {
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Error in json " << obj;
return infos;
......@@ -48,7 +48,7 @@ QVector<GrammalecteGrammarError> GrammalecteParser::parseResult(const QJsonObjec
const QJsonArray grammarErrorArray = grammaObject.value(QLatin1String("lGrammarErrors")).toArray();
for (const QJsonValue &error : grammarErrorArray) {
//qDebug() << " grammarErrorArray"<<error;
GrammalecteGrammarError info;
GrammarError info;
if (error.type() == QJsonValue::Object) {
info.parse(error.toObject(), blockId);
if (info.isValid()) {
......
......@@ -23,13 +23,13 @@
#include <QVector>
#include <QJsonObject>
#include "libgrammalect_private_export.h"
#include "grammalectegrammarerror.h"
#include "grammarerror.h"
class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammalecteParser
{
public:
GrammalecteParser();
~GrammalecteParser();
QVector<GrammalecteGrammarError> parseResult(const QJsonObject &obj) const;
QVector<GrammarError> parseResult(const QJsonObject &obj) const;
};
#endif // GRAMMALECTEPARSER_H
......@@ -67,7 +67,7 @@ void GrammarResultWidget::setText(const QString &str)
mResult->setText(str);
}
void GrammarResultWidget::applyGrammarResult(const QVector<GrammalecteGrammarError> &infos)
void GrammarResultWidget::applyGrammarResult(const QVector<GrammarError> &infos)
{
mResult->applyGrammarResult(infos);
}
......@@ -22,7 +22,7 @@
#include <QWidget>
#include "libkmailgrammalecte_export.h"
#include "grammalectegrammarerror.h"
#include "grammarerror.h"
namespace MessageComposer {
class PluginGrammarAction;
}
......@@ -35,7 +35,7 @@ public:
~GrammarResultWidget();
void setText(const QString &str);
void checkGrammar();
void applyGrammarResult(const QVector<GrammalecteGrammarError> &infos);
void applyGrammarResult(const QVector<GrammarError> &infos);
Q_SIGNALS:
void replaceText(const MessageComposer::PluginGrammarAction &act);
void checkAgain();
......
set(grammarcommon_SRCS
grammarerror.cpp
grammarresulttextedit.cpp
)
ecm_qt_declare_logging_category(grammarcommon_SRCS HEADER grammarcommon_debug.h IDENTIFIER LIBGRAMMARCOMMON_LOG CATEGORY_NAME org.kde.pim.libgrammarcommon)
add_library(grammarcommon ${grammarcommon_SRCS})
generate_export_header(grammarcommon BASE_NAME grammarcommon)
target_link_libraries(grammarcommon
KF5::I18n
KF5::MessageComposer
)
set_target_properties(grammarcommon
PROPERTIES OUTPUT_NAME grammarcommon VERSION ${KDEPIMADDONS_LIB_VERSION} SOVERSION ${KDEPIMADDONS_LIB_SOVERSION}
)
install(TARGETS grammarcommon ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP)
......@@ -17,92 +17,92 @@
Boston, MA 02110-1301, USA.
*/
#include "grammalectegrammarerror.h"
#include "libgrammalecte_debug.h"
#include "grammarerror.h"
#include "grammarcommon_debug.h"
#include <QJsonArray>
#include <QJsonObject>
GrammalecteGrammarError::GrammalecteGrammarError()
GrammarError::GrammarError()
{
}
GrammalecteGrammarError::~GrammalecteGrammarError()
GrammarError::~GrammarError()
{
}
QColor GrammalecteGrammarError::color() const
QColor GrammarError::color() const
{
return mColor;
}
void GrammalecteGrammarError::setColor(const QColor &color)
void GrammarError::setColor(const QColor &color)
{
mColor = color;
}
QString GrammalecteGrammarError::error() const
QString GrammarError::error() const
{
return mError;
}
void GrammalecteGrammarError::setError(const QString &error)
void GrammarError::setError(const QString &error)
{
mError = error;
}
int GrammalecteGrammarError::blockId() const
int GrammarError::blockId() const
{
return mBlockId;
}
void GrammalecteGrammarError::setBlockId(int blockId)
void GrammarError::setBlockId(int blockId)
{
mBlockId = blockId;
}
int GrammalecteGrammarError::begin() const
int GrammarError::start() const
{
return mBegin;
return mStart;
}
void GrammalecteGrammarError::setBegin(int begin)
void GrammarError::setStart(int begin)
{
mBegin = begin;
mStart = begin;
}
int GrammalecteGrammarError::end() const
int GrammarError::end() const
{
return mEnd;
}
void GrammalecteGrammarError::setEnd(int end)
void GrammarError::setEnd(int end)
{
mEnd = end;
}
QStringList GrammalecteGrammarError::suggestions() const
QStringList GrammarError::suggestions() const
{
return mSuggestions;
}
void GrammalecteGrammarError::setSuggestions(const QStringList &suggestions)
void GrammarError::setSuggestions(const QStringList &suggestions)
{
mSuggestions = suggestions;
}
bool GrammalecteGrammarError::isValid() const
bool GrammarError::isValid() const
{
if ((mEnd != -1) && (mBegin != -1) && (!mError.isEmpty())) {
if ((mEnd != -1) && (mStart != -1) && (!mError.isEmpty())) {
return true;
}
return false;
}
void GrammalecteGrammarError::parse(const QJsonObject &obj, int blockindex)
void GrammarError::parse(const QJsonObject &obj, int blockindex)
{
mEnd = obj[QStringLiteral("nEnd")].toInt(-1);
mBegin = obj[QStringLiteral("nStart")].toInt(-1);
mStart = obj[QStringLiteral("nStart")].toInt(-1);
mError = obj[QStringLiteral("sMessage")].toString();
if (mEnd != -1) {
mBlockId = blockindex;
......@@ -114,11 +114,11 @@ void GrammalecteGrammarError::parse(const QJsonObject &obj, int blockindex)
mUrl = obj[QStringLiteral("URL")].toString();
}
bool GrammalecteGrammarError::operator ==(const GrammalecteGrammarError &other) const
bool GrammarError::operator ==(const GrammarError &other) const
{
return (mBlockId == other.blockId())
&& (mEnd == other.end())
&& (mBegin == other.begin())
&& (mStart == other.start())
&& (mColor == other.color())
&& (mSuggestions == other.suggestions())
&& (mError == other.error())
......@@ -127,7 +127,7 @@ bool GrammalecteGrammarError::operator ==(const GrammalecteGrammarError &other)
&& (mUrl == other.url());
}
QStringList GrammalecteGrammarError::parseSuggestion(const QJsonObject &obj)
QStringList GrammarError::parseSuggestion(const QJsonObject &obj)
{
QStringList lst;
const QJsonArray array = obj[QStringLiteral("aSuggestions")].toArray();
......@@ -139,37 +139,37 @@ QStringList GrammalecteGrammarError::parseSuggestion(const QJsonObject &obj)
return lst;
}
QString GrammalecteGrammarError::url() const
QString GrammarError::url() const
{
return mUrl;
}
void GrammalecteGrammarError::setUrl(const QString &url)
void GrammarError::setUrl(const QString &url)
{
mUrl = url;
}
QString GrammalecteGrammarError::rule() const
QString GrammarError::rule() const
{
return mRule;
}
void GrammalecteGrammarError::setRule(const QString &rule)
void GrammarError::setRule(const QString &rule)
{
mRule = rule;
}
QString GrammalecteGrammarError::option() const
QString GrammarError::option() const
{
return mOption;
}
void GrammalecteGrammarError::setOption(const QString &option)
void GrammarError::setOption(const QString &option)
{
mOption = option;
}
QColor GrammalecteGrammarError::parseColor(const QJsonObject &obj)
QColor GrammarError::parseColor(const QJsonObject &obj)
{
QColor col;
const QJsonArray array = obj[QStringLiteral("aColor")].toArray();
......@@ -183,15 +183,15 @@ QColor GrammalecteGrammarError::parseColor(const QJsonObject &obj)
// }
col = QColor(array.at(0).toInt(), array.at(1).toInt(), array.at(2).toInt());
} else {
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Parsing color: Array is not correct:" << array;
qCWarning(LIBGRAMMARCOMMON_LOG) << "Parsing color: Array is not correct:" << array;
}
return col;
}
QDebug operator <<(QDebug d, const GrammalecteGrammarError &t)
QDebug operator <<(QDebug d, const GrammarError &t)
{
d << "mError: " << t.error();
d << "Start: " << t.begin();
d << "Start: " << t.start();
d << "End: " << t.end();
d << "BlockId: " << t.blockId();
d << "Color: " << t.color().name();
......
......@@ -25,12 +25,12 @@
#include <QString>
#include <QDebug>
#include <QJsonObject>
#include "libgrammalect_private_export.h"
class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammalecteGrammarError
#include "grammarcommon_export.h"
class GRAMMARCOMMON_EXPORT GrammarError
{
public:
GrammalecteGrammarError();
~GrammalecteGrammarError();
GrammarError();
~GrammarError();
Q_REQUIRED_RESULT QColor color() const;
void setColor(const QColor &color);
......@@ -40,8 +40,8 @@ public:
Q_REQUIRED_RESULT int blockId() const;
void setBlockId(int blockId);
Q_REQUIRED_RESULT int begin() const;
void setBegin(int begin);
Q_REQUIRED_RESULT int start() const;
void setStart(int start);
Q_REQUIRED_RESULT int end() const;
void setEnd(int end);
......@@ -53,7 +53,7 @@ public:
void parse(const QJsonObject &obj, int blockindex);
Q_REQUIRED_RESULT bool operator ==(const GrammalecteGrammarError &other) const;
Q_REQUIRED_RESULT bool operator ==(const GrammarError &other) const;
Q_REQUIRED_RESULT QString option() const;
void setOption(const QString &option);
......@@ -74,10 +74,10 @@ private:
QString mUrl;
QColor mColor;
int mBlockId = -1;
int mBegin = -1;
int mStart = -1;
int mEnd = -1;
};
Q_DECLARE_METATYPE(GrammalecteGrammarError)
Q_DECLARE_TYPEINFO(GrammalecteGrammarError, Q_MOVABLE_TYPE);
LIBKMAILGRAMMALECTE_EXPORT QDebug operator <<(QDebug d, const GrammalecteGrammarError &t);
Q_DECLARE_METATYPE(GrammarError)
Q_DECLARE_TYPEINFO(GrammarError, Q_MOVABLE_TYPE);
GRAMMARCOMMON_EXPORT QDebug operator <<(QDebug d, const GrammarError &t);
#endif // GRAMMALECTEINFO_H
......@@ -19,7 +19,7 @@
#include "grammarresulttextedit.h"
#include <MessageComposer/PluginEditorGrammarCustomToolsViewInterface>
#include "libgrammalecte_debug.h"
#include "grammarcommon_debug.h"
#include <KLocalizedString>
......@@ -39,9 +39,9 @@ GrammarResultTextEdit::~GrammarResultTextEdit()
{
}
void GrammarResultTextEdit::applyGrammarResult(const QVector<GrammalecteGrammarError> &infos)
void GrammarResultTextEdit::applyGrammarResult(const QVector<GrammarError> &infos)
{
for (const GrammalecteGrammarError &info : infos) {
for (const GrammarError &info : infos) {
//Block id based on 1 not 0 as QTextDocument (perhaps remove -1 when loading ?)
QTextBlock block = document()->findBlockByNumber(info.blockId() - 1);
if (block.isValid()) {
......@@ -53,15 +53,15 @@ void GrammarResultTextEdit::applyGrammarResult(const QVector<GrammalecteGrammarE
format.setToolTip(info.error());
MessageComposer::PluginGrammarAction act;
act.setEnd(info.end());
act.setStart(info.begin());
act.setStart(info.start());
act.setSuggestions(info.suggestions());
act.setBlockId(info.blockId());
format.setProperty(ReplaceFormatInfo, QVariant::fromValue(act));
cur.setPosition(position + info.begin());
cur.setPosition(position + info.start());
cur.setPosition(position + info.end(), QTextCursor::KeepAnchor);
cur.mergeCharFormat(format);
} else {
qCWarning(LIBGRAMMALECTE_PLUGIN_LOG) << "Unable to find block Id" << (info.blockId() -1);
qCWarning(LIBGRAMMARCOMMON_LOG) << "Unable to find block Id" << (info.blockId() -1);
}
}
}
......
......@@ -21,19 +21,19 @@
#define GRAMMARRESULTTEXTEDIT_H
#include <QTextEdit>
#include "grammalectegrammarerror.h"
#include "libgrammalect_private_export.h"
#include "grammarerror.h"
#include "grammarcommon_export.h"
namespace MessageComposer {
class PluginGrammarAction;
}
class LIBGRAMMALECTPRIVATE_TESTS_EXPORT GrammarResultTextEdit : public QTextEdit
class GRAMMARCOMMON_EXPORT GrammarResultTextEdit : public QTextEdit
{
Q_OBJECT
public:
explicit GrammarResultTextEdit(QWidget *parent = nullptr);
~GrammarResultTextEdit() override;
void applyGrammarResult(const QVector<GrammalecteGrammarError> &infos);
void applyGrammarResult(const QVector<GrammarError> &infos);
protected:
void contextMenuEvent(QContextMenuEvent *event) override;
......
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