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: LocationPickerView implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "locationpickerpotraitview.h" |
|
19 |
|
20 #include <HbMainWindow> |
|
21 #include <qstandarditemmodel.h> |
|
22 #include <HbListView> |
|
23 #include <HbListViewItem> |
|
24 #include <HbAction> |
|
25 |
|
26 #include "locationpickerproxymodel.h" |
|
27 #include "locationpickerdatamanager.h" |
|
28 #include "locationpickercontent.h" |
|
29 #include "locationpickercollectionlistcontent.h" |
|
30 #include "locationpickercollectioncontent.h" |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // ---------------------------------------------------- |
|
35 // LocationPickerPotraitView::LocationPickerView() |
|
36 // ---------------------------------------------------- |
|
37 LocationPickerPotraitView::LocationPickerPotraitView( HbDocumentLoader* aLoader ) |
|
38 :mDocumentLoader(aLoader), |
|
39 mLocationPickerCollectionListContent(NULL), |
|
40 mProxyModel(NULL), |
|
41 mAllAction(NULL), |
|
42 mCollectionAction(NULL), |
|
43 mSearchAction(NULL), |
|
44 mAscendingAction(NULL), |
|
45 mDescendingAction(NULL), |
|
46 mListView(NULL), |
|
47 mCollectionContent(NULL), |
|
48 mViewType(ELocationPickerContent) |
|
49 { |
|
50 // create back action |
|
51 mPotraitBackAction = new HbAction(Hb::BackNaviAction); |
|
52 // add back key action |
|
53 setNavigationAction(mPotraitBackAction); |
|
54 //connect to slots |
|
55 connect(mPotraitBackAction, SIGNAL(triggered()), this, |
|
56 SLOT(backTriggered())); |
|
57 //create list item |
|
58 mListItem = new HbListViewItem(); |
|
59 //set the graphics size |
|
60 mListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
|
61 } |
|
62 // ---------------------------------------------------- |
|
63 // LocationPickerPotraitView::~LocationPickerView() |
|
64 // ---------------------------------------------------- |
|
65 LocationPickerPotraitView::~LocationPickerPotraitView() |
|
66 { |
|
67 delete mCollectionContent; |
|
68 delete mLocationPickerCollectionListContent; |
|
69 delete mAllAction; |
|
70 delete mCollectionAction; |
|
71 delete mAscendingAction; |
|
72 delete mDescendingAction; |
|
73 delete mListView; |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // LocationPickerPotraitView::backButtonTriggered() |
|
78 // ---------------------------------------------------------------------------- |
|
79 void LocationPickerPotraitView::backTriggered() |
|
80 { |
|
81 //if current model is collection content, go back to collectionlist content |
|
82 if(mViewType == ELocationPickerCollectionContent) |
|
83 { |
|
84 colectionTabTriggered(); |
|
85 emit collectionContentExited(); |
|
86 } |
|
87 else |
|
88 { |
|
89 //complete the service |
|
90 emit completeService(); |
|
91 } |
|
92 } |
|
93 |
|
94 |
|
95 // ---------------------------------------------------- |
|
96 // LocationPickerPotraitView::init() |
|
97 // ---------------------------------------------------- |
|
98 void LocationPickerPotraitView::init( bool aPopulated, Qt::Orientation aOrientation, QStandardItemModel *aModel ) |
|
99 { |
|
100 mModel = aModel; |
|
101 if(aPopulated) |
|
102 { |
|
103 // Create Collection List Content |
|
104 mLocationPickerCollectionListContent = new LocationPickerCollectionListContent(aOrientation); |
|
105 //create proxy model |
|
106 mProxyModel = new LocationPickerProxyModel( aOrientation , this ); |
|
107 mProxyModel->setSourceModel(aModel); |
|
108 // set sort properties |
|
109 mProxyModel->setDynamicSortFilter(TRUE); |
|
110 mProxyModel->setSortRole(Qt::DisplayRole); |
|
111 mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
112 // sort in ascending order |
|
113 mProxyModel->sort(0, Qt::AscendingOrder); |
|
114 } |
|
115 //Get HbAction items |
|
116 mListView = qobject_cast<HbListView*> (mDocumentLoader->findObject(QString( |
|
117 "ListView"))); |
|
118 //get the action items from docml |
|
119 mAllAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(QString( |
|
120 "allAction"))); |
|
121 mCollectionAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
122 QString("collectionAction"))); |
|
123 mSearchAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(QString( |
|
124 "searchAction"))); |
|
125 mAscendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
126 QString("ascendingAction"))); |
|
127 mDescendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject( |
|
128 QString("descendingAction"))); |
|
129 if( !mAllAction || !mCollectionAction || !mSearchAction || !mAscendingAction || !mDescendingAction || !mListView) |
|
130 { |
|
131 qFatal("Error Reading Docml"); |
|
132 } |
|
133 |
|
134 //connect to slots |
|
135 connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); |
|
136 connect(mDescendingAction, SIGNAL(triggered()), this, |
|
137 SLOT(sortDescending())); |
|
138 //connect all action Items to respective slots |
|
139 connect(mAllAction, SIGNAL(triggered()), this, SLOT(allTabTriggered())); |
|
140 connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered())); |
|
141 connect(mSearchAction, SIGNAL(triggered()), this, |
|
142 SLOT(searchTabTriggered())); |
|
143 // connect the signal of the list activated to a slot. |
|
144 connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &))); |
|
145 } |
|
146 |
|
147 void LocationPickerPotraitView::manageListView() |
|
148 { |
|
149 //set the appropriate model |
|
150 switch(mViewType) |
|
151 { |
|
152 case ELocationPickerContent: |
|
153 { |
|
154 mListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
|
155 mListView->setModel(mProxyModel,mListItem); |
|
156 mAllAction->setChecked(true); |
|
157 mCollectionAction->setChecked(false); |
|
158 mViewType = ELocationPickerContent; |
|
159 } |
|
160 break; |
|
161 case ELocationPickerCollectionListContent: |
|
162 { |
|
163 mListItem->setGraphicsSize(HbListViewItem::MediumIcon); |
|
164 mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem); |
|
165 mCollectionAction->setChecked(true); |
|
166 mAllAction->setChecked(false); |
|
167 mViewType = ELocationPickerCollectionListContent; |
|
168 } |
|
169 break; |
|
170 case ELocationPickerCollectionContent: |
|
171 { |
|
172 setCollectionData(mCategoryId); |
|
173 mCollectionAction->setChecked(true); |
|
174 mAllAction->setChecked(false); |
|
175 mViewType = ELocationPickerCollectionContent; |
|
176 } |
|
177 break; |
|
178 default: |
|
179 break; |
|
180 } |
|
181 } |
|
182 |
|
183 |
|
184 void LocationPickerPotraitView::disableTabs( QStandardItemModel *aModel ) |
|
185 { |
|
186 //if no location entries present |
|
187 mListView->setModel(aModel,mListItem); |
|
188 mAllAction->setDisabled(true); |
|
189 mCollectionAction->setDisabled(true); |
|
190 mSearchAction->setDisabled(true); |
|
191 mAscendingAction->setDisabled(true); |
|
192 mDescendingAction->setDisabled(true); |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // LocationPickerView::handleActivated() |
|
197 // ----------------------------------------------------------------------------- |
|
198 void LocationPickerPotraitView::handleActivated( const QModelIndex &aIndex ) |
|
199 { |
|
200 //handle the activated signal according to model set |
|
201 switch(mViewType) |
|
202 { |
|
203 case ELocationPickerContent: |
|
204 { |
|
205 if(!mProxyModel) |
|
206 { |
|
207 break; |
|
208 } |
|
209 QModelIndex index = mProxyModel->mapToSource( |
|
210 aIndex); |
|
211 quint32 lm = 0; |
|
212 QStandardItem* item = mModel->item( index.row(), index.column() ); |
|
213 QVariant var = item->data( Qt::UserRole ); |
|
214 lm = var.toUInt(); |
|
215 //item selected, complete request |
|
216 emit selectItem( lm ); |
|
217 } |
|
218 break; |
|
219 case ELocationPickerCollectionListContent: |
|
220 { |
|
221 mLocationPickerCollectionListContent->getData( |
|
222 aIndex, mCategoryId ); |
|
223 mViewType = ELocationPickerCollectionContent; |
|
224 //send categoryID to set the collection content |
|
225 emit sendCategoryID(mCategoryId); |
|
226 } |
|
227 break; |
|
228 case ELocationPickerCollectionContent: |
|
229 { |
|
230 if(!mCollectionContent->getProxyModel()) |
|
231 { |
|
232 break; |
|
233 } |
|
234 QModelIndex index = mCollectionContent->getProxyModel()->mapToSource( |
|
235 aIndex); |
|
236 quint32 lm = 0; |
|
237 mCollectionContent->getData(index, lm); |
|
238 //item selected, complete request |
|
239 emit selectItem(lm); |
|
240 } |
|
241 break; |
|
242 default: |
|
243 break; |
|
244 } |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // LocationPickerView::sortAscending() |
|
249 // ----------------------------------------------------------------------------- |
|
250 void LocationPickerPotraitView::sortAscending() |
|
251 { |
|
252 //check the model set and do sorting accordingly |
|
253 if (mViewType == ELocationPickerContent) |
|
254 { |
|
255 mProxyModel->sort(0, Qt::AscendingOrder); |
|
256 } |
|
257 else |
|
258 { |
|
259 mCollectionContent->getProxyModel()->sort(0, Qt::AscendingOrder); |
|
260 } |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // LocationPickerView::sortDescending() |
|
265 // ----------------------------------------------------------------------------- |
|
266 void LocationPickerPotraitView::sortDescending() |
|
267 { |
|
268 //check the model set and do sorting accordingly |
|
269 if (mViewType == ELocationPickerContent) |
|
270 { |
|
271 mProxyModel->sort(0, Qt::DescendingOrder); |
|
272 } |
|
273 else |
|
274 { |
|
275 mCollectionContent->getProxyModel()->sort(0, Qt::DescendingOrder); |
|
276 } |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // LocationPickerView::handleAllTab() |
|
281 // ----------------------------------------------------------------------------- |
|
282 void LocationPickerPotraitView::allTabTriggered() |
|
283 { |
|
284 //execute only if tab is not pressed |
|
285 if (mAllAction->isChecked()) |
|
286 { |
|
287 mViewType = ELocationPickerContent; |
|
288 if(this->mainWindow()->orientation() == Qt::Horizontal) |
|
289 { |
|
290 //if in landscape send signal to launch grid view |
|
291 emit handleAllList(); |
|
292 } |
|
293 else |
|
294 { |
|
295 mListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
|
296 mListView->setModel(mProxyModel,mListItem); |
|
297 mCollectionAction->setChecked(false); |
|
298 } |
|
299 mAscendingAction->setEnabled(true); |
|
300 mDescendingAction->setEnabled(true); |
|
301 //delete mCollectionContent if coming back from collectioncontent |
|
302 if (mCollectionContent) |
|
303 { |
|
304 delete mCollectionContent; |
|
305 mCollectionContent = NULL; |
|
306 } |
|
307 } |
|
308 else |
|
309 { |
|
310 //Keep the tab pressed |
|
311 mAllAction->setChecked(true); |
|
312 } |
|
313 |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // LocationPickerView::handleCollectionTab() |
|
318 // ----------------------------------------------------------------------------- |
|
319 void LocationPickerPotraitView::colectionTabTriggered() |
|
320 { |
|
321 //execute only if tab is not pressed |
|
322 if (mCollectionAction->isChecked()) |
|
323 { |
|
324 mListItem->setGraphicsSize(HbListViewItem::MediumIcon); |
|
325 mListView->setModel(mLocationPickerCollectionListContent->getStandardModel(),mListItem); |
|
326 mAscendingAction->setDisabled(true); |
|
327 mDescendingAction->setDisabled(true); |
|
328 mAllAction->setChecked(false); |
|
329 mViewType = ELocationPickerCollectionListContent; |
|
330 } |
|
331 else |
|
332 { |
|
333 //Keep the tab pressed |
|
334 mCollectionAction->setChecked(true); |
|
335 } |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // LocationPickerView::searchTabTriggered() |
|
340 // ----------------------------------------------------------------------------- |
|
341 void LocationPickerPotraitView::searchTabTriggered() |
|
342 { |
|
343 emit switchToSearchView(); |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // LocationPickerView::setCollectionData() |
|
348 // ----------------------------------------------------------------------------- |
|
349 void LocationPickerPotraitView::setCollectionData( quint32 acategoryId ) |
|
350 { |
|
351 |
|
352 if(!mCollectionContent) |
|
353 { |
|
354 mCollectionContent |
|
355 = new LocationPickerCollectionContent(Qt::Vertical , acategoryId); |
|
356 } |
|
357 mListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
|
358 if(mCollectionContent->locationFound()) |
|
359 { |
|
360 mListView->setModel(mCollectionContent->getProxyModel(),mListItem); |
|
361 } |
|
362 else |
|
363 { |
|
364 mListView->setModel(mCollectionContent->getStandardModel(),mListItem); |
|
365 } |
|
366 mViewType = ELocationPickerCollectionContent; |
|
367 //Enable the options |
|
368 mAscendingAction->setEnabled(true); |
|
369 mDescendingAction->setEnabled(true); |
|
370 mCollectionAction->setChecked(true); |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // LocationPickerView::setCategoryID() |
|
375 // ----------------------------------------------------------------------------- |
|
376 void LocationPickerPotraitView::setCategoryID( quint32 aCategoryId ) |
|
377 { |
|
378 mCategoryId = aCategoryId; |
|
379 } |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // LocationPickerView::getViewType() |
|
383 // ----------------------------------------------------------------------------- |
|
384 TViewType LocationPickerPotraitView::getViewType() |
|
385 { |
|
386 return mViewType; |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // LocationPickerView::setViewType() |
|
391 // ----------------------------------------------------------------------------- |
|
392 void LocationPickerPotraitView::setViewType(TViewType aViewType) |
|
393 { |
|
394 mViewType = aViewType; |
|
395 } |
|
396 |
|
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 // LocationPickerView::clearContentModel() |
|
400 // ----------------------------------------------------------------------------- |
|
401 void LocationPickerPotraitView::clearContentModel() |
|
402 { |
|
403 if(mCollectionContent) |
|
404 { |
|
405 delete mCollectionContent; |
|
406 mCollectionContent = NULL; |
|
407 } |
|
408 } |
|
409 |
|