userguide/src/HelpProxyModel.cpp
branchRCL_3
changeset 17 12f60d9a73b3
equal deleted inserted replaced
16:0d1adf67ec1b 17:12f60d9a73b3
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QStringList>
       
    19 #include <QDebug>
       
    20 
       
    21 #include "HelpUtils.h"
       
    22 #include "HelpCommon.h"
       
    23 #include "HelpProxyModel.h"
       
    24 
       
    25 HelpProxyModel::HelpProxyModel(QObject * parent):QSortFilterProxyModel(parent)
       
    26 {
       
    27 }
       
    28 
       
    29 HelpProxyModel::~HelpProxyModel()
       
    30 {
       
    31 }
       
    32 
       
    33 bool HelpProxyModel::filterAcceptsRow(int sourceRow,
       
    34         const QModelIndex &sourceParent) const
       
    35 {
       
    36 	QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
       
    37 
       
    38 	switch(filterRole())
       
    39 	{
       
    40 	case KeywordRole:
       
    41 		{			
       
    42 			QStringList keywordLst = sourceModel()->data(index, KeywordRole).toStringList();
       
    43 
       
    44 			foreach(QString str, keywordLst)
       
    45 			{
       
    46 				if(HelpUtils::findStr(str, filterRegExp().pattern()) != -1)
       
    47 				{
       
    48 					return true;
       
    49 				}
       
    50 			}
       
    51 			return false;
       
    52 		}
       
    53 	case Qt::DisplayRole:
       
    54 		{
       
    55 			QString title = sourceModel()->data(index, Qt::DisplayRole).toString();
       
    56 			if(HelpUtils::findStr(title, filterRegExp().pattern()) != -1)
       
    57 			{
       
    58 				return true;
       
    59 			}
       
    60 			return false;
       
    61 		}
       
    62 	default:
       
    63 		return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
       
    64 	}
       
    65 }