fix(Spellchecking): Add check for hunspell existence

This commit is contained in:
B.Melnik 2021-10-21 17:44:22 +03:00 committed by Michał Cieślak
parent 3c7b498e74
commit 75d0382e97
3 changed files with 20 additions and 17 deletions

View File

@ -32,9 +32,12 @@ macx {
hunspellTarget.commands = brew install hunspell
QMAKE_EXTRA_TARGETS += hunspellTarget
exists (/usr/local/lib/libhunspell-1.7.a) {
LIBS += -L"/usr/local/lib" -lhunspell-1.7
INCLUDEPATH += /usr/local/include/hunspell
DEFINES += USE_HUNSPELL
message("hunspell exists in /usr/local/lib")
}
}
ios {

View File

@ -1,6 +1,6 @@
#include "spellchecker.h"
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
#include "hunspell.hxx"
#endif
#include <QTextCodec>
@ -14,24 +14,24 @@
SpellChecker::SpellChecker(QObject *parent)
: QObject(parent)
#ifdef Q_OS_MACOS
, m_userDict("userDict_")
#ifdef USE_HUNSPELL
, m_hunspell(nullptr)
#endif
, m_userDict("userDict_")
{
}
SpellChecker::~SpellChecker()
{
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
delete m_hunspell;
#endif
}
bool SpellChecker::spell(const QString &word)
{
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
return m_hunspell->spell(m_codec->fromUnicode(word).toStdString());
#else
return true;
@ -40,15 +40,15 @@ bool SpellChecker::spell(const QString &word)
bool SpellChecker::isInit() const
{
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
return !m_hunspell;
#endif
return false;
}
void SpellChecker::initHunspell()
{
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
if (m_hunspell) {
delete m_hunspell;
}
@ -109,7 +109,7 @@ QVariantList SpellChecker::suggest(const QString &word)
{
int numSuggestions = 0;
QVariantList suggestions;
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
std::vector<std::string> wordlist;
wordlist = m_hunspell->suggest(m_codec->fromUnicode(word).toStdString());
@ -128,14 +128,14 @@ QVariantList SpellChecker::suggest(const QString &word)
void SpellChecker::ignoreWord(const QString &word)
{
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
m_hunspell->add(m_codec->fromUnicode(word).constData());
#endif
}
void SpellChecker::addToUserWordlist(const QString &word)
{
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
QString userDict = m_userDict + m_lang + ".txt";
if (!userDict.isEmpty()) {
QFile userDictonaryFile(userDict);

View File

@ -6,7 +6,7 @@
#include <QQuickTextDocument>
#include <QSyntaxHighlighter>
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
class Hunspell;
#endif
class QTextCodec;
@ -45,7 +45,7 @@ private:
QString m_userDict;
QQuickTextDocument *m_document;
#ifdef Q_OS_MACOS
#ifdef USE_HUNSPELL
Hunspell *m_hunspell;
#endif
QTextCodec *m_codec;