|
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: LocationPickerAllView implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <HbMenu> |
|
19 #include <HbListViewItem> |
|
20 #include <HbAction> |
|
21 #include <HbListView> |
|
22 #include <QStandardItemModel> |
|
23 |
|
24 #include "locationpickerallview.h" |
|
25 #include "locationpickerproxymodel.h" |
|
26 #include "locationpickertypes.h" |
|
27 #include "locationpickerappwindow.h" |
|
28 #include "locationpickerdatamanager.h" |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // LocationPickerAllView::LocationPickerAllView() |
|
34 // ----------------------------------------------------------------------------- |
|
35 LocationPickerAllView::LocationPickerAllView( LocationPickerAppWindow *aWindow, QGraphicsItem* aParent ) |
|
36 : HbView( aParent ) |
|
37 { |
|
38 mWindow = aWindow; |
|
39 |
|
40 // Create a standard model for the view list |
|
41 mModel = new QStandardItemModel( this ); |
|
42 |
|
43 // create the list view and connect the signal |
|
44 mListView=new HbListView( this ); |
|
45 |
|
46 // create data manager to manage data in the model |
|
47 mDataManager = new LocationPickerDataManager( *mModel, ELocationPickerAllView ); |
|
48 if( mDataManager->populateModel() ) |
|
49 { |
|
50 // connect the signal of the list activated to a slot. |
|
51 connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &))); |
|
52 |
|
53 //Creation of List View |
|
54 //Set grahics size for the list items. |
|
55 HbListViewItem *hbListItem = new HbListViewItem(); |
|
56 hbListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
|
57 |
|
58 // Create the proxy model and set source model |
|
59 mProxyModel = new LocationPickerProxyModel( this ); |
|
60 mProxyModel->setSourceModel(mModel); |
|
61 |
|
62 // set proxymodel with list view |
|
63 mListView->setModel(mProxyModel, hbListItem); |
|
64 |
|
65 // set sort properties |
|
66 mProxyModel->setDynamicSortFilter(TRUE); |
|
67 mProxyModel->setSortRole(Qt::DisplayRole); |
|
68 mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
69 |
|
70 // sort in ascending order |
|
71 mProxyModel->sort(0, Qt::AscendingOrder); |
|
72 |
|
73 // construct menu for the view |
|
74 constructMenu(); |
|
75 |
|
76 mLocationsFound = true; |
|
77 } |
|
78 |
|
79 else |
|
80 { |
|
81 // no locations to display. |
|
82 QStandardItem *modelItem = new QStandardItem(); |
|
83 modelItem->setData(QVariant(KNoLocations), Qt::DisplayRole); |
|
84 mModel->appendRow( modelItem ); |
|
85 mListView->setModel(mModel); |
|
86 mLocationsFound = false; |
|
87 } |
|
88 |
|
89 // set the listview as the view's widget |
|
90 setWidget(mListView); |
|
91 |
|
92 // create back action |
|
93 mSecondaryBackAction = new HbAction( Hb::BackAction, this ); |
|
94 // add back key action |
|
95 setNavigationAction( mSecondaryBackAction ); |
|
96 connect(mSecondaryBackAction, SIGNAL(triggered()), mWindow, |
|
97 SLOT(backButtonTriggered())); |
|
98 |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // LocationPickerAllView::LocationPickerAllView() |
|
103 // ----------------------------------------------------------------------------- |
|
104 LocationPickerAllView::~LocationPickerAllView() |
|
105 { |
|
106 // delete data manager |
|
107 if( mDataManager ) |
|
108 delete mDataManager; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // LocationPickerAllView::locationsFound() |
|
113 // ----------------------------------------------------------------------------- |
|
114 bool LocationPickerAllView::locationsFound() |
|
115 { |
|
116 return mLocationsFound; |
|
117 } |
|
118 |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // LocationPickerAllView::constructMenu() |
|
122 // ----------------------------------------------------------------------------- |
|
123 void LocationPickerAllView::constructMenu() |
|
124 { |
|
125 HbMenu *menu = this->menu(); |
|
126 HbMenu *subMenu = menu->addMenu(KSortBy); |
|
127 HbAction *act; |
|
128 |
|
129 act = new HbAction(KAscend, this ); |
|
130 subMenu->addAction(act); |
|
131 connect(act,SIGNAL(triggered()),this,SLOT(sortAscending())); |
|
132 |
|
133 act = subMenu->addAction( KDescend ); |
|
134 connect(act, SIGNAL(triggered()), SLOT(sortDescending())); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // LocationPickerAllView::sortAscending() |
|
139 // ----------------------------------------------------------------------------- |
|
140 void LocationPickerAllView::sortAscending() |
|
141 { |
|
142 mProxyModel->sort(0, Qt::AscendingOrder); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // LocationPickerAllView::sortDescending() |
|
147 // ----------------------------------------------------------------------------- |
|
148 void LocationPickerAllView::sortDescending() |
|
149 { |
|
150 mProxyModel->sort(0, Qt::DescendingOrder); |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // LocationPickerAllView::handleActivated() |
|
155 // ----------------------------------------------------------------------------- |
|
156 void LocationPickerAllView::handleActivated( const QModelIndex &aIndex) |
|
157 { |
|
158 QModelIndex index = mProxyModel->mapToSource(aIndex); |
|
159 quint32 lm = 0; |
|
160 mDataManager->getData( index.row(), lm ); |
|
161 mWindow->itemSelected( lm ); |
|
162 } |