S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CLandmarksCategoriesModel Class Reference

#include <LandmarksCategoriesModel.h>

List of all members.

Public Member Functions

 ~CLandmarksCategoriesModel ()
void SetItemIds (RArray< TPosLmItemId > *aItemIds)
CDesCArraySeg * ItemList ()
void SetCurrentItem (TInt aIndex)
TPosLmItemId CurrentItemId ()
CIconList * CreateIconListL ()
void RepopulateModelL (CArrayPtr< CPosLandmarkCategory > *aCategories)

Static Public Member Functions

static CLandmarksCategoriesModel * NewL ()

Private Member Functions

 CLandmarksCategoriesModel ()
void ConstructL ()
HBufC * FormatListItemLC (CPosLandmarkCategory &aCategory)
void AppendIconL (const TDesC &aMbmFile, TInt aIconOffset, TInt aMaskOffset)

Private Attributes

RArray< TPosLmItemId > * iItemIds
 contains the ids idenetifying the categories in the DB
TInt iCurrentItem
 indicates which item in the model is selected
CDesCArraySeg * iListItems
CIconList * iIconList
 an array of category icons


Detailed Description

CLandmarksCategoriesModel holds the data displayed in the category listbox.

Definition at line 30 of file LandmarksCategoriesModel.h.


Constructor & Destructor Documentation

CLandmarksCategoriesModel::~CLandmarksCategoriesModel (   ) 
 

Destructor.

Definition at line 110 of file LandmarksCategoriesModel.cpp.

References iListItems.

00111         {
00112         delete iListItems;
00113         }

CLandmarksCategoriesModel::CLandmarksCategoriesModel (   )  [private]
 

C++ constructor.

Definition at line 79 of file LandmarksCategoriesModel.cpp.

00080         {
00081         }


Member Function Documentation

CLandmarksCategoriesModel * CLandmarksCategoriesModel::NewL (   )  [static]
 

Two-phased constructor.

Definition at line 99 of file LandmarksCategoriesModel.cpp.

References CLandmarksCategoriesModel().

00100     {
00101     CLandmarksCategoriesModel* self = 
00102         new (ELeave) CLandmarksCategoriesModel();
00103     CleanupStack::PushL(self);
00104     self->ConstructL();
00105     CleanupStack::Pop(self);
00106     return self;
00107     }

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

Sets the data member iItemIds

Parameters:
aItemIds a pointer to an array of item ids

Definition at line 121 of file LandmarksCategoriesModel.cpp.

References iItemIds, and iListItems.

00122     {
00123     iItemIds = aItemIds;
00124 
00125     // Empty descriptor model
00126     iListItems->Reset();
00127     }

CDesCArraySeg * CLandmarksCategoriesModel::ItemList (   ) 
 

ItemList returns a pointer to an array to be used for the listbox

Returns:
a pointer to an array of descriptors to be displayed in the listbox

Definition at line 135 of file LandmarksCategoriesModel.cpp.

References iListItems.

00136     {
00137     return iListItems;
00138     }

void CLandmarksCategoriesModel::SetCurrentItem (  TInt  aIndex  ) 
 

SetCurrentItem sets the item in the model that is selected in the listbox.

Parameters:
aIndex the index in the list box that is selected

Definition at line 146 of file LandmarksCategoriesModel.cpp.

References iCurrentItem.

00147     {
00148     iCurrentItem = aIndex;
00149     }

TPosLmItemId CLandmarksCategoriesModel::CurrentItemId (   ) 
 

CurrentItemId returns the id of the current item from the model.

Returns:
the id of the current item from the model, KPosLmNullItemId if there is no current item.

Definition at line 157 of file LandmarksCategoriesModel.cpp.

References iCurrentItem, and iItemIds.

00158     {
00159     if (iCurrentItem < 0 || iCurrentItem > iItemIds->Count() - 1)
00160         {
00161         return KPosLmNullItemId;
00162         }
00163 
00164     return (*iItemIds)[iCurrentItem];
00165     }

CIconList * CLandmarksCategoriesModel::CreateIconListL (   ) 
 

CreateIconListL creates and returns an array of icons that is displayed in the listbox. Caller takes ownership of the returned array.

Returns:
a pointer to an array to be displayed in the listbox

Definition at line 173 of file LandmarksCategoriesModel.cpp.

References iIconList.

00174     {
00175     CIconList* iconList = new (ELeave) CArrayPtrFlat<CGulIcon>(KGranularity);
00176     CleanupStack::PushL(TCleanupItem(ResetAndDestroyIcons, iconList));
00177     
00178     // Create the global category icon consisting of its image and mask.
00179     TAknsItemID aknsItemId ={0,0};
00180     CGulIcon* icon = AknsUtils::CreateGulIconL(NULL, aknsItemId,
00181         KLandmarksMbmFileName, 
00182         EMbmLmrefappCategory_global, 
00183         EMbmLmrefappCategory_global_mask);
00184     CleanupStack::PushL(icon);
00185     icon->SetBitmapsOwnedExternally(EFalse); 
00186     iconList->AppendL(icon);
00187     CleanupStack::Pop(icon);
00188 
00189     // Create the user defined category icon consisting of its image and mask.
00190     icon = AknsUtils::CreateGulIconL(NULL, aknsItemId,
00191         KLandmarksMbmFileName, 
00192         EMbmLmrefappCategory_user, 
00193         EMbmLmrefappCategory_user_mask);
00194     CleanupStack::PushL(icon);
00195     icon->SetBitmapsOwnedExternally(EFalse); 
00196     iconList->AppendL(icon);
00197     CleanupStack::Pop(icon);
00198     
00199     CleanupStack::Pop(); // iconList
00200 
00201     // initialze iIconList. We don't need to delete any possible previous 
00202     // iIconList since ownership is transferred to calling object.
00203     iIconList = iconList;
00204 
00205     return iconList;
00206     }

void CLandmarksCategoriesModel::RepopulateModelL (  CArrayPtr< CPosLandmarkCategory > *  aCategories  ) 
 

Repopulates a part of the model.

Parameters:
aCategories the categories to insert to the model

Definition at line 216 of file LandmarksCategoriesModel.cpp.

References FormatListItemLC(), and iListItems.

00218     {
00219     TInt nrOfReadItems = aCategories->Count();
00220 
00221     // Format and insert the read categories
00222     for (TInt i = 0; i < nrOfReadItems; i++)
00223         {
00224         // Format name and icon
00225         CPosLandmarkCategory* category = (*aCategories)[i];
00226         HBufC* formattedName = FormatListItemLC(*category);
00227 
00228         // Insert formatted descriptor into model
00229         iListItems->AppendL(*formattedName);
00230 
00231         CleanupStack::PopAndDestroy(formattedName);
00232         }
00233     }

void CLandmarksCategoriesModel::ConstructL (   )  [private]
 

By default Symbian 2nd phase constructor is private.

Definition at line 88 of file LandmarksCategoriesModel.cpp.

References iListItems.

00089         {
00090         // The list box model uses MDesCArray interface class to take in text items.
00091         iListItems = new(ELeave) CDesCArraySeg(KGranularity);
00092         }

HBufC * CLandmarksCategoriesModel::FormatListItemLC (  CPosLandmarkCategory &  aCategory  )  [private]
 

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

Parameters:
aCategory the category this list item will represent
Returns:
a formatted descriptor buffer

Definition at line 242 of file LandmarksCategoriesModel.cpp.

References AppendIconL(), and iIconList.

00243     {
00244     // Extract name
00245     TPtrC name;
00246     aCategory.GetCategoryName(name);
00247     // 10 extra chars for icon index and column separator
00248     const TInt KExtraChars = 10;
00249     HBufC* formattedNameBuf = HBufC::NewLC(name.Length() + KExtraChars);
00250     TPtr formattedNamePtr = formattedNameBuf->Des();
00251 
00252     // Extract icon info
00253     TPtrC mbmIconFile;
00254     TInt iconIndex, maskIndex;
00255     TInt res = aCategory.GetIcon(mbmIconFile, iconIndex, maskIndex);
00256 
00257     // Format list item
00258     if (res == KErrNone)
00259         {
00260         // Create icon and append it to icon array. 
00261         TRAPD(err, AppendIconL(mbmIconFile, iconIndex, maskIndex));
00262         if (err == KErrNone)
00263             {
00264             // Append the array index where the icon is appended
00265             formattedNamePtr.AppendNum(iIconList->Count() - 1);
00266             }
00267         else // Unable to create icon, use appropriate default icon.
00268             {
00269             formattedNamePtr.AppendNum(DefaultIconIndex(aCategory));
00270             }
00271         }
00272     else // res == KErrNotFound
00273         {
00274         formattedNamePtr.AppendNum(DefaultIconIndex(aCategory));
00275         }
00276     formattedNamePtr.Append(KTab);
00277     formattedNamePtr.Append(name);
00278 
00279     return formattedNameBuf;
00280     }

void CLandmarksCategoriesModel::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 288 of file LandmarksCategoriesModel.cpp.

References iIconList.

00292     {
00293     TAknsItemID aknsItemId = {0,0};
00294     CGulIcon* icon = AknsUtils::CreateGulIconL(NULL, aknsItemId,
00295         aMbmFile, 
00296         aIconOffset, 
00297         aMaskOffset);
00298     CleanupStack::PushL(icon);
00299     icon->SetBitmapsOwnedExternally(EFalse);
00300     iIconList->AppendL(icon);
00301     CleanupStack::Pop(icon);
00302     }


Member Data Documentation

CDesCArraySeg* CLandmarksCategoriesModel::iListItems [private]
 

Array of formated descriptors suitable to display in a column listbox

Definition at line 139 of file LandmarksCategoriesModel.h.


© Nokia 2006

Back to top