S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CLandmarksModel Class Reference

#include <LandmarksModel.h>

List of all members.

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


Detailed Description

Contains the data model of the landmarks view.

Definition at line 34 of file LandmarksModel.h.


Constructor & Destructor Documentation

CLandmarksModel::~CLandmarksModel (   ) 
 

Destructor.

Definition at line 69 of file LandmarksModel.cpp.

References iListItems.

00070         {
00071         delete iListItems;
00072         }

CLandmarksModel::CLandmarksModel (   )  [private]
 

C++ constructor.

Definition at line 39 of file LandmarksModel.cpp.

00040         {
00041         }


Member Function Documentation

CLandmarksModel * CLandmarksModel::NewL (   )  [static]
 

Two-phased constructor.

Definition at line 59 of file LandmarksModel.cpp.

References CLandmarksModel().

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

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

Sets the data member iItemIds

Parameters:
aItemIds a pointer to an array of item ids

Definition at line 80 of file LandmarksModel.cpp.

References iItemIds, and iListItems.

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

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 94 of file LandmarksModel.cpp.

References iListItems.

00095     {
00096     return iListItems;
00097     }

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 105 of file LandmarksModel.cpp.

References iCurrentItem.

00106     {
00107     iCurrentItem = aIndex;
00108     }

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 116 of file LandmarksModel.cpp.

References iCurrentItem, and iItemIds.

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

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 133 of file LandmarksModel.cpp.

References iIconList.

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

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

Repopulates a part of the model.

Parameters:
aLandmarks the landmarks to insert to the model

Definition at line 163 of file LandmarksModel.cpp.

References FormatListItemLC(), and iListItems.

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

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 185 of file LandmarksModel.cpp.

References AppendIconL(), and iIconList.

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

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 231 of file LandmarksModel.cpp.

References iIconList.

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

void CLandmarksModel::ConstructL (   )  [private]
 

By default Symbian 2nd phase constructor is private.

Definition at line 48 of file LandmarksModel.cpp.

References iListItems.

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


© Nokia 2006

Back to top