20 |
20 |
21 // ---------------------------------------------------- |
21 // ---------------------------------------------------- |
22 // LocationPickerProxyModel::LocationPickerProxyModel() |
22 // LocationPickerProxyModel::LocationPickerProxyModel() |
23 // ---------------------------------------------------- |
23 // ---------------------------------------------------- |
24 |
24 |
25 LocationPickerProxyModel::LocationPickerProxyModel( Qt::Orientations aOrientation , QObject *parent ) |
25 LocationPickerProxyModel::LocationPickerProxyModel( QObject *parent ) |
26 :QSortFilterProxyModel(parent), |
26 :QSortFilterProxyModel(parent) |
27 mOrientation( aOrientation ) |
|
28 { |
27 { |
29 } |
28 } |
30 |
29 |
31 // ---------------------------------------------------- |
30 // ---------------------------------------------------- |
32 // LocationPickerProxyModel::lessThan() |
31 // LocationPickerProxyModel::lessThan() |
34 bool LocationPickerProxyModel::lessThan( const QModelIndex &left, |
33 bool LocationPickerProxyModel::lessThan( const QModelIndex &left, |
35 const QModelIndex &right ) const |
34 const QModelIndex &right ) const |
36 { |
35 { |
37 // get left and right items data and implement sort logic |
36 // get left and right items data and implement sort logic |
38 // return true if left is less than right |
37 // return true if left is less than right |
39 QVariant leftData = sourceModel()->data(left); |
38 QVariant leftData = sourceModel()->data(left); |
40 QVariant rightData = sourceModel()->data(right); |
39 QVariant rightData = sourceModel()->data(right); |
41 |
40 |
42 if( mOrientation == Qt::Vertical ) |
41 QStringList leftStringList = leftData.toStringList(); |
43 { |
|
44 QStringList leftStringList = leftData.toStringList(); |
|
45 |
42 |
46 QStringList rightStringList = rightData.toStringList(); |
43 QStringList rightStringList = rightData.toStringList(); |
47 |
44 |
48 return QString::compare( QString( leftStringList[0] + " " + leftStringList[1] ), |
45 return QString::compare( QString( leftStringList[0] + " " + leftStringList[1] ), |
49 QString( rightStringList[0] + " " + rightStringList[1] ), Qt::CaseInsensitive ) < 0; |
46 QString( rightStringList[0] + " " + rightStringList[1] ), Qt::CaseInsensitive ) < 0; |
50 } |
|
51 else |
|
52 { |
|
53 QString leftString = leftData.toString(); |
|
54 |
47 |
55 QString rightString = rightData.toString(); |
|
56 |
|
57 return QString::compare( leftString, rightString, Qt::CaseInsensitive ) < 0; |
|
58 } |
|
59 } |
48 } |
60 |
49 |
61 // ---------------------------------------------------- |
50 // ---------------------------------------------------- |
62 // LocationPickerProxyModel::filterAcceptsRow() |
51 // LocationPickerProxyModel::filterAcceptsRow() |
63 // ---------------------------------------------------- |
52 // ---------------------------------------------------- |
64 |
53 |
65 bool LocationPickerProxyModel::filterAcceptsRow( int sourceRow, |
54 bool LocationPickerProxyModel::filterAcceptsRow( int sourceRow, |
66 const QModelIndex &sourceParent ) const |
55 const QModelIndex &sourceParent ) const |
67 { |
56 { |
68 if( mOrientation == Qt::Vertical) |
57 |
69 { |
|
70 // implement logic for search. |
58 // implement logic for search. |
71 QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); |
59 QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); |
72 |
60 |
73 QStringList stringList = sourceModel()->data(index0).toStringList(); |
61 QStringList stringList = sourceModel()->data(index0).toStringList(); |
74 QString fullString = " " + stringList[0] + " " + stringList[1]; |
62 QString fullString = " " + stringList[0] + " " + stringList[1]; |
75 |
63 |
76 return (fullString.contains(mSearchText, Qt::CaseInsensitive)); |
64 return (fullString.contains(mSearchText, Qt::CaseInsensitive)); |
77 } |
65 |
78 else |
|
79 return true; |
|
80 } |
66 } |
81 |
67 |
82 // ---------------------------------------------------- |
68 // ---------------------------------------------------- |
83 // LocationPickerProxyModel::filterParameterChanged() |
69 // LocationPickerProxyModel::filterParameterChanged() |
84 // ---------------------------------------------------- |
70 // ---------------------------------------------------- |