mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-28 08:49:42 -05:00
Move match method out of entry class.
This commit is contained in:
parent
c90ac914bb
commit
819cfd459a
@ -579,25 +579,6 @@ const Database* Entry::database() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Entry::match(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity)
|
|
||||||
{
|
|
||||||
QStringList wordList = searchTerm.split(QRegExp("\\s"), QString::SkipEmptyParts);
|
|
||||||
Q_FOREACH (const QString& word, wordList) {
|
|
||||||
if (!wordMatch(word, caseSensitivity)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Entry::wordMatch(const QString& word, Qt::CaseSensitivity caseSensitivity)
|
|
||||||
{
|
|
||||||
return title().contains(word, caseSensitivity) ||
|
|
||||||
username().contains(word, caseSensitivity) ||
|
|
||||||
url().contains(word, caseSensitivity) ||
|
|
||||||
notes().contains(word, caseSensitivity);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Entry::resolvePlaceholders(const QString& str) const
|
QString Entry::resolvePlaceholders(const QString& str) const
|
||||||
{
|
{
|
||||||
QString result = str;
|
QString result = str;
|
||||||
|
@ -141,7 +141,6 @@ public:
|
|||||||
void setGroup(Group* group);
|
void setGroup(Group* group);
|
||||||
|
|
||||||
void setUpdateTimeinfo(bool value);
|
void setUpdateTimeinfo(bool value);
|
||||||
bool match(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
@ -157,7 +156,6 @@ private Q_SLOTS:
|
|||||||
void updateModifiedSinceBegin();
|
void updateModifiedSinceBegin();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool wordMatch(const QString& word, Qt::CaseSensitivity caseSensitivity);
|
|
||||||
const Database* database() const;
|
const Database* database() const;
|
||||||
template <class T> bool set(T& property, const T& value);
|
template <class T> bool set(T& property, const T& value);
|
||||||
|
|
||||||
|
@ -33,9 +33,7 @@ QList<Entry*> EntrySearcher::searchEntries(const QString &searchTerm, const Grou
|
|||||||
QList<Entry*> searchResult;
|
QList<Entry*> searchResult;
|
||||||
|
|
||||||
Q_FOREACH (Entry* entry, group->entries()) {
|
Q_FOREACH (Entry* entry, group->entries()) {
|
||||||
if (entry->match(searchTerm, caseSensitivity)) {
|
searchResult.append(matchEntry(searchTerm, entry, caseSensitivity));
|
||||||
searchResult.append(entry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Q_FOREACH (Group* childGroup, group->children()) {
|
Q_FOREACH (Group* childGroup, group->children()) {
|
||||||
if (childGroup->searchingEnabled() != Group::Disable) {
|
if (childGroup->searchingEnabled() != Group::Disable) {
|
||||||
@ -45,3 +43,23 @@ QList<Entry*> EntrySearcher::searchEntries(const QString &searchTerm, const Grou
|
|||||||
|
|
||||||
return searchResult;
|
return searchResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Entry*> EntrySearcher::matchEntry(const QString& searchTerm, Entry* entry, Qt::CaseSensitivity caseSensitivity)
|
||||||
|
{
|
||||||
|
QStringList wordList = searchTerm.split(QRegExp("\\s"), QString::SkipEmptyParts);
|
||||||
|
Q_FOREACH (const QString& word, wordList) {
|
||||||
|
if (!wordMatch(word, entry, caseSensitivity)) {
|
||||||
|
return QList<Entry*>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QList<Entry*>() << entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EntrySearcher::wordMatch(const QString& word, Entry* entry, Qt::CaseSensitivity caseSensitivity)
|
||||||
|
{
|
||||||
|
return entry->title().contains(word, caseSensitivity) ||
|
||||||
|
entry->username().contains(word, caseSensitivity) ||
|
||||||
|
entry->url().contains(word, caseSensitivity) ||
|
||||||
|
entry->notes().contains(word, caseSensitivity);
|
||||||
|
}
|
||||||
|
@ -30,6 +30,8 @@ public:
|
|||||||
QList<Entry*> search(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity);
|
QList<Entry*> search(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity);
|
||||||
private:
|
private:
|
||||||
QList<Entry*> searchEntries(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity);
|
QList<Entry*> searchEntries(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity);
|
||||||
|
QList<Entry*> matchEntry(const QString& searchTerm, Entry* entry, Qt::CaseSensitivity caseSensitivity);
|
||||||
|
bool wordMatch(const QString &word, Entry *entry, Qt::CaseSensitivity caseSensitivity);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_ENTRYSEARCHER_H
|
#endif // KEEPASSX_ENTRYSEARCHER_H
|
||||||
|
Loading…
Reference in New Issue
Block a user