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