Commit bf2ed1ee authored by Scott Wheeler's avatar Scott Wheeler

Add "Contains", "Exact" and "ContainsWord" modes to the

PlaylistSearch::Component and use the ContainsWord mode for building the
tree view.

CCMAIL:59269-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=239801
parent 65c7b2ae
...@@ -113,6 +113,7 @@ void PlaylistSearch::search() ...@@ -113,6 +113,7 @@ void PlaylistSearch::search()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
PlaylistSearch::Component::Component() : PlaylistSearch::Component::Component() :
m_mode(Contains),
m_searchAllVisible(true), m_searchAllVisible(true),
m_caseSensitive(false) m_caseSensitive(false)
{ {
...@@ -121,9 +122,11 @@ PlaylistSearch::Component::Component() : ...@@ -121,9 +122,11 @@ PlaylistSearch::Component::Component() :
PlaylistSearch::Component::Component(const QString &query, PlaylistSearch::Component::Component(const QString &query,
bool caseSensitive, bool caseSensitive,
const ColumnList &columns) : const ColumnList &columns,
MatchMode mode) :
m_query(query), m_query(query),
m_columns(columns), m_columns(columns),
m_mode(mode),
m_searchAllVisible(columns.isEmpty()), m_searchAllVisible(columns.isEmpty()),
m_caseSensitive(caseSensitive), m_caseSensitive(caseSensitive),
m_re(false) m_re(false)
...@@ -134,6 +137,7 @@ PlaylistSearch::Component::Component(const QString &query, ...@@ -134,6 +137,7 @@ PlaylistSearch::Component::Component(const QString &query,
PlaylistSearch::Component::Component(const QRegExp &query, const ColumnList& columns) : PlaylistSearch::Component::Component(const QRegExp &query, const ColumnList& columns) :
m_queryRe(query), m_queryRe(query),
m_columns(columns), m_columns(columns),
m_mode(Exact),
m_searchAllVisible(columns.isEmpty()), m_searchAllVisible(columns.isEmpty()),
m_caseSensitive(false), m_caseSensitive(false),
m_re(true) m_re(true)
...@@ -155,12 +159,39 @@ bool PlaylistSearch::Component::matches(PlaylistItem *item) ...@@ -155,12 +159,39 @@ bool PlaylistSearch::Component::matches(PlaylistItem *item)
} }
for(ColumnList::Iterator it = m_columns.begin(); it != m_columns.end(); ++it) { bool match = false;
int matches = m_re ? item->text(*it).contains(m_queryRe)
: item->text(*it).contains(m_query, m_caseSensitive); for(ColumnList::Iterator it = m_columns.begin(); !match && it != m_columns.end(); ++it) {
if(matches > 0)
return true; if(m_re)
match = item->text(*it).contains(m_queryRe) > 0;
else {
switch(m_mode) {
case Contains:
match = item->text(*it).contains(m_query, m_caseSensitive) > 0;
break;
case Exact:
{
if(item->text(*it).length() == m_query.length()) {
if(m_caseSensitive)
match = item->text(*it) == m_query;
else
match = item->text(*it).lower() == m_query.lower();
}
break;
}
case ContainsWord:
{
QRegExp r(QString("\\b%1\\b").arg(m_query), m_caseSensitive);
match = item->text(*it).contains(r) > 0;
break;
}
}
}
} }
return false; return match;
} }
...@@ -72,6 +72,8 @@ private: ...@@ -72,6 +72,8 @@ private:
class PlaylistSearch::Component class PlaylistSearch::Component
{ {
public: public:
enum MatchMode { Contains = 0, Exact = 1, ContainsWord = 2 };
/** /**
* Create an empty search component. This is only provided for use by * Create an empty search component. This is only provided for use by
* QValueList and should not be used in any other context. * QValueList and should not be used in any other context.
...@@ -83,7 +85,8 @@ public: ...@@ -83,7 +85,8 @@ public:
*/ */
Component(const QString &query, Component(const QString &query,
bool caseSensitive = false, bool caseSensitive = false,
const ColumnList &columns = ColumnList()); const ColumnList &columns = ColumnList(),
MatchMode mode = Contains);
/** /**
* Create a query component. This defaults to searching all visible coulumns. * Create a query component. This defaults to searching all visible coulumns.
...@@ -102,6 +105,7 @@ private: ...@@ -102,6 +105,7 @@ private:
QString m_query; QString m_query;
QRegExp m_queryRe; QRegExp m_queryRe;
ColumnList m_columns; ColumnList m_columns;
MatchMode m_mode;
bool m_searchAllVisible; bool m_searchAllVisible;
bool m_caseSensitive; bool m_caseSensitive;
bool m_re; bool m_re;
......
...@@ -233,7 +233,7 @@ void TreeViewMode::setupCategory(const QString &searchCategory, const QStringLis ...@@ -233,7 +233,7 @@ void TreeViewMode::setupCategory(const QString &searchCategory, const QStringLis
for(QStringList::ConstIterator it = members.begin(); it != members.end(); ++it) { for(QStringList::ConstIterator it = members.begin(); it != members.end(); ++it) {
PlaylistSearch::ComponentList components; PlaylistSearch::ComponentList components;
components.append(PlaylistSearch::Component(*it, false, columns)); components.append(PlaylistSearch::Component(*it, false, columns, PlaylistSearch::Component::ContainsWord));
PlaylistList playlists; PlaylistList playlists;
playlists.append(collection); playlists.append(collection);
......
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