locationpickerservice/src/locationpickersearchview.cpp
changeset 15 13ae750350c9
child 17 0f22fb80ebba
equal deleted inserted replaced
0:522cd55cc3d7 15:13ae750350c9
       
     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: LocationPickerSearchView implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <HbListViewItem>
       
    19 #include <QGraphicsLinearLayout>
       
    20 #include <QStandardItemModel>
       
    21 #include <HbSearchPanel>
       
    22 #include <HbListView>
       
    23 
       
    24 #include "locationpickerproxymodel.h"
       
    25 #include "locationpickersearchview.h"
       
    26 #include "locationpickerdatamanager.h"
       
    27 #include "locationpickerappwindow.h"
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ----------------------------------------------------
       
    32 // LocationPickerSearchView::LocationPickerSearchView()
       
    33 // ----------------------------------------------------
       
    34 LocationPickerSearchView::LocationPickerSearchView( LocationPickerAppWindow *aWindow, QGraphicsItem* aParent ):
       
    35         HbView( aParent ),
       
    36         mSearchPanel(new HbSearchPanel(this))
       
    37 
       
    38 {
       
    39     
       
    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.
       
    49     HbListViewItem *hbListItem = new HbListViewItem();
       
    50     hbListItem->setGraphicsSize(HbListViewItem::Thumbnail);
       
    51     mListView->setItemPrototype( hbListItem );
       
    52 
       
    53     // Create a standard model for the view list
       
    54     mModel = new QStandardItemModel();
       
    55     // create a data manager to populate the model
       
    56     mDataManager = new LocationPickerDataManager( *mModel, ELocationPickerSearchView );
       
    57 
       
    58     // Create the proxy model.
       
    59     mProxyModel = new LocationPickerProxyModel();
       
    60     mProxyModel->setSourceModel(mModel);
       
    61     mListView->setModel(mProxyModel);
       
    62 
       
    63     // set filter properties
       
    64     mProxyModel->setDynamicSortFilter(TRUE);
       
    65     mProxyModel->setSortRole(Qt::DisplayRole);
       
    66     mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
       
    67 
       
    68     // populate data
       
    69     mDataManager->populateModel();
       
    70 
       
    71     // sort
       
    72     mProxyModel->sort(0, Qt::AscendingOrder);
       
    73 
       
    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 // ----------------------------------------------------
       
    99 // LocationPickerSearchView::~LocationPickerSearchView()
       
   100 // ----------------------------------------------------
       
   101 LocationPickerSearchView::~LocationPickerSearchView()
       
   102 {
       
   103     // delete mDataManager
       
   104     if( mDataManager )
       
   105         delete mDataManager;
       
   106 }
       
   107 
       
   108 // ----------------------------------------------------
       
   109 // LocationPickerSearchView::doSearch()
       
   110 // ----------------------------------------------------
       
   111 void LocationPickerSearchView::doSearch(QString aCriteria)
       
   112 {
       
   113     // use the string to search
       
   114     mProxyModel->filterParameterChanged(aCriteria);
       
   115     mProxyModel->setFilterFixedString(aCriteria);
       
   116 }
       
   117 
       
   118 // ----------------------------------------------------
       
   119 // LocationPickerSearchView::handleActivated()
       
   120 // ----------------------------------------------------
       
   121 void LocationPickerSearchView::handleActivated(const QModelIndex &aIndex)
       
   122 {
       
   123     QModelIndex index = mProxyModel->mapToSource(aIndex);
       
   124     quint32 lm = 0;
       
   125     mDataManager->getData( index.row(), lm );
       
   126     mWindow->itemSelected( lm );
       
   127 }
       
   128