14 * Description: LocationPickerSearchView implementation |
14 * Description: LocationPickerSearchView implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <HbListViewItem> |
18 #include <HbListViewItem> |
19 #include <QGraphicsLinearLayout> |
|
20 #include <QStandardItemModel> |
19 #include <QStandardItemModel> |
21 #include <HbSearchPanel> |
20 #include <HbSearchPanel> |
22 #include <HbListView> |
21 #include <HbListView> |
|
22 #include <HbTextItem> |
|
23 #include <HbDocumentLoader> |
|
24 #include <QGraphicsLinearLayout> |
23 |
25 |
24 #include "locationpickerproxymodel.h" |
26 #include "locationpickerproxymodel.h" |
25 #include "locationpickersearchview.h" |
27 #include "locationpickersearchview.h" |
26 #include "locationpickerdatamanager.h" |
28 #include "locationpickerdatamanager.h" |
27 #include "locationpickerappwindow.h" |
|
28 |
29 |
29 // ======== MEMBER FUNCTIONS ======== |
30 // ======== MEMBER FUNCTIONS ======== |
30 |
31 |
31 // ---------------------------------------------------- |
32 // ---------------------------------------------------- |
32 // LocationPickerSearchView::LocationPickerSearchView() |
33 // LocationPickerSearchView::LocationPickerSearchView() |
33 // ---------------------------------------------------- |
34 // ---------------------------------------------------- |
34 LocationPickerSearchView::LocationPickerSearchView( LocationPickerAppWindow *aWindow, QGraphicsItem* aParent ): |
35 LocationPickerSearchView::LocationPickerSearchView(HbDocumentLoader &aLoader) |
35 HbView( aParent ), |
36 :mProxyModel(NULL), |
36 mSearchPanel(new HbSearchPanel(this)) |
37 mModel(NULL), |
|
38 mListView(NULL), |
|
39 mSearchPanel(NULL), |
|
40 mDataManager(NULL), |
|
41 mEmptyLabel(NULL), |
|
42 mVerticalLayout(NULL), |
|
43 mDocumentLoader(aLoader) |
|
44 { |
37 |
45 |
|
46 } |
|
47 // ---------------------------------------------------- |
|
48 // LocationPickerSearchView::~LocationPickerSearchView() |
|
49 // ---------------------------------------------------- |
|
50 LocationPickerSearchView::~LocationPickerSearchView() |
38 { |
51 { |
|
52 if( mDataManager ) |
|
53 delete mDataManager; |
|
54 delete mProxyModel; |
|
55 delete mModel; |
|
56 delete mEmptyLabel; |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------- |
|
60 // LocationPickerSearchView::init() |
|
61 // ---------------------------------------------------- |
|
62 void LocationPickerSearchView::init() |
|
63 { |
|
64 //get listview from docml |
|
65 mListView = qobject_cast<HbListView*>( |
|
66 mDocumentLoader.findObject(QString("SearchListView"))); |
|
67 if(mListView == NULL) |
|
68 { |
|
69 qFatal("Error Reading Docml"); |
|
70 } |
|
71 //get search panel from docml |
|
72 mSearchPanel = qobject_cast<HbSearchPanel*>( |
|
73 mDocumentLoader.findObject(QString("searchPanel"))); |
|
74 if(mListView == NULL) |
|
75 { |
|
76 qFatal("Error Reading Docml"); |
|
77 } |
|
78 //conect to respective slots |
|
79 connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated |
|
80 (const QModelIndex &))); |
|
81 connect(mSearchPanel, SIGNAL(exitClicked()),this, SLOT(handleExit())); |
|
82 connect(mSearchPanel,SIGNAL(criteriaChanged(QString)),this,SLOT(doSearch(QString))); |
39 |
83 |
40 mWindow = aWindow; |
|
41 //Create a linear layout |
|
42 mLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
43 |
|
44 // create the list view |
|
45 mListView=new HbListView(); |
|
46 connect(mListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &))); |
|
47 |
|
48 //Set graphics size for the list items. |
84 //Set graphics size for the list items. |
49 HbListViewItem *hbListItem = new HbListViewItem(); |
85 HbListViewItem *hbListItem = new HbListViewItem(); |
50 hbListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
86 hbListItem->setGraphicsSize(HbListViewItem::Thumbnail); |
51 mListView->setItemPrototype( hbListItem ); |
87 mListView->setItemPrototype( hbListItem ); |
52 |
88 |
53 // Create a standard model for the view list |
89 // Create a standard model for the view list |
54 mModel = new QStandardItemModel(); |
90 mModel = new QStandardItemModel(this); |
55 // create a data manager to populate the model |
91 // create a data manager to populate the model |
56 mDataManager = new LocationPickerDataManager( *mModel, ELocationPickerSearchView ); |
92 mDataManager = new LocationPickerDataManager( *mModel, ELocationPickerSearchView ); |
57 |
93 |
58 // Create the proxy model. |
94 // Create the proxy model. |
59 mProxyModel = new LocationPickerProxyModel(); |
95 mProxyModel = new LocationPickerProxyModel( Qt ::Vertical ); |
60 mProxyModel->setSourceModel(mModel); |
96 mProxyModel->setSourceModel(mModel); |
61 mListView->setModel(mProxyModel); |
97 mListView->setModel(mProxyModel); |
62 |
98 |
63 // set filter properties |
99 // set filter properties |
64 mProxyModel->setDynamicSortFilter(TRUE); |
100 mProxyModel->setDynamicSortFilter(TRUE); |
65 mProxyModel->setSortRole(Qt::DisplayRole); |
101 mProxyModel->setSortRole(Qt::DisplayRole); |
66 mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
102 mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
67 |
103 |
68 // populate data |
104 // populate data |
69 mDataManager->populateModel(); |
105 bool populated = mDataManager->populateModel(Qt::Vertical); |
|
106 if(!populated) |
|
107 { |
|
108 // no entries to display. |
|
109 QStandardItem *modelItem = new QStandardItem(); |
|
110 modelItem->setData(QVariant(hbTrId("txt_lint_list_no_location_entries_present")), Qt::DisplayRole); |
|
111 mModel->appendRow( modelItem ); |
|
112 } |
70 |
113 |
71 // sort |
114 // sort |
72 mProxyModel->sort(0, Qt::AscendingOrder); |
115 mProxyModel->sort(0, Qt::AscendingOrder); |
|
116 } |
73 |
117 |
74 // add the list view to layout |
|
75 mLayout->addItem(mListView); |
|
76 |
|
77 // create search panel |
|
78 mSearchPanel->setProgressive(true); |
|
79 mSearchPanel->setSearchOptionsEnabled(false); |
|
80 connect(mSearchPanel,SIGNAL(criteriaChanged(QString)),this,SLOT(doSearch(QString))); |
|
81 |
|
82 // add search panel to the layout |
|
83 mLayout->addItem(mSearchPanel); |
|
84 |
|
85 // setlayout for the view |
|
86 setLayout(mLayout); |
|
87 |
|
88 |
|
89 // create back action |
|
90 mSecondaryBackAction = new HbAction( Hb::BackAction, this ); |
|
91 // add back key action |
|
92 setNavigationAction( mSecondaryBackAction ); |
|
93 connect(mSecondaryBackAction, SIGNAL(triggered()), mWindow, |
|
94 SLOT(backButtonTriggered())); |
|
95 |
|
96 |
|
97 } |
|
98 // ---------------------------------------------------- |
118 // ---------------------------------------------------- |
99 // LocationPickerSearchView::~LocationPickerSearchView() |
119 // LocationPickerSearchView::handleExit() |
100 // ---------------------------------------------------- |
120 // ---------------------------------------------------- |
101 LocationPickerSearchView::~LocationPickerSearchView() |
121 void LocationPickerSearchView::handleExit() |
102 { |
122 { |
103 // delete mDataManager |
123 //emit signal to switch the current view |
104 if( mDataManager ) |
124 emit switchView(); |
105 delete mDataManager; |
|
106 } |
125 } |
107 |
126 |
108 // ---------------------------------------------------- |
127 // ---------------------------------------------------- |
109 // LocationPickerSearchView::doSearch() |
128 // LocationPickerSearchView::doSearch() |
110 // ---------------------------------------------------- |
129 // ---------------------------------------------------- |
111 void LocationPickerSearchView::doSearch(QString aCriteria) |
130 void LocationPickerSearchView::doSearch(QString aCriteria) |
112 { |
131 { |
113 // use the string to search |
132 // use the string to search |
114 mProxyModel->filterParameterChanged(aCriteria); |
133 mProxyModel->filterParameterChanged(aCriteria); |
115 mProxyModel->setFilterFixedString(aCriteria); |
134 mProxyModel->setFilterFixedString(aCriteria); |
|
135 //if no entries presentdisplay empty text item |
|
136 if (!mProxyModel->rowCount() ) |
|
137 { |
|
138 if(!mEmptyLabel) |
|
139 { |
|
140 QGraphicsWidget *widget = NULL; |
|
141 widget = mDocumentLoader.findWidget(QString("container")); |
|
142 if(widget == NULL) |
|
143 { |
|
144 qFatal("Error Reading Docml"); |
|
145 } |
|
146 mVerticalLayout = static_cast<QGraphicsLinearLayout*>(widget->layout()); |
|
147 if(mVerticalLayout == NULL) |
|
148 { |
|
149 qFatal("Error Reading Docml"); |
|
150 } |
|
151 mVerticalLayout->removeItem(mListView); |
|
152 mListView->setVisible(false); |
|
153 mEmptyLabel = new HbTextItem(hbTrId("txt_lint_list_no_results")); |
|
154 mEmptyLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
|
155 mEmptyLabel->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
156 mEmptyLabel->setAlignment(Qt::AlignCenter); |
|
157 mVerticalLayout->insertItem(0, mEmptyLabel); |
|
158 mEmptyLabel->setVisible(true); |
|
159 } |
|
160 } |
|
161 //else display the result |
|
162 else if (mEmptyLabel) |
|
163 { |
|
164 mVerticalLayout->removeItem(mEmptyLabel); |
|
165 mEmptyLabel->setVisible(false); |
|
166 delete mEmptyLabel; |
|
167 mEmptyLabel=NULL; |
|
168 mVerticalLayout->insertItem(0, mListView); |
|
169 mListView->setVisible(true); |
|
170 } |
116 } |
171 } |
117 |
172 |
118 // ---------------------------------------------------- |
173 // ---------------------------------------------------- |
119 // LocationPickerSearchView::handleActivated() |
174 // LocationPickerSearchView::handleActivated() |
120 // ---------------------------------------------------- |
175 // ---------------------------------------------------- |
121 void LocationPickerSearchView::handleActivated(const QModelIndex &aIndex) |
176 void LocationPickerSearchView::handleActivated(const QModelIndex &aIndex) |
122 { |
177 { |
123 QModelIndex index = mProxyModel->mapToSource(aIndex); |
178 QModelIndex index = mProxyModel->mapToSource(aIndex); |
124 quint32 lm = 0; |
179 quint32 lm = 0; |
125 mDataManager->getData( index.row(), lm ); |
180 mDataManager->getData( index.row(), lm ); |
126 mWindow->itemSelected( lm ); |
181 //emit item is selectedsignal |
|
182 emit selectItem( lm ); |
127 } |
183 } |
128 |
184 |