locationpickerservice/src/locationpickercollectioncontent.cpp
branchRCL_3
changeset 18 870918037e16
parent 17 1fc85118c3ae
equal deleted inserted replaced
17:1fc85118c3ae 18:870918037e16
     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 <QStandardItemModel>
       
    19 
       
    20 #include "locationpickerproxymodel.h"
       
    21 #include "locationpickercollectioncontent.h"
       
    22 #include "locationpickerdatamanager.h"
       
    23 #include "locationpickertypes.h"
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 
       
    27 // ----------------------------------------------------------------
       
    28 // LocationPickerCollectionContent::LocationPickerCollectionContent()
       
    29 // -----------------------------------------------------------------
       
    30 LocationPickerCollectionContent::LocationPickerCollectionContent( quint32 aCollectionId )
       
    31     :mProxyModel(NULL),
       
    32     mModel(NULL),
       
    33     mDataManager(NULL),
       
    34 	mLocationFound(false)
       
    35 {
       
    36     // Create a standard model for the view list
       
    37     mModel = new QStandardItemModel( this );
       
    38     // create data manager to manage data in the model
       
    39     mDataManager = LocationPickerDataManager::getInstance();
       
    40     if( mDataManager->populateModel( *mModel, ELocationPickerCollectionContent, aCollectionId ) )
       
    41     {
       
    42         // Create the proxy model.
       
    43         mProxyModel = new LocationPickerProxyModel();
       
    44         mProxyModel->setSourceModel(mModel);
       
    45         mProxyModel->setDynamicSortFilter(TRUE);
       
    46         mProxyModel->setSortRole(Qt::DisplayRole);
       
    47         mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
       
    48         // sort
       
    49         mProxyModel->sort(0, Qt::AscendingOrder);
       
    50         mLocationFound = true;
       
    51     }
       
    52     else
       
    53     {
       
    54         // no locations to display.
       
    55         QStandardItem *modelItem = new QStandardItem();
       
    56         modelItem->setData(QVariant(hbTrId("txt_lint_list_no_location_entries_present")), Qt::DisplayRole);
       
    57         mModel->appendRow( modelItem );
       
    58         mLocationFound = false;
       
    59      }
       
    60 }
       
    61 
       
    62 // ----------------------------------------------------------------
       
    63 // LocationPickerCollectionContent::~LocationPickerCollectionContent
       
    64 // -----------------------------------------------------------------
       
    65 LocationPickerCollectionContent::~LocationPickerCollectionContent()
       
    66 {
       
    67     delete mProxyModel;
       
    68     delete mModel;
       
    69 }
       
    70 
       
    71 // ----------------------------------------------------------------
       
    72 // LocationPickerCollectionContent::getProxyModel
       
    73 // -----------------------------------------------------------------
       
    74 LocationPickerProxyModel* LocationPickerCollectionContent::getProxyModel()
       
    75 {
       
    76     return mProxyModel;
       
    77 }
       
    78 
       
    79 // ----------------------------------------------------------------------------
       
    80 // LocationPickerCollectionContent::getData()
       
    81 // ----------------------------------------------------------------------------
       
    82 
       
    83 void LocationPickerCollectionContent::getData( QModelIndex aIndex, quint32& aValue )
       
    84 {
       
    85     QStandardItem* item = mModel->item( aIndex.row(), aIndex.column() );
       
    86     QVariant var = item->data( Qt::UserRole );
       
    87     aValue = var.toUInt();
       
    88 }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // LocationPickerCollectionContent::locationFound()
       
    92 // ----------------------------------------------------------------------------
       
    93 bool LocationPickerCollectionContent::locationFound()
       
    94 {
       
    95     return mLocationFound;
       
    96 }