|
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: LocationPickerContent implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QStandardItemModel> |
|
19 |
|
20 #include "locationpickercontent.h" |
|
21 #include "locationpickerproxymodel.h" |
|
22 #include "locationpickertypes.h" |
|
23 #include "locationpickerdatamanager.h" |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // LocationPickerContent::LocationPickerContent() |
|
29 // ----------------------------------------------------------------------------- |
|
30 LocationPickerContent::LocationPickerContent( Qt::Orientation aOrientation ) |
|
31 :mOrientation(aOrientation), |
|
32 mListProxyModel(NULL), |
|
33 mProxyGridModel(NULL), |
|
34 mDataManager(NULL), |
|
35 mModel(NULL), |
|
36 mLocationsFound(true) |
|
37 { |
|
38 // Create a standard model for the list view |
|
39 mModel = new QStandardItemModel( this ); |
|
40 // create data manager to manage data in the model |
|
41 mDataManager = new LocationPickerDataManager( *mModel, ELocationPickerContent ); |
|
42 if(mOrientation == Qt::Vertical) |
|
43 { |
|
44 if( mDataManager->populateModel(mOrientation) ) |
|
45 { |
|
46 // Create the proxy model and set source model |
|
47 mListProxyModel = new LocationPickerProxyModel( mOrientation, this ); |
|
48 mListProxyModel->setSourceModel(mModel); |
|
49 // set sort properties |
|
50 mListProxyModel->setDynamicSortFilter(TRUE); |
|
51 mListProxyModel->setSortRole(Qt::DisplayRole); |
|
52 mListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
53 |
|
54 // sort in ascending order |
|
55 mListProxyModel->sort(0, Qt::AscendingOrder); |
|
56 mLocationsFound = true; |
|
57 } |
|
58 else |
|
59 { |
|
60 // no locations to display. |
|
61 QStandardItem *modelItem = new QStandardItem(); |
|
62 modelItem->setData(QVariant(hbTrId("txt_lint_list_no_location_entries_present")), Qt::DisplayRole); |
|
63 mModel->appendRow( modelItem ); |
|
64 mLocationsFound = false; |
|
65 } |
|
66 } |
|
67 //for landscape view |
|
68 else |
|
69 { |
|
70 if( mDataManager->populateModel(mOrientation) ) |
|
71 { |
|
72 // Create the proxy model and set source model |
|
73 mProxyGridModel = new LocationPickerProxyModel( mOrientation , this ); |
|
74 mProxyGridModel->setSourceModel(mModel); |
|
75 // set sort properties |
|
76 mProxyGridModel->setDynamicSortFilter(TRUE); |
|
77 mProxyGridModel->setSortRole(Qt::DisplayRole); |
|
78 mProxyGridModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
79 |
|
80 // sort in ascending order |
|
81 mProxyGridModel->sort(0, Qt::AscendingOrder); |
|
82 mLocationsFound = true; |
|
83 } |
|
84 else |
|
85 { |
|
86 // no locations to display. |
|
87 QStandardItem *modelItem = new QStandardItem(); |
|
88 modelItem->setData(QVariant(hbTrId("txt_lint_list_no_location_entries_present")), Qt::DisplayRole); |
|
89 mModel->appendRow( modelItem ); |
|
90 mLocationsFound = false; |
|
91 } |
|
92 } |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // LocationPickerContent::LocationPickerContent() |
|
97 // ----------------------------------------------------------------------------- |
|
98 LocationPickerContent::~LocationPickerContent() |
|
99 { |
|
100 // delete data manager |
|
101 if( mDataManager ) |
|
102 delete mDataManager; |
|
103 delete mProxyGridModel; |
|
104 delete mListProxyModel; |
|
105 delete mModel; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // LocationPickerContent::locationsFound() |
|
110 // ----------------------------------------------------------------------------- |
|
111 bool LocationPickerContent::locationsFound() |
|
112 { |
|
113 return mLocationsFound; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // LocationPickerContent::getListProxyModel() |
|
118 // ----------------------------------------------------------------------------- |
|
119 LocationPickerProxyModel* LocationPickerContent::getListProxyModel() |
|
120 { |
|
121 return mListProxyModel; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // LocationPickerContent::getStandardModel() |
|
126 // ----------------------------------------------------------------------------- |
|
127 QStandardItemModel* LocationPickerContent::getStandardModel() |
|
128 { |
|
129 return mModel; |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // LocationPickerContent::getDataManager() |
|
134 // ----------------------------------------------------------------------------- |
|
135 LocationPickerDataManager* LocationPickerContent::getDataManager() |
|
136 { |
|
137 return mDataManager; |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // LocationPickerContent::getGridProxyModel() |
|
142 // ----------------------------------------------------------------------------- |
|
143 LocationPickerProxyModel* LocationPickerContent::getGridProxyModel() |
|
144 { |
|
145 return mProxyGridModel; |
|
146 } |