File indexing completed on 2024-05-19 04:49:51
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #include "SearchProxy.h" 0019 0020 namespace Playlist 0021 { 0022 0023 SearchProxy::SearchProxy( AbstractModel *belowModel, QObject *parent ) 0024 : ProxyBase( belowModel, parent ) 0025 , m_currentSearchFields( 0 ) 0026 { 0027 } 0028 0029 SearchProxy::~SearchProxy() 0030 {} 0031 0032 int 0033 SearchProxy::find( const QString & searchTerm, int searchFields ) 0034 { 0035 ProxyBase::find( searchTerm, searchFields ); 0036 0037 m_currentSearchTerm = searchTerm; 0038 m_currentSearchFields = searchFields; 0039 0040 for( int row = 0; row < rowCount(); row++ ) 0041 { 0042 if( rowMatch( row, searchTerm, searchFields ) ) 0043 return row; 0044 } 0045 return -1; 0046 } 0047 0048 int 0049 SearchProxy::findNext( const QString & searchTerm, int selectedRow, int searchFields ) 0050 { 0051 m_currentSearchTerm = searchTerm; 0052 m_currentSearchFields = searchFields; 0053 int firstMatch = -1; 0054 0055 for( int row = 0; row < rowCount(); row++ ) 0056 { 0057 if( rowMatch( row, searchTerm, searchFields ) ) 0058 { 0059 if( firstMatch == -1 ) 0060 firstMatch = row; 0061 if( row > selectedRow ) 0062 return row; 0063 } 0064 } 0065 // We have searched through everything without finding anything that matched _below_ 0066 // the selected index. So we return the first one found above it (wrap around). 0067 return firstMatch; 0068 } 0069 0070 int 0071 SearchProxy::findPrevious( const QString & searchTerm, int selectedRow, int searchFields ) 0072 { 0073 m_currentSearchTerm = searchTerm; 0074 m_currentSearchFields = searchFields; 0075 int lastMatch = -1; 0076 0077 for( int row = rowCount() - 1; row >= 0; row-- ) 0078 { 0079 if( rowMatch( row, searchTerm, searchFields ) ) 0080 { 0081 if( lastMatch == -1 ) 0082 lastMatch = row; 0083 if( row < selectedRow ) 0084 return row; 0085 } 0086 } 0087 0088 // We have searched through everything without finding anything that matched _above_ 0089 // the selected index. So we return the first one found above it (wrap around). 0090 return lastMatch; 0091 } 0092 0093 void 0094 SearchProxy::clearSearchTerm() 0095 { 0096 m_currentSearchTerm.clear(); 0097 m_currentSearchFields = 0; 0098 0099 m_belowModel->clearSearchTerm(); 0100 } 0101 0102 } //namespace Playlist