94 */ |
94 */ |
95 void HsSearchFilterProxyModel::setFilterString(const QString &filterCriteria) |
95 void HsSearchFilterProxyModel::setFilterString(const QString &filterCriteria) |
96 { |
96 { |
97 mInSettingFilterString = true; |
97 mInSettingFilterString = true; |
98 mFilterCriteria = filterCriteria; |
98 mFilterCriteria = filterCriteria; |
99 setFilterRegExp( |
99 filterChanged(); |
100 QRegExp("(^|\\b)" + filterCriteria, Qt::CaseInsensitive)); |
|
101 mInSettingFilterString = false; |
100 mInSettingFilterString = false; |
102 } |
101 } |
103 |
102 |
104 QString HsSearchFilterProxyModel::filterString() const |
103 QString HsSearchFilterProxyModel::filterString() const |
105 { |
104 { |
111 The filterAcceptsRow method is overridden to send a dataChanged signal |
110 The filterAcceptsRow method is overridden to send a dataChanged signal |
112 to the list view item |
111 to the list view item |
113 \param source_row row in source model. |
112 \param source_row row in source model. |
114 \param source_parent source parent index. |
113 \param source_parent source parent index. |
115 */ |
114 */ |
116 bool HsSearchFilterProxyModel::filterAcceptsRow (int source_row, |
115 bool HsSearchFilterProxyModel::filterAcceptsRow (int sourceRow, |
117 const QModelIndex &source_parent) const |
116 const QModelIndex &sourceParent) const |
118 { |
117 { |
119 bool retVal = QSortFilterProxyModel::filterAcceptsRow(source_row, |
118 bool retVal = false; |
120 source_parent); |
119 QModelIndex sourceIndex = sourceModel()->index(sourceRow, filterKeyColumn(), sourceParent); |
|
120 QString key = sourceModel()->data(sourceIndex, filterRole()).toString(); |
|
121 QStringList words = key.split(QRegExp("\\s+", Qt::CaseInsensitive)); |
|
122 for (int i = 0 ; i < words.count() ; ++ i) { |
|
123 if (words[i].indexOf(mFilterCriteria, 0, Qt::CaseInsensitive) == 0) { |
|
124 retVal = true; |
|
125 break; |
|
126 } |
|
127 } |
|
128 |
121 if (mInSettingFilterString && retVal) { |
129 if (mInSettingFilterString && retVal) { |
122 QModelIndex mi = mapFromSource(sourceModel()->index(source_row, 0, |
130 QModelIndex mi = mapFromSource(sourceModel()->index(sourceRow, 0, |
123 source_parent)); |
131 sourceParent)); |
124 emit const_cast<HsSearchFilterProxyModel*>(this)->dataChanged(mi, mi); |
132 emit const_cast<HsSearchFilterProxyModel*>(this)->dataChanged(mi, mi); |
125 } |
133 } |
126 return retVal; |
134 return retVal; |
127 } |
135 } |
128 |
136 |