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()
////////////////////////////////////////////////////////////////////////////////
PlaylistSearch::Component::Component() :
m_mode(Contains),
m_searchAllVisible(true),
m_caseSensitive(false)
{
......@@ -121,9 +122,11 @@ PlaylistSearch::Component::Component() :
PlaylistSearch::Component::Component(const QString &query,
bool caseSensitive,
const ColumnList &columns) :
const ColumnList &columns,
MatchMode mode) :
m_query(query),
m_columns(columns),
m_mode(mode),
m_searchAllVisible(columns.isEmpty()),
m_caseSensitive(caseSensitive),
m_re(false)
......@@ -134,6 +137,7 @@ PlaylistSearch::Component::Component(const QString &query,
PlaylistSearch::Component::Component(const QRegExp &query, const ColumnList& columns) :
m_queryRe(query),
m_columns(columns),
m_mode(Exact),
m_searchAllVisible(columns.isEmpty()),
m_caseSensitive(false),
m_re(true)
......@@ -155,12 +159,39 @@ bool PlaylistSearch::Component::matches(PlaylistItem *item)
}
for(ColumnList::Iterator it = m_columns.begin(); it != m_columns.end(); ++it) {
int matches = m_re ? item->text(*it).contains(m_queryRe)
: item->text(*it).contains(m_query, m_caseSensitive);
if(matches > 0)
return true;
bool match = false;
for(ColumnList::Iterator it = m_columns.begin(); !match && it != m_columns.end(); ++it) {
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:
class PlaylistSearch::Component
{
public:
enum MatchMode { Contains = 0, Exact = 1, ContainsWord = 2 };
/**
* Create an empty search component. This is only provided for use by
* QValueList and should not be used in any other context.
......@@ -83,7 +85,8 @@ public:
*/
Component(const QString &query,
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.
......@@ -102,6 +105,7 @@ private:
QString m_query;
QRegExp m_queryRe;
ColumnList m_columns;
MatchMode m_mode;
bool m_searchAllVisible;
bool m_caseSensitive;
bool m_re;
......
......@@ -233,7 +233,7 @@ void TreeViewMode::setupCategory(const QString &searchCategory, const QStringLis
for(QStringList::ConstIterator it = members.begin(); it != members.end(); ++it) {
PlaylistSearch::ComponentList components;
components.append(PlaylistSearch::Component(*it, false, columns));
components.append(PlaylistSearch::Component(*it, false, columns, PlaylistSearch::Component::ContainsWord));
PlaylistList playlists;
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