1 /* |
|
2 * Copyright (c) 2010 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: LocationPickerProxyModel implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QStandardItemModel> |
|
19 #include "locationpickerproxymodel.h" |
|
20 |
|
21 // ---------------------------------------------------- |
|
22 // LocationPickerProxyModel::LocationPickerProxyModel() |
|
23 // ---------------------------------------------------- |
|
24 |
|
25 LocationPickerProxyModel::LocationPickerProxyModel( QObject *parent ) |
|
26 :QSortFilterProxyModel(parent) |
|
27 { |
|
28 } |
|
29 |
|
30 // ---------------------------------------------------- |
|
31 // LocationPickerProxyModel::lessThan() |
|
32 // ---------------------------------------------------- |
|
33 bool LocationPickerProxyModel::lessThan( const QModelIndex &left, |
|
34 const QModelIndex &right ) const |
|
35 { |
|
36 // get left and right items data and implement sort logic |
|
37 // return true if left is less than right |
|
38 QVariant leftData = sourceModel()->data(left); |
|
39 QVariant rightData = sourceModel()->data(right); |
|
40 |
|
41 QStringList leftStringList = leftData.toStringList(); |
|
42 |
|
43 QStringList rightStringList = rightData.toStringList(); |
|
44 |
|
45 return QString::compare( QString( leftStringList[0] + " " + leftStringList[1] ), |
|
46 QString( rightStringList[0] + " " + rightStringList[1] ), Qt::CaseInsensitive ) < 0; |
|
47 |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------- |
|
51 // LocationPickerProxyModel::filterAcceptsRow() |
|
52 // ---------------------------------------------------- |
|
53 |
|
54 bool LocationPickerProxyModel::filterAcceptsRow( int sourceRow, |
|
55 const QModelIndex &sourceParent ) const |
|
56 { |
|
57 |
|
58 // implement logic for search. |
|
59 QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); |
|
60 |
|
61 QStringList stringList = sourceModel()->data(index0).toStringList(); |
|
62 QString fullString = " " + stringList[0] + " " + stringList[1]; |
|
63 |
|
64 return (fullString.contains(mSearchText, Qt::CaseInsensitive)); |
|
65 |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------- |
|
69 // LocationPickerProxyModel::filterParameterChanged() |
|
70 // ---------------------------------------------------- |
|
71 void LocationPickerProxyModel::filterParameterChanged( QString aSearchText ) |
|
72 { |
|
73 mSearchText = " " + aSearchText; |
|
74 } |
|