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