S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CLandmarksLmCategoriesModel Class Reference

#include <LandmarksLmCategoriesModel.h>

List of all members.

Public Member Functions

 ~CLandmarksLmCategoriesModel ()
void SelectCategoriesL (CArrayFixFlat< TInt > &aSelectedIndexes)
CDesCArray * FormattedCategoryNamesL ()
CArrayFixFlat< TInt > * SelectedCategoriesL ()

Static Public Member Functions

static CLandmarksLmCategoriesModel * NewL (CLandmarksApplicationEngine &aEngine, RArray< TPosLmItemId > &aMarkedCategories)

Private Member Functions

 CLandmarksLmCategoriesModel (RArray< TPosLmItemId > &aMarkedCategories)
void ConstructL (CLandmarksApplicationEngine &aEngine)

Private Attributes

CArrayPtr< CPosLandmarkCategory > * iCategories
 contains all existing categories
RArray< TPosLmItemId > & iMarkedCategoryIds
CDesCArrayFlat * iListItems


Detailed Description

CLandmarksLmCategoriesModel holds the data displayed in the category listbox in the landmarks category edit dialog.

Definition at line 34 of file LandmarksLmCategoriesModel.h.


Constructor & Destructor Documentation

CLandmarksLmCategoriesModel::~CLandmarksLmCategoriesModel (   ) 
 

Destructor.

Definition at line 74 of file LandmarksLmCategoriesModel.cpp.

References iCategories.

00075         {
00076     if (iCategories)
00077         {
00078         iCategories->ResetAndDestroy();
00079             delete iCategories;
00080         }
00081         }

CLandmarksLmCategoriesModel::CLandmarksLmCategoriesModel (  RArray< TPosLmItemId > &  aMarkedCategories  )  [private]
 

C++ constructor.

Parameters:
aMarkedCategories an array of selected landmarks.

Definition at line 40 of file LandmarksLmCategoriesModel.cpp.

00042 :   iMarkedCategoryIds(aMarkedCategories)
00043         {
00044         }


Member Function Documentation

CLandmarksLmCategoriesModel * CLandmarksLmCategoriesModel::NewL (  CLandmarksApplicationEngine &  aEngine,
RArray< TPosLmItemId > &  aMarkedCategories
)  [static]
 

Two-phased constructor.

Parameters:
aEngine the landmarks application engine.
aMarkedCategories an array of selected landmarks.

Definition at line 61 of file LandmarksLmCategoriesModel.cpp.

References CLandmarksLmCategoriesModel().

00064     {
00065     CLandmarksLmCategoriesModel* self = new (ELeave) 
00066         CLandmarksLmCategoriesModel(aMarkedCategories);
00067     CleanupStack::PushL(self);
00068     self->ConstructL(aEngine);
00069     CleanupStack::Pop(self);
00070     return self;
00071     }

void CLandmarksLmCategoriesModel::SelectCategoriesL (  CArrayFixFlat< TInt > &  aSelectedIndexes  ) 
 

Stores ids of selected categories.

Parameters:
aSelectedIndexes array of indexes of selected catgeories

Definition at line 89 of file LandmarksLmCategoriesModel.cpp.

References iMarkedCategoryIds, and LandmarksUtils::Panic().

00091     {
00092     // clear current list of selected categories
00093     iMarkedCategoryIds.Reset();
00094 
00095     for (TInt i = 0; i < aSelectedIndexes.Count(); i++)
00096         {
00097         TInt categoryIndex = aSelectedIndexes[i];
00098 
00099         // Fetch the id of the selected item.
00100         __ASSERT_ALWAYS((categoryIndex >= 0) && (categoryIndex < iCategories->Count()),
00101                         LandmarksUtils::Panic(KErrGeneral));
00102         TPosLmItemId selectedCategoryId = (*iCategories)[categoryIndex]->CategoryId();
00103 
00104         User::LeaveIfError(iMarkedCategoryIds.Append(selectedCategoryId));
00105         }
00106     }

CDesCArray * CLandmarksLmCategoriesModel::FormattedCategoryNamesL (   ) 
 

Returns a descriptor array of formatted list items.

Returns:
an descriptor array suitable for a two-column listbox

Definition at line 140 of file LandmarksLmCategoriesModel.cpp.

References iCategories, and iListItems.

00141     {
00142     // Granularity is set to be 8.
00143     CDesCArrayFlat* listItems = new (ELeave) CDesCArrayFlat(KGranularity);
00144     CleanupStack::PushL(listItems);
00145 
00146     for (TInt i = 0; i < iCategories->Count(); i++)
00147         {
00148         // Create buffer that will contain the name and mark status. 3 extra 
00149         // chars for tab and icon index.
00150         const TInt KExtraChars = 3; 
00151         TPtrC categoryName;
00152         User::LeaveIfError((*iCategories)[i]->GetCategoryName(categoryName));
00153         HBufC* formattedCategoryName = HBufC::NewLC(categoryName.Length() + KExtraChars);
00154 
00155         // format string with category
00156         formattedCategoryName->Des().Format(KItemFormat, &categoryName);
00157 
00158         listItems->AppendL(*formattedCategoryName);
00159         CleanupStack::PopAndDestroy(formattedCategoryName);
00160         }
00161 
00162     CleanupStack::Pop(listItems);
00163 
00164     iListItems = listItems;
00165     return iListItems;
00166     }

CArrayFixFlat< TInt > * CLandmarksLmCategoriesModel::SelectedCategoriesL (   ) 
 

Returns array of indices of selected categories.

Returns:
array of indexes of selected catgeories

Definition at line 114 of file LandmarksLmCategoriesModel.cpp.

References iMarkedCategoryIds.

00115     {
00116     CArrayFixFlat<TInt>* selectedItems = new (ELeave) CArrayFixFlat<TInt>(KGranularity);
00117     CleanupStack::PushL(selectedItems);
00118 
00119     for (TInt i = 0; i < iCategories->Count(); i++)
00120         {
00121         TPosLmItemId categoryId = (*iCategories)[i]->CategoryId();
00122 
00123                 TInt index = iMarkedCategoryIds.Find(categoryId);
00124         if (KErrNotFound != index)
00125                 {
00126                 selectedItems->AppendL(i);
00127                 }
00128         }
00129 
00130         CleanupStack::Pop(selectedItems);        
00131         return selectedItems;        
00132     }

void CLandmarksLmCategoriesModel::ConstructL (  CLandmarksApplicationEngine &  aEngine  )  [private]
 

By default Symbian 2nd phase constructor is private.

Parameters:
aEngine the landmarks application engine.

Definition at line 51 of file LandmarksLmCategoriesModel.cpp.

References CLandmarksApplicationEngine::CategoriesL(), and iCategories.

00052         {
00053     iCategories = aEngine.CategoriesL();
00054         }


Member Data Documentation

RArray<TPosLmItemId>& CLandmarksLmCategoriesModel::iMarkedCategoryIds [private]
 

contains Ids for those categories that are selected for the edited landmark.

Definition at line 100 of file LandmarksLmCategoriesModel.h.

CDesCArrayFlat* CLandmarksLmCategoriesModel::iListItems [private]
 

An array of formatted category names suitable for a two-column listbox.

Definition at line 104 of file LandmarksLmCategoriesModel.h.


© Nokia 2006

Back to top