locationpickerservice/src/locationpickerlandscapeview.cpp
branchGCC_SURGE
changeset 32 9bd2e0ffe298
parent 25 a4fe51dd4d22
parent 31 8db05346071b
equal deleted inserted replaced
25:a4fe51dd4d22 32:9bd2e0ffe298
     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: LocationPickerLandscapeView implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "locationpickerlandscapeview.h"
       
    19 
       
    20 #include <qstandarditemmodel.h>
       
    21 #include <HbMainWindow>
       
    22 #include <HbGridViewItem>
       
    23 #include <HbGridView>
       
    24 #include <HbStyleLoader>
       
    25 #include <HbAction>
       
    26 
       
    27 #include "locationpickerproxymodel.h"
       
    28 #include "locationpickerdatamanager.h"
       
    29 #include "locationpickercollectionlistcontent.h"
       
    30 #include "locationpickercollectioncontent.h"
       
    31 
       
    32 
       
    33 // ----------------------------------------------------
       
    34 // LocationPickerLandscapeView::LocationPickerLandscapeView()
       
    35 // ----------------------------------------------------
       
    36 LocationPickerLandscapeView::LocationPickerLandscapeView(HbDocumentLoader* aLoader)
       
    37     :mDocumentLoader(aLoader),
       
    38     mAllAction(NULL),
       
    39     mCollectionAction(NULL),
       
    40     mSearchAction(NULL),
       
    41     mAscendingAction(NULL),
       
    42     mDescendingAction(NULL),
       
    43     mGridView(NULL),
       
    44     mCollectionContent(NULL),
       
    45     mGridViewItem(NULL),
       
    46     mViewType(ELocationPickerContent)
       
    47 {   
       
    48     HbStyleLoader::registerFilePath(":/locationgrid.css"); 
       
    49     HbStyleLoader::registerFilePath(":/locationgrid.hbgridviewitem.widgetml");
       
    50     //create grid view item
       
    51     mGridViewItem = new HbGridViewItem();
       
    52     mGridViewItem->setObjectName("locationgrid");
       
    53     
       
    54     // create back action
       
    55     mLandscapeBackAction = new HbAction(Hb::BackNaviAction);
       
    56     setNavigationAction(mLandscapeBackAction);
       
    57     connect(mLandscapeBackAction, SIGNAL(triggered()), this,
       
    58             SLOT(backButtonTriggered()));
       
    59 }
       
    60 // ----------------------------------------------------
       
    61 // LocationPickerPotraitView::~LocationPickerLandscapeView()
       
    62 // ----------------------------------------------------
       
    63 LocationPickerLandscapeView::~LocationPickerLandscapeView()
       
    64 {
       
    65     delete mCollectionContent;
       
    66     delete mAllAction;
       
    67     delete mCollectionAction;
       
    68     delete mAscendingAction;
       
    69     delete mDescendingAction;
       
    70 }
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // LocationPickerPotraitView::backButtonTriggered()
       
    74 // ----------------------------------------------------------------------------
       
    75 void LocationPickerLandscapeView::backButtonTriggered()
       
    76 {
       
    77     //if current model is collection content, go back to collectionlist content  
       
    78     if(mViewType == ELocationPickerCollectionContent)
       
    79     {
       
    80         colectionTabTriggered();
       
    81         emit collectionContentExited(); 
       
    82     }
       
    83     else
       
    84     {
       
    85         //complete the service
       
    86         emit completeService();
       
    87     } 
       
    88 }
       
    89 
       
    90 
       
    91 // ----------------------------------------------------
       
    92 // LocationPickerPotraitView::~init()
       
    93 // ----------------------------------------------------
       
    94 void LocationPickerLandscapeView::init(Qt::Orientation aOrientation, QStandardItemModel *aModel )
       
    95 {   
       
    96       mModel = aModel;      
       
    97       //create proxy model
       
    98       mProxyModel = new LocationPickerProxyModel( aOrientation , this  );
       
    99       mProxyModel->setSourceModel(aModel);
       
   100       // set sort properties
       
   101       mProxyModel->setDynamicSortFilter(TRUE);
       
   102       mProxyModel->setSortRole(Qt::DisplayRole);
       
   103       mProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
       
   104       // sort in ascending order
       
   105       mProxyModel->sort(0, Qt::AscendingOrder);    
       
   106       
       
   107      //Get HbAction items
       
   108 	 mGridView = qobject_cast<HbGridView*> (mDocumentLoader->findObject(QString(
       
   109                   "gridView")));
       
   110       //get the action items from docml
       
   111       mAllAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(QString(
       
   112               "allAction")));
       
   113       mCollectionAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   114               QString("collectionAction")));
       
   115       mSearchAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(QString(
       
   116               "searchAction")));
       
   117       mAscendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   118               QString("ascendingAction")));
       
   119       mDescendingAction = qobject_cast<HbAction*> (mDocumentLoader->findObject(
       
   120               QString("descendingAction")));
       
   121       if( !mAllAction || !mCollectionAction || !mSearchAction || !mGridView || !mAscendingAction || !mDescendingAction)
       
   122       {
       
   123           qFatal("Error Reading Docml");
       
   124       }
       
   125       
       
   126       if(this->mainWindow()->orientation() == Qt::Horizontal)
       
   127       { 
       
   128           int rowCount = mGridView->rowCount();
       
   129           int columnCount = mGridView->columnCount();
       
   130           mGridView->setRowCount(columnCount);
       
   131           mGridView->setColumnCount(rowCount);
       
   132       }
       
   133       //connect to slots
       
   134       connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
       
   135       connect(mDescendingAction, SIGNAL(triggered()), this,
       
   136               SLOT(sortDescending()));
       
   137       //connect all action Items to respective slots
       
   138       connect(mAllAction, SIGNAL(triggered()), this, SLOT(allTabTriggered()));
       
   139       connect(mCollectionAction, SIGNAL(triggered()), this,SLOT(colectionTabTriggered()));
       
   140       connect(mSearchAction, SIGNAL(triggered()), this,
       
   141               SLOT(searchTabTriggered()));
       
   142       
       
   143       connect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &)));
       
   144 }
       
   145 
       
   146 
       
   147 void LocationPickerLandscapeView::manageGridView()
       
   148 {
       
   149     //set the appropriate model
       
   150     switch(mViewType)
       
   151     {
       
   152         case ELocationPickerContent:
       
   153         {
       
   154             mGridView->setModel(mProxyModel,mGridViewItem);
       
   155             mAllAction->setChecked(true);
       
   156             mCollectionAction->setChecked(false);
       
   157         }
       
   158         break;
       
   159         case ELocationPickerCollectionContent:
       
   160         {
       
   161             setCollectionData(mCategoryId);
       
   162             mCollectionAction->setChecked(true);
       
   163             mAllAction->setChecked(false);
       
   164         }
       
   165         break;
       
   166     }
       
   167 }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // LocationPickerLandscapeView::handleActivated()
       
   171 // -----------------------------------------------------------------------------
       
   172 void LocationPickerLandscapeView::handleActivated(const QModelIndex &aIndex)
       
   173 {   
       
   174     //handle the activated signal according to model set
       
   175     
       
   176        switch(mViewType)
       
   177        {
       
   178            case ELocationPickerContent:
       
   179                {
       
   180                 QModelIndex  index = mProxyModel->mapToSource(
       
   181                                   aIndex);
       
   182                 quint32 lm = 0;
       
   183                 QStandardItem* item = mModel->item( index.row(), index.column() );
       
   184                 QVariant var = item->data( Qt::UserRole );
       
   185                 lm = var.toUInt();
       
   186                 //item selected, complete request
       
   187                 emit selectItem( lm );
       
   188                }
       
   189            break;
       
   190            case ELocationPickerCollectionContent:
       
   191                {
       
   192                if(!mCollectionContent->getProxyModel())
       
   193                {
       
   194                break;
       
   195                }
       
   196                QModelIndex   index = mCollectionContent->getProxyModel()->mapToSource(
       
   197                                       aIndex);
       
   198                quint32 lm = 0;
       
   199                mCollectionContent->getData(index, lm);
       
   200                emit selectItem(lm);
       
   201                }
       
   202                break;
       
   203            default:
       
   204                break;
       
   205      }
       
   206 }
       
   207 
       
   208 
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // LocationPickerLandscapeView::sortAscending()
       
   212 // -----------------------------------------------------------------------------
       
   213 void LocationPickerLandscapeView::sortAscending()
       
   214 {   
       
   215     //check the model set and do sorting accordingly
       
   216         if (mViewType == ELocationPickerContent)
       
   217         {
       
   218             mProxyModel->sort(0, Qt::AscendingOrder);
       
   219         }
       
   220         else
       
   221         {
       
   222             mCollectionContent->getProxyModel()->sort(0, Qt::AscendingOrder);
       
   223         }
       
   224 }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // LocationPickerLandscapeView::sortDescending()
       
   228 // -----------------------------------------------------------------------------
       
   229 void LocationPickerLandscapeView::sortDescending()
       
   230 {
       
   231     //check the model set and do sorting accordingly
       
   232         if (mViewType == ELocationPickerContent)
       
   233         {
       
   234             mProxyModel->sort(0, Qt::DescendingOrder);
       
   235         }
       
   236         else
       
   237         {
       
   238             mCollectionContent->getProxyModel()->sort(0, Qt::DescendingOrder);
       
   239         }   
       
   240 }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // LocationPickerLandscapeView::handleAllTab()
       
   244 // -----------------------------------------------------------------------------
       
   245 void LocationPickerLandscapeView::allTabTriggered()
       
   246 {
       
   247     //execute only if tab is not pressed
       
   248        if (mAllAction->isChecked())
       
   249        {    
       
   250            mGridView->setModel(mProxyModel,mGridViewItem);
       
   251            mAscendingAction->setEnabled(true);
       
   252            mDescendingAction->setEnabled(true);
       
   253            mCollectionAction->setChecked(false);
       
   254            mViewType = ELocationPickerContent;
       
   255 		   //delete mCollectionContent if coming back from collectioncontent
       
   256            if (mCollectionContent)
       
   257            {
       
   258                delete mCollectionContent;
       
   259                mCollectionContent = NULL;
       
   260            }
       
   261        }
       
   262        else
       
   263        {
       
   264 	       //Keep the tab pressed
       
   265            mAllAction->setChecked(true);
       
   266        }
       
   267     
       
   268 }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // LocationPickerLandscapeView::handleCollectionTab()
       
   272 // -----------------------------------------------------------------------------
       
   273 void LocationPickerLandscapeView::colectionTabTriggered()
       
   274 {
       
   275     //execute only if tab is not pressed
       
   276     if (mCollectionAction->isChecked())
       
   277     {   
       
   278         mViewType = ELocationPickerCollectionListContent;
       
   279     	emit handleCollectionList();
       
   280     }
       
   281     else
       
   282     {
       
   283 	    //Keep the tab pressed
       
   284         mCollectionAction->setChecked(true);
       
   285     }
       
   286 }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // LocationPickerLandscapeView::searchTabTriggered()
       
   290 // -----------------------------------------------------------------------------
       
   291 void LocationPickerLandscapeView::searchTabTriggered()
       
   292 {
       
   293     emit switchToSearchView();
       
   294 }
       
   295 
       
   296 void LocationPickerLandscapeView::setCollectionData( quint32 aCategoryId )
       
   297 {   
       
   298     if(!mCollectionContent)
       
   299     {
       
   300         mCollectionContent = new LocationPickerCollectionContent(Qt::Horizontal , aCategoryId);
       
   301     }
       
   302     if(mCollectionContent->locationFound())
       
   303     {
       
   304         mGridView->setModel(mCollectionContent->getProxyModel(),mGridViewItem);
       
   305     }
       
   306     else
       
   307     {
       
   308         mGridView->setModel(mCollectionContent->getStandardModel(),mGridViewItem);
       
   309     }
       
   310     mViewType = ELocationPickerCollectionContent;
       
   311     //Enable the options
       
   312     mAscendingAction->setEnabled(true);
       
   313     mDescendingAction->setEnabled(true);
       
   314     mCollectionAction->setChecked(true);
       
   315 }
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // LocationPickerLandscapeView::setCategoryID()
       
   319 // -----------------------------------------------------------------------------
       
   320 void LocationPickerLandscapeView::setCategoryID( quint32 aCategoryId  )
       
   321 {
       
   322     mCategoryId = aCategoryId;
       
   323 }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // LocationPickerLandscapeView::getViewType()
       
   327 // -----------------------------------------------------------------------------
       
   328 TViewType LocationPickerLandscapeView::getViewType()
       
   329 {
       
   330     return mViewType;
       
   331 }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // LocationPickerLandscapeView::setViewType()
       
   335 // -----------------------------------------------------------------------------
       
   336 void LocationPickerLandscapeView::setViewType(TViewType aViewType)
       
   337 {
       
   338     mViewType = aViewType;
       
   339 }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // LocationPickerLandscapeView::clearContentModel()
       
   343 // -----------------------------------------------------------------------------
       
   344 void LocationPickerLandscapeView::clearContentModel()
       
   345 {
       
   346    if(mCollectionContent)
       
   347    {
       
   348    delete mCollectionContent;
       
   349    mCollectionContent = NULL;
       
   350    }
       
   351 }
       
   352