locationpickerservice/src/locationpickerlandscapeview.cpp
changeset 20 cd10d5b85554
parent 17 0f22fb80ebba
child 24 ccec19943943
equal deleted inserted replaced
17:0f22fb80ebba 20:cd10d5b85554
    24 #include <HbStyleLoader>
    24 #include <HbStyleLoader>
    25 #include <HbAction>
    25 #include <HbAction>
    26 
    26 
    27 #include "locationpickerproxymodel.h"
    27 #include "locationpickerproxymodel.h"
    28 #include "locationpickerdatamanager.h"
    28 #include "locationpickerdatamanager.h"
    29 #include "locationpickercontent.h" 
       
    30 #include "locationpickercollectionlistcontent.h"
    29 #include "locationpickercollectionlistcontent.h"
    31 #include "locationpickercollectioncontent.h"
    30 #include "locationpickercollectioncontent.h"
    32 
    31 
    33 
    32 
    34 // ----------------------------------------------------
    33 // ----------------------------------------------------
    35 // LocationPickerLandscapeView::LocationPickerLandscapeView()
    34 // LocationPickerLandscapeView::LocationPickerLandscapeView()
    36 // ----------------------------------------------------
    35 // ----------------------------------------------------
    37 LocationPickerLandscapeView::LocationPickerLandscapeView(HbDocumentLoader* aLoader)
    36 LocationPickerLandscapeView::LocationPickerLandscapeView(HbDocumentLoader* aLoader)
    38     :mDocumentLoader(aLoader),
    37     :mDocumentLoader(aLoader),
    39     mLocationPickerContent(NULL),
       
    40     mLocationPickerCollectionListContent(NULL),
       
    41     mAllAction(NULL),
    38     mAllAction(NULL),
    42     mCollectionAction(NULL),
    39     mCollectionAction(NULL),
    43     mSearchAction(NULL),
    40     mSearchAction(NULL),
    44     mAscendingAction(NULL),
    41     mAscendingAction(NULL),
    45     mDescendingAction(NULL),
    42     mDescendingAction(NULL),
    53     //create grid view item
    50     //create grid view item
    54     mGridViewItem = new HbGridViewItem();
    51     mGridViewItem = new HbGridViewItem();
    55     mGridViewItem->setObjectName("locationgrid");
    52     mGridViewItem->setObjectName("locationgrid");
    56     
    53     
    57     // create back action
    54     // create back action
    58     mLandscapeBackAction = new HbAction(Hb::BackAction);
    55     mLandscapeBackAction = new HbAction(Hb::BackNaviAction);
    59     setNavigationAction(mLandscapeBackAction);
    56     setNavigationAction(mLandscapeBackAction);
    60     connect(mLandscapeBackAction, SIGNAL(triggered()), this,
    57     connect(mLandscapeBackAction, SIGNAL(triggered()), this,
    61             SLOT(backButtonTriggered()));
    58             SLOT(backButtonTriggered()));
    62 }
    59 }
    63 // ----------------------------------------------------
    60 // ----------------------------------------------------
    64 // LocationPickerPotraitView::~LocationPickerLandscapeView()
    61 // LocationPickerPotraitView::~LocationPickerLandscapeView()
    65 // ----------------------------------------------------
    62 // ----------------------------------------------------
    66 LocationPickerLandscapeView::~LocationPickerLandscapeView()
    63 LocationPickerLandscapeView::~LocationPickerLandscapeView()
    67 {
    64 {
    68     delete mCollectionContent;
    65     delete mCollectionContent;
    69     delete mLocationPickerContent;
       
    70     delete mLocationPickerCollectionListContent;
       
    71     delete mAllAction;
    66     delete mAllAction;
    72     delete mCollectionAction;
    67     delete mCollectionAction;
    73     delete mAscendingAction;
    68     delete mAscendingAction;
    74     delete mDescendingAction;
    69     delete mDescendingAction;
    75 }
    70 }
    81 {
    76 {
    82     //if current model is collection content, go back to collectionlist content  
    77     //if current model is collection content, go back to collectionlist content  
    83     if(mViewType == ELocationPickerCollectionContent)
    78     if(mViewType == ELocationPickerCollectionContent)
    84     {
    79     {
    85         colectionTabTriggered();
    80         colectionTabTriggered();
    86         delete mCollectionContent;
    81         emit collectionContentExited(); 
    87         mCollectionContent=NULL; 
       
    88     }
    82     }
    89     else
    83     else
    90     {
    84     {
    91         //complete the service
    85         //complete the service
    92         emit completeService();
    86         emit completeService();
    95 
    89 
    96 
    90 
    97 // ----------------------------------------------------
    91 // ----------------------------------------------------
    98 // LocationPickerPotraitView::~init()
    92 // LocationPickerPotraitView::~init()
    99 // ----------------------------------------------------
    93 // ----------------------------------------------------
   100 void LocationPickerLandscapeView::init(Qt::Orientation aOrientation )
    94 void LocationPickerLandscapeView::init(Qt::Orientation aOrientation, QStandardItemModel *aModel )
   101 {   
    95 {   
   102       // Create Collection List Content
    96       mModel = aModel;      
   103       mLocationPickerCollectionListContent = new LocationPickerCollectionListContent(aOrientation);
    97       //create proxy model
   104       
    98       mProxyModel = new LocationPickerProxyModel( aOrientation , this  );
   105       mLocationPickerContent = new LocationPickerContent(aOrientation);
    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       
   106       
   107      //Get HbAction items
   107      //Get HbAction items
   108 	 mGridView = qobject_cast<HbGridView*> (mDocumentLoader->findObject(QString(
   108 	 mGridView = qobject_cast<HbGridView*> (mDocumentLoader->findObject(QString(
   109                   "gridView")));
   109                   "gridView")));
   110       //get the action items from docml
   110       //get the action items from docml
   120               QString("descendingAction")));
   120               QString("descendingAction")));
   121       if( !mAllAction || !mCollectionAction || !mSearchAction || !mGridView || !mAscendingAction || !mDescendingAction)
   121       if( !mAllAction || !mCollectionAction || !mSearchAction || !mGridView || !mAscendingAction || !mDescendingAction)
   122       {
   122       {
   123           qFatal("Error Reading Docml");
   123           qFatal("Error Reading Docml");
   124       }
   124       }
   125 
   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       }
   126       //connect to slots
   133       //connect to slots
   127       connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
   134       connect(mAscendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
   128       connect(mDescendingAction, SIGNAL(triggered()), this,
   135       connect(mDescendingAction, SIGNAL(triggered()), this,
   129               SLOT(sortDescending()));
   136               SLOT(sortDescending()));
   130       //connect all action Items to respective slots
   137       //connect all action Items to respective slots
   136       connect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &)));
   143       connect(mGridView, SIGNAL(activated(const QModelIndex &)), this, SLOT(handleActivated(const QModelIndex &)));
   137 }
   144 }
   138 
   145 
   139 
   146 
   140 void LocationPickerLandscapeView::manageGridView()
   147 void LocationPickerLandscapeView::manageGridView()
   141 {   
   148 {
   142     // Create Locationpicker Content
   149     //set the appropriate model
   143     if (!mLocationPickerContent->locationsFound())
   150     switch(mViewType)
   144     {
   151     {
   145         //if no location entries present
   152         case ELocationPickerContent:
   146         mGridView->setModel(mLocationPickerContent->getStandardModel(),mGridViewItem); 
   153         {
   147         disableTabs();
   154             mGridView->setModel(mProxyModel,mGridViewItem);
   148         mViewType = ELocationPickerContent;
   155             mAllAction->setChecked(true);
   149     }
   156             mCollectionAction->setChecked(false);
   150     else
   157         }
   151     {
   158         break;
   152         //set the appropriate model
   159         case ELocationPickerCollectionContent:
   153         switch(mViewType)
   160         {
   154             {
   161             setCollectionData(mCategoryId);
   155                 case ELocationPickerContent:
   162             mCollectionAction->setChecked(true);
   156                 {
   163             mAllAction->setChecked(false);
   157                     mGridView->setModel(mLocationPickerContent->getGridProxyModel(),mGridViewItem);
   164         }
   158                     mAllAction->setChecked(true);
   165         break;
   159                     mCollectionAction->setChecked(false);
   166     }
   160                 }
   167 }
   161                 break;
       
   162                 case ELocationPickerCollectionContent:
       
   163                 {
       
   164                     setCollectionData(mCategoryId);
       
   165                     mCollectionAction->setChecked(true);
       
   166                     mAllAction->setChecked(false);
       
   167                 }
       
   168                 break;
       
   169             }
       
   170     }
       
   171 }
       
   172 
       
   173 void LocationPickerLandscapeView::disableTabs()
       
   174 {
       
   175     mAllAction->setDisabled(true);
       
   176     mCollectionAction->setDisabled(true);
       
   177     mSearchAction->setDisabled(true);
       
   178     mAscendingAction->setDisabled(true);
       
   179     mDescendingAction->setDisabled(true);
       
   180 }
       
   181 
       
   182 
   168 
   183 // -----------------------------------------------------------------------------
   169 // -----------------------------------------------------------------------------
   184 // LocationPickerLandscapeView::handleActivated()
   170 // LocationPickerLandscapeView::handleActivated()
   185 // -----------------------------------------------------------------------------
   171 // -----------------------------------------------------------------------------
   186 void LocationPickerLandscapeView::handleActivated(const QModelIndex &aIndex)
   172 void LocationPickerLandscapeView::handleActivated(const QModelIndex &aIndex)
   187 {   
   173 {   
   188     //handle the activated signal according to model set
   174     //handle the activated signal according to model set
   189     
   175     
   190        switch(mViewType)
   176        switch(mViewType)
   191            {
   177        {
   192            case ELocationPickerContent:
   178            case ELocationPickerContent:
   193                {
   179                {
   194                    QModelIndex  index = mLocationPickerContent->getGridProxyModel()->mapToSource(
   180                 QModelIndex  index = mProxyModel->mapToSource(
   195                                   aIndex);
   181                                   aIndex);
   196                 quint32 lm = 0;
   182                 quint32 lm = 0;
   197                 mLocationPickerContent->getDataManager()->getData(index.row(), lm);
   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
   198                 emit selectItem( lm );
   187                 emit selectItem( lm );
   199                }
   188                }
   200            break;
   189            break;
   201            case ELocationPickerCollectionListContent:
       
   202                {
       
   203                mLocationPickerCollectionListContent->getDataManager()->getData(
       
   204                        aIndex.row(), mCategoryId);
       
   205                setCollectionData(mCategoryId);
       
   206                emit sendCategoryID(mCategoryId);
       
   207                }
       
   208                break;
       
   209               //default
       
   210            case ELocationPickerCollectionContent:
   190            case ELocationPickerCollectionContent:
   211                {
   191                {
       
   192                if(!mCollectionContent->getProxyModel())
       
   193                {
       
   194                break;
       
   195                }
   212                QModelIndex   index = mCollectionContent->getProxyModel()->mapToSource(
   196                QModelIndex   index = mCollectionContent->getProxyModel()->mapToSource(
   213                                       aIndex);
   197                                       aIndex);
   214                quint32 lm = 0;
   198                quint32 lm = 0;
   215                mCollectionContent->getDataManager()->getData(index.row(), lm);
   199                mCollectionContent->getData(index, lm);
   216                emit selectItem(lm);
   200                emit selectItem(lm);
   217                }
   201                }
   218                break;
   202                break;
   219            default:
   203            default:
   220                break;
   204                break;
   229 void LocationPickerLandscapeView::sortAscending()
   213 void LocationPickerLandscapeView::sortAscending()
   230 {   
   214 {   
   231     //check the model set and do sorting accordingly
   215     //check the model set and do sorting accordingly
   232         if (mViewType == ELocationPickerContent)
   216         if (mViewType == ELocationPickerContent)
   233         {
   217         {
   234             mLocationPickerContent->getGridProxyModel()->sort(0, Qt::AscendingOrder);
   218             mProxyModel->sort(0, Qt::AscendingOrder);
   235         }
   219         }
   236         else
   220         else
   237         {
   221         {
   238             mCollectionContent->getProxyModel()->sort(0, Qt::AscendingOrder);
   222             mCollectionContent->getProxyModel()->sort(0, Qt::AscendingOrder);
   239         }
   223         }
   245 void LocationPickerLandscapeView::sortDescending()
   229 void LocationPickerLandscapeView::sortDescending()
   246 {
   230 {
   247     //check the model set and do sorting accordingly
   231     //check the model set and do sorting accordingly
   248         if (mViewType == ELocationPickerContent)
   232         if (mViewType == ELocationPickerContent)
   249         {
   233         {
   250             mLocationPickerContent->getGridProxyModel()->sort(0, Qt::DescendingOrder);
   234             mProxyModel->sort(0, Qt::DescendingOrder);
   251         }
   235         }
   252         else
   236         else
   253         {
   237         {
   254             mCollectionContent->getProxyModel()->sort(0, Qt::DescendingOrder);
   238             mCollectionContent->getProxyModel()->sort(0, Qt::DescendingOrder);
   255         }   
   239         }   
   261 void LocationPickerLandscapeView::allTabTriggered()
   245 void LocationPickerLandscapeView::allTabTriggered()
   262 {
   246 {
   263     //execute only if tab is not pressed
   247     //execute only if tab is not pressed
   264        if (mAllAction->isChecked())
   248        if (mAllAction->isChecked())
   265        {    
   249        {    
   266            mGridView->setModel(mLocationPickerContent->getGridProxyModel(),mGridViewItem);
   250            mGridView->setModel(mProxyModel,mGridViewItem);
   267            mAscendingAction->setEnabled(true);
   251            mAscendingAction->setEnabled(true);
   268            mDescendingAction->setEnabled(true);
   252            mDescendingAction->setEnabled(true);
   269            mCollectionAction->setChecked(false);
   253            mCollectionAction->setChecked(false);
   270            mViewType = ELocationPickerContent;
   254            mViewType = ELocationPickerContent;
   271 		   //delete mCollectionContent if coming back from collectioncontent
   255 		   //delete mCollectionContent if coming back from collectioncontent
   309     emit switchToSearchView();
   293     emit switchToSearchView();
   310 }
   294 }
   311 
   295 
   312 void LocationPickerLandscapeView::setCollectionData( quint32 aCategoryId )
   296 void LocationPickerLandscapeView::setCollectionData( quint32 aCategoryId )
   313 {   
   297 {   
   314     mCollectionContent
   298     if(!mCollectionContent)
   315     = new LocationPickerCollectionContent(this->mainWindow()->orientation() , aCategoryId);
   299     {
   316     mGridView->setModel(mCollectionContent->getProxyModel(),mGridViewItem);
   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     }
   317     mViewType = ELocationPickerCollectionContent;
   310     mViewType = ELocationPickerCollectionContent;
   318     //Enable the options
   311     //Enable the options
   319     mAscendingAction->setEnabled(true);
   312     mAscendingAction->setEnabled(true);
   320     mDescendingAction->setEnabled(true);
   313     mDescendingAction->setEnabled(true);
   321     mCollectionAction->setChecked(true);
   314     mCollectionAction->setChecked(true);
   342 // -----------------------------------------------------------------------------
   335 // -----------------------------------------------------------------------------
   343 void LocationPickerLandscapeView::setViewType(TViewType aViewType)
   336 void LocationPickerLandscapeView::setViewType(TViewType aViewType)
   344 {
   337 {
   345     mViewType = aViewType;
   338     mViewType = aViewType;
   346 }
   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