Added filter box for keywords

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1615 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2011-01-16 13:34:50 +00:00
parent e74f883345
commit d217349148
17 changed files with 908 additions and 880 deletions
-38
View File
@@ -55,41 +55,6 @@ String Card::identification() const {
}
}
/// Does the given object match the quick search query?
template <typename T>
bool match_quicksearch_query(String const& query, T const& object) {
bool need_match = true;
// iterate over the components of the query
for (size_t i = 0 ; i < query.size() ; ) {
if (query.GetChar(i) == _(' ')) {
// skip spaces
i++;
} else if (query.GetChar(i) == _('-')) {
// negate the next query, i.e. match only if it is not on the card
need_match = !need_match;
i++;
} else {
size_t end, next;
if (query.GetChar(i) == _('"')) {
// quoted string, match exactly
i++;
end =query.find_first_of(_('"'),i);
next = min(end,query.size()) + 1;
} else {
// single word
next = end = query.find_first_of(_(' '),i);
}
bool match = object.contains(query.substr(i,end-i));
if (match != need_match) {
return false;
}
need_match = true; // next word is no longer negated
i = next;
}
}
return true;
}
bool Card::contains(String const& query) const {
FOR_EACH_CONST(v, data) {
if (find_i(v->toString(),query) != String::npos) return true;
@@ -97,9 +62,6 @@ bool Card::contains(String const& query) const {
if (find_i(notes,query) != String::npos) return true;
return false;
}
bool Card::contains_words(String const& query) const {
return match_quicksearch_query(query,*this);
}
IndexMap<FieldP, ValueP>& Card::extraDataFor(const StyleSheet& stylesheet) {
return extra_data.get(stylesheet.name(), stylesheet.extra_card_fields);
+8
View File
@@ -80,6 +80,14 @@ void read_compat(Reader& tag, Keyword* k) {
}
}
bool Keyword::contains(String const& query) const {
if (find_i(keyword,query) != String::npos) return true;
if (find_i(rules,query) != String::npos) return true;
if (find_i(match,query) != String::npos) return true;
if (find_i(reminder.get(),query) != String::npos) return true;
return false;
}
IMPLEMENT_REFLECTION(Keyword) {
REFLECT(keyword);
read_compat(tag, this);
+3
View File
@@ -116,6 +116,9 @@ class Keyword : public IntrusivePtrVirtualBase {
*/
void prepare(const vector<KeywordParamP>& param_types, bool force = false);
/// Does the keyword contain the given query word?
bool contains(String const& word) const;
DECLARE_REFLECTION();
};