Nokia N97 SDK
Example Applications Guide

CLandmarksModel Class Reference

#include <LandmarksModel.h>

Inheritance diagram for CLandmarksModel:

List of all members.

Detailed Description

Contains the data model of the landmarks view.

Definition at line 34 of file LandmarksModel.h.


Public Member Functions

  ~CLandmarksModel ()
void  SetItemIds (RArray< TPosLmItemId > *aItemIds)
CDesCArraySeg *  ItemList ()
void  SetCurrentItem (TInt aIndex)
TPosLmItemId  CurrentItemId ()
CIconList *  CreateIconListL ()
void  RepopulateModelL (CArrayPtr< CPosLandmark > *aLandmarks)

Static Public Member Functions

static CLandmarksModel *  NewL ()

Private Member Functions

HBufC *  FormatListItemLC (CPosLandmark &aLandmark)
void  AppendIconL (const TDesC &aMbmFile, TInt aIconOffset, TInt aMaskOffset)
  CLandmarksModel ()
void  ConstructL ()

Private Attributes

TInt  iCurrentItem
  contains the current item in the model
CDesCArraySeg *  iListItems
  an array of formatted descriptors
RArray< TPosLmItemId > *  iItemIds
  an array of item ids matching the landmarks represented by iListItems
CIconList *  iIconList
  an array of landmark icons
TInt  iIndexToPopulate
  the next index to repopulate


Constructor & Destructor Documentation

CLandmarksModel::~CLandmarksModel (   ) 
 

Destructor.

Definition at line 70 of file LandmarksModel.cpp.

References iListItems.

00071         {
00072         delete iListItems;
00073         }

CLandmarksModel::CLandmarksModel (   )  [private]
 

C++ constructor.

Definition at line 40 of file LandmarksModel.cpp.

Referenced by NewL().

00041         {
00042         }


Member Function Documentation

CLandmarksModel * CLandmarksModel::NewL (   )  [static]
 

Two-phased constructor.

Definition at line 60 of file LandmarksModel.cpp.

References CLandmarksModel().

Referenced by CLandmarksContainer::ConstructL().

00061     {
00062     CLandmarksModel* self = new (ELeave) CLandmarksModel();
00063     CleanupStack::PushL(self);
00064     self->ConstructL();
00065     CleanupStack::Pop(self);
00066     return self;
00067     }

void CLandmarksModel::SetItemIds (  RArray< TPosLmItemId > *  aItemIds  ) 
 

Sets the data member iItemIds

Parameters:
aItemIds  a pointer to an array of item ids

Definition at line 81 of file LandmarksModel.cpp.

References iItemIds, and iListItems.

Referenced by CLandmarksContainer::HandleSearchReadyL().

00082     {
00083     iItemIds = aItemIds;
00084 
00085     // Empty descriptor model
00086     iListItems->Reset();
00087     }

CDesCArraySeg * CLandmarksModel::ItemList (   ) 
 

Returns a pointer to an array to be used for a list box.

Returns:
an array of descriptors formatted to fit a CEikColumnListBox with one icon column to the left and one descriptor column to the right.

Definition at line 95 of file LandmarksModel.cpp.

References iListItems.

Referenced by CLandmarksContainer::ConstructL().

00096     {
00097     return iListItems;
00098     }

void CLandmarksModel::SetCurrentItem (  TInt  aIndex  ) 
 

Sets current item in the model. The current item should match the current selected one in the listbox displaying this model.

Parameters:
aIndex  the index of the current item in the list.

Definition at line 106 of file LandmarksModel.cpp.

References iCurrentItem.

Referenced by CLandmarksContainer::HandleControlEventL(), CLandmarksContainer::HandleReadReadyL(), and CLandmarksContainer::HandleSearchReadyL().

00107     {
00108     iCurrentItem = aIndex;
00109     }

TPosLmItemId CLandmarksModel::CurrentItemId (   ) 
 

Returns the item id of the current item in the model.

Returns:
the item id of the current item in the model. KPosLmNullItemId if no item is set as current

Definition at line 117 of file LandmarksModel.cpp.

References iCurrentItem, and iItemIds.

Referenced by CLandmarksContainer::CurrentLandmark(), CLandmarksContainer::DeleteLandmarkL(), CLandmarksContainer::IsRefreshNeededL(), and CLandmarksContainer::StoreCurrentLandmarkNameL().

00118     {
00119     if (!iItemIds || iCurrentItem < 0 || 
00120         iCurrentItem > iItemIds->Count() - 1)
00121         {
00122         return KPosLmNullItemId;
00123         }
00124 
00125     return (*iItemIds)[iCurrentItem];
00126     }

CIconList * CLandmarksModel::CreateIconListL (   ) 
 

Creates an array of icons that should be displayed be the listbox displaying the data of this model.

Returns:
an array of icons. Ownership of CIconList* is tranferred to caller

Definition at line 134 of file LandmarksModel.cpp.

References iIconList.

Referenced by CLandmarksContainer::ConstructL(), and CLandmarksContainer::HandleSearchReadyL().

00135     {
00136     CIconList* iconList = new (ELeave) CAknIconArray( KGranularity );
00137 
00138     CleanupStack::PushL(iconList);
00139     
00140     // Create the default landmark icon consisting of its image and mask
00141     TAknsItemID aknsItemId = {0,0};
00142     CGulIcon* icon = AknsUtils::CreateGulIconL(NULL, aknsItemId,
00143         KLandmarksMbmFileName, 
00144         EMbmLmrefappDefault_lm, 
00145         EMbmLmrefappDefault_lm_mask);
00146     CleanupStack::PushL(icon);
00147     icon->SetBitmapsOwnedExternally(EFalse);
00148     iconList->AppendL(icon);
00149     CleanupStack::Pop(2, iconList);
00150 
00151     // initialze iIconList. We don't need to delete any possible previous 
00152     // iIconList since ownership is transferred to calling object.
00153     iIconList = iconList;
00154 
00155     return iIconList;
00156     }

void CLandmarksModel::RepopulateModelL (  CArrayPtr< CPosLandmark > *  aLandmarks  ) 
 

Repopulates a part of the model.

Parameters:
aLandmarks  the landmarks to insert to the model

Definition at line 164 of file LandmarksModel.cpp.

References FormatListItemLC(), and iListItems.

Referenced by CLandmarksContainer::HandleReadReadyL().

00166     {
00167     TInt nrOfReadItems = aLandmarks->Count();
00168 
00169     // Format and insert the read landmarks
00170     for (TInt i = 0; i < nrOfReadItems; i++)
00171         {
00172         CPosLandmark* landmark = (*aLandmarks)[i];
00173         HBufC* formattedListItem = FormatListItemLC(*landmark);
00174         iListItems->AppendL(*formattedListItem);
00175         CleanupStack::PopAndDestroy(formattedListItem);
00176         }
00177     }

HBufC * CLandmarksModel::FormatListItemLC (  CPosLandmark &  aLandmark  )  [private]
 

Formats a list item to fit a CEikColumnistBox with one graphic column and one descriptor column.

Parameters:
aLandmark  the landmarks this list item will represent
Returns:
a formatted descriptor buffer

Definition at line 186 of file LandmarksModel.cpp.

References AppendIconL(), and iIconList.

Referenced by RepopulateModelL().

00187     {
00188     // Extract name
00189     TPtrC name;
00190     aLandmark.GetLandmarkName(name);
00191     // 10 extra chars for icon index and column separator
00192     const TInt KExtraChars = 10;
00193     HBufC* formattedNameBuf = HBufC::NewLC(name.Length() + KExtraChars);
00194     TPtr formattedNamePtr = formattedNameBuf->Des();
00195 
00196     // Extract icon info
00197     TPtrC mbmIconFile;
00198     TInt iconIndex, maskIndex;
00199     TInt res = aLandmark.GetIcon(mbmIconFile, iconIndex, maskIndex);
00200 
00201     // Format list item
00202     if (res == KErrNone)
00203         {
00204         // Create icon and append it to icon array. 
00205         TRAPD(err, AppendIconL(mbmIconFile, iconIndex, maskIndex));
00206         if (err == KErrNone)
00207             {
00208             // Append the array index where the icon is appended
00209             formattedNamePtr.AppendNum(iIconList->Count() - 1);
00210             }
00211         else
00212             {
00213             formattedNamePtr.AppendNum(KDefaultIconIndex);
00214             }
00215         }
00216     else // res == KErrNotFound
00217         {
00218         formattedNamePtr.AppendNum(KDefaultIconIndex);
00219         }
00220     formattedNamePtr.Append(KTab);
00221     formattedNamePtr.Append(name);
00222 
00223     return formattedNameBuf;
00224     }

void CLandmarksModel::AppendIconL (  const TDesC &  aMbmFile,
TInt  aIconOffset,
TInt  aMaskOffset
)  [private]
 

Appends an icen to the icon array.

Parameters:
aMbmFile  the multi bitmap file containing the icon to add
aIconOffset  the offset in the mbm-file where the icon is located
aMaskOffset  the offset in the mbm-file where the icon mask is located

Definition at line 232 of file LandmarksModel.cpp.

References iIconList.

Referenced by FormatListItemLC().

00236     {
00237     TAknsItemID aknsItemId = {0,0};
00238     CGulIcon* icon = AknsUtils::CreateGulIconL(NULL, aknsItemId,
00239         aMbmFile, 
00240         aIconOffset, 
00241         aMaskOffset);
00242     CleanupStack::PushL(icon);
00243     icon->SetBitmapsOwnedExternally(EFalse);
00244     iIconList->AppendL(icon);
00245     CleanupStack::Pop(icon);
00246     }

void CLandmarksModel::ConstructL (   )  [private]
 

By default Symbian 2nd phase constructor is private.

Definition at line 49 of file LandmarksModel.cpp.

References iListItems.

00050         {
00051         // The list box model uses MDesCArray interface class to take in text items.
00052         iListItems = new (ELeave) CDesCArraySeg(KGranularity);
00053         }


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top