mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-17 07:48:27 +01:00
- dic_search.cpp: Do not add twice the same word in a 7+1 search (this can happen when using jokers)
- dic_tools_widget.cpp: Allow up to 2 jokers in the 7+1 search
This commit is contained in:
parent
4686153a7a
commit
003b403422
2 changed files with 22 additions and 8 deletions
|
@ -112,7 +112,10 @@ void Dictionary::searchWordByLen(struct params_7plus1_t *params,
|
||||||
{
|
{
|
||||||
if (edgeptr->term)
|
if (edgeptr->term)
|
||||||
{
|
{
|
||||||
(*params->results)[params->added_char].push_back(params->search_wordtst);
|
// Add the solution
|
||||||
|
vector<wstring> &sols = (*params->results)[params->added_char];
|
||||||
|
if (sols.empty() || sols.back() != params->search_wordtst)
|
||||||
|
sols.push_back(params->search_wordtst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -132,7 +135,10 @@ void Dictionary::searchWordByLen(struct params_7plus1_t *params,
|
||||||
{
|
{
|
||||||
if (edgeptr->term)
|
if (edgeptr->term)
|
||||||
{
|
{
|
||||||
(*params->results)[params->added_char].push_back(params->search_wordtst);
|
// Add the solution
|
||||||
|
vector<wstring> &sols = (*params->results)[params->added_char];
|
||||||
|
if (sols.empty() || sols.back() != params->search_wordtst)
|
||||||
|
sols.push_back(params->search_wordtst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -43,11 +43,13 @@ class DicRackValidator: public QValidator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit DicRackValidator(QObject *parent,
|
explicit DicRackValidator(QObject *parent,
|
||||||
const Dictionary *iDic);
|
const Dictionary *iDic,
|
||||||
|
bool acceptJoker = false);
|
||||||
virtual State validate(QString &input, int &pos) const;
|
virtual State validate(QString &input, int &pos) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Dictionary *m_dic;
|
const Dictionary *m_dic;
|
||||||
|
const bool m_acceptJoker;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +116,7 @@ void DicToolsWidget::setDic(const Dictionary *iDic)
|
||||||
lineEditRegexp->clear();
|
lineEditRegexp->clear();
|
||||||
// Create new validators
|
// Create new validators
|
||||||
lineEditCheck->setValidator(new DicRackValidator(this, m_dic));
|
lineEditCheck->setValidator(new DicRackValidator(this, m_dic));
|
||||||
lineEditPlus1->setValidator(new DicRackValidator(this, m_dic));
|
lineEditPlus1->setValidator(new DicRackValidator(this, m_dic, true));
|
||||||
lineEditRegexp->setValidator(new RegexpValidator(this, m_dic));
|
lineEditRegexp->setValidator(new RegexpValidator(this, m_dic));
|
||||||
// Refresh
|
// Refresh
|
||||||
refreshCheck();
|
refreshCheck();
|
||||||
|
@ -177,7 +179,7 @@ void DicToolsWidget::refreshPlus1()
|
||||||
if (rack->text() != "")
|
if (rack->text() != "")
|
||||||
{
|
{
|
||||||
map<wchar_t, vector<wstring> > wordList;
|
map<wchar_t, vector<wstring> > wordList;
|
||||||
m_dic->search7pl1(qtw(rack->text()), wordList, false);
|
m_dic->search7pl1(qtw(rack->text()), wordList, true);
|
||||||
|
|
||||||
int rowNum = 0;
|
int rowNum = 0;
|
||||||
map<wchar_t, vector<wstring> >::const_iterator it;
|
map<wchar_t, vector<wstring> >::const_iterator it;
|
||||||
|
@ -311,8 +313,9 @@ void DicToolsWidget::refreshDicInfo()
|
||||||
|
|
||||||
|
|
||||||
DicRackValidator::DicRackValidator(QObject *parent,
|
DicRackValidator::DicRackValidator(QObject *parent,
|
||||||
const Dictionary *iDic)
|
const Dictionary *iDic,
|
||||||
: QValidator(parent), m_dic(iDic)
|
bool acceptJoker)
|
||||||
|
: QValidator(parent), m_dic(iDic), m_acceptJoker(acceptJoker)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +332,12 @@ QValidator::State DicRackValidator::validate(QString &input, int &) const
|
||||||
|
|
||||||
// The string is invalid if it contains characters not present
|
// The string is invalid if it contains characters not present
|
||||||
// in the dictionary or if it contains a '?'
|
// in the dictionary or if it contains a '?'
|
||||||
if (!m_dic->validateLetters(qtw(input)) || input.contains('?'))
|
if (!m_dic->validateLetters(qtw(input)))
|
||||||
|
return Invalid;
|
||||||
|
if (!m_acceptJoker && input.contains('?'))
|
||||||
|
return Invalid;
|
||||||
|
// Do not accept more than 2 jokers
|
||||||
|
if (input.count('?') > 2)
|
||||||
return Invalid;
|
return Invalid;
|
||||||
return Acceptable;
|
return Acceptable;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue