locationpickerservice/src/locationpickercollectioncontent.cpp
changeset 17 0f22fb80ebba
parent 15 13ae750350c9
child 20 cd10d5b85554
equal deleted inserted replaced
15:13ae750350c9 17:0f22fb80ebba
    13 *
    13 *
    14 * Description: LocationPickerCollectionContent implementation
    14 * Description: LocationPickerCollectionContent implementation
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <HbListView>
       
    19 #include <QStandardItemModel>
    18 #include <QStandardItemModel>
    20 #include <HbMenu>
       
    21 #include <HbListViewItem>
       
    22 #include <HbAction>
       
    23 
    19 
    24 #include "locationpickerproxymodel.h"
    20 #include "locationpickerproxymodel.h"
    25 #include "locationpickercollectioncontent.h"
    21 #include "locationpickercollectioncontent.h"
    26 #include "locationpickerdatamanager.h"
    22 #include "locationpickerdatamanager.h"
    27 #include "locationpickertypes.h"
    23 #include "locationpickertypes.h"
    28 #include "locationpickerappwindow.h"
       
    29 
    24 
    30 // ======== MEMBER FUNCTIONS ========
    25 // ======== MEMBER FUNCTIONS ========
    31 
    26 
    32 // ----------------------------------------------------------------
    27 // ----------------------------------------------------------------
    33 // LocationPickerCollectionContent::LocationPickerCollectionContent()
    28 // LocationPickerCollectionContent::LocationPickerCollectionContent()
    34 // -----------------------------------------------------------------
    29 // -----------------------------------------------------------------
    35 LocationPickerCollectionContent::LocationPickerCollectionContent(
    30 LocationPickerCollectionContent::LocationPickerCollectionContent( Qt::Orientations aOrientation , quint32 aCollectionId )
    36         LocationPickerAppWindow *aWindow, quint32 aCollectionId, QGraphicsItem* aParent):
    31     :mOrientation(aOrientation),
    37         HbView( aParent )
    32 	 mProxyModel(NULL),
    38 
    33     mModel(NULL),
       
    34     mDataManager(NULL)
    39 {
    35 {
    40     // inditialize window
       
    41     mWindow = aWindow;
       
    42     // Create a standard model for the view list
    36     // Create a standard model for the view list
    43     mModel = new QStandardItemModel( this );
    37     mModel = new QStandardItemModel( this );
    44     mDataManager = new LocationPickerDataManager( *mModel, ELocationPickerCollectionContentView );
    38     mDataManager = new LocationPickerDataManager( *mModel, ELocationPickerCollectionContent );
    45     mListView = new HbListView( this );
    39     if( mDataManager->populateModel( mOrientation , aCollectionId ) )
    46 
       
    47 
       
    48     if( mDataManager->populateModel( aCollectionId ) )
       
    49     {
    40     {
    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.
    41         // Create the proxy model.
    58         mProxyModel = new LocationPickerProxyModel();
    42         mProxyModel = new LocationPickerProxyModel(mOrientation);
    59         mProxyModel->setSourceModel(mModel);
    43         mProxyModel->setSourceModel(mModel);
    60 
       
    61         // set the model
       
    62         mListView->setModel( mProxyModel, hbListItem );
       
    63         mProxyModel->setDynamicSortFilter(TRUE);
    44         mProxyModel->setDynamicSortFilter(TRUE);
    64         mProxyModel->setSortRole(Qt::DisplayRole);
    45         mProxyModel->setSortRole(Qt::DisplayRole);
    65         mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
    46         mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
    66 
       
    67         // sort
    47         // sort
    68         mProxyModel->sort(0, Qt::AscendingOrder);
    48         mProxyModel->sort(0, Qt::AscendingOrder);
    69 
       
    70         // construct menu for the view
       
    71         constructMenu();
       
    72     }
    49     }
    73 
       
    74     else
    50     else
    75     {
    51     {
    76         // no locations to display.
    52         // no locations to display.
    77         QStandardItem *modelItem = new QStandardItem();
    53         QStandardItem *modelItem = new QStandardItem();
    78         modelItem->setData(QVariant(KNoLocations), Qt::DisplayRole);
    54         modelItem->setData(QVariant(hbTrId("txt_lint_list_no_location_entries_present")), Qt::DisplayRole);
    79         mModel->appendRow( modelItem );
    55         mModel->appendRow( modelItem );
    80         mListView->setModel(mModel);
    56      }
    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 }
    57 }
    94 
    58 
    95 // ----------------------------------------------------------------
    59 // ----------------------------------------------------------------
    96 // LocationPickerCollectionContent::~LocationPickerCollectionContent
    60 // LocationPickerCollectionContent::~LocationPickerCollectionContent
    97 // -----------------------------------------------------------------
    61 // -----------------------------------------------------------------
    98 LocationPickerCollectionContent::~LocationPickerCollectionContent()
    62 LocationPickerCollectionContent::~LocationPickerCollectionContent()
    99 {
    63 {
   100     if( mDataManager )
    64     delete mProxyModel;
   101         delete mDataManager;
    65     delete mModel;
       
    66     delete mDataManager;
   102 }
    67 }
   103 
    68 
   104 // ----------------------------------------------------------------
    69 // ----------------------------------------------------------------
   105 // LocationPickerCollectionContent::constructMenu()
    70 // LocationPickerCollectionContent::getProxyModel
   106 // -----------------------------------------------------------------
    71 // -----------------------------------------------------------------
   107 void LocationPickerCollectionContent::constructMenu()
    72 LocationPickerProxyModel* LocationPickerCollectionContent::getProxyModel()
   108 {
    73     {
   109     HbMenu *menu = this->menu();
    74     return mProxyModel;
   110     HbMenu *subMenu = menu->addMenu(KSortBy);
    75     }
   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 
    76 
   121 
    77 
   122 // ----------------------------------------------------------------
    78 // ----------------------------------------------------------------
   123 // LocationPickerCollectionContent::sortAscending()
    79 // LocationPickerCollectionContent::getDataManager
   124 // -----------------------------------------------------------------
    80 // -----------------------------------------------------------------
   125 void LocationPickerCollectionContent::sortAscending()
    81 LocationPickerDataManager* LocationPickerCollectionContent::getDataManager()
   126 {
    82     {
   127     mProxyModel->sort(0, Qt::AscendingOrder);
    83     return mDataManager;
   128 }
    84     }
   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 }