本文整理汇总了C++中CContactDatabase::SortL方法的典型用法代码示例。如果您正苦于以下问题:C++ CContactDatabase::SortL方法的具体用法?C++ CContactDatabase::SortL怎么用?C++ CContactDatabase::SortL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CContactDatabase
的用法示例。
在下文中一共展示了CContactDatabase::SortL方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetSortOrderL
// Helper function for RenameDefectL() below. Sets a sort ordering for the database.
//
LOCAL_C void SetSortOrderL(CContactDatabase& aDb, TFieldType aFieldType)
{
CArrayFix<CContactDatabase::TSortPref>* sortOrder=new(ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(3);
CleanupStack::PushL(sortOrder);
sortOrder->AppendL(CContactDatabase::TSortPref(aFieldType,CContactDatabase::TSortPref::EAsc));
aDb.SortL(sortOrder);
CleanupStack::Pop(); // sortOrder
}
示例2: DoSortL
GLDEF_C void DoSortL(CContactDatabase& aDb)
{
CContactTextDef* textDef=CContactTextDef::NewLC();
textDef->AppendL(TContactTextDefItem(KUidContactFieldGivenName));
textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName));
textDef->AppendL(TContactTextDefItem(KUidContactFieldCompanyName));
aDb.SetTextDefinitionL(textDef); // Takes ownership.
CleanupStack::Pop(); // textDef.
CArrayFix<CContactDatabase::TSortPref>* sortOrder=new(ELeave)CArrayFixFlat<CContactDatabase::TSortPref>(2);
CleanupStack::PushL(sortOrder);
sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldDefinedText));
aDb.SortL(sortOrder); // Takes ownership.
CleanupStack::Pop(); // sortOrder
}
示例3: DoTestsL
LOCAL_C void DoTestsL()
{
test.Start(_L("@SYMTESTCaseID:PIM-T-DB-SORTL-TEST-0001 T_DB_SortL_test"));
// create default, empty database
CContactDatabase* db = CContactDatabase::ReplaceL(KDbName);
CleanupStack::PushL(db);
// create contact 1 and add it to the db
CContactCard* contact1 = CContactCard::NewLC();
CContactItemField* fname1 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
_LIT(KFname1, "Aaron");
fname1->TextStorage()->SetTextL(KFname1() );
contact1->AddFieldL(*fname1);
CleanupStack::Pop(fname1);
CContactItemField* lname1 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
_LIT(KLname1, "Zimmerman");
lname1->TextStorage()->SetTextL(KLname1() );
contact1->AddFieldL(*lname1);
CleanupStack::Pop(lname1);
db->AddNewContactL(*contact1);
// create contact 2 and add it to the db
CContactCard* contact2 = CContactCard::NewLC();
CContactItemField* fname2 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
_LIT(KFname2, "Zachary");
fname2->TextStorage()->SetTextL(KFname2() );
contact2->AddFieldL(*fname2);
CleanupStack::Pop(fname2);
CContactItemField* lname2 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
_LIT(KLname2, "Abrahams");
lname2->TextStorage()->SetTextL(KLname2() );
contact2->AddFieldL(*lname2);
CleanupStack::Pop(lname2);
db->AddNewContactL(*contact2);
// fetch and print contact IDs. Expected order: 1, 2
const CContactIdArray* items = db->SortedItemsL(); // doesn't take ownership
_LIT(KFormattedIdList1, "Contact IDs *before* sorting: %d, %d\n");
test.Printf(KFormattedIdList1, (*items)[0], (*items)[1]);
TInt item1BeforeSort = (*items)[0];
TInt item2BeforeSort = (*items)[1];
// create sort order array
CArrayFix<CContactDatabase::TSortPref>* sortOrder = new (ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(2);
CleanupStack::PushL(sortOrder);
sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldFamilyName) );
sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldGivenName) );
// sort db and measure differences in heap allocations as a proxy for
// whether sortOrder has been deleted by SortL() or not.
TInt totalAllocSize(0);
TInt heapCellsDifference = User::AllocSize(totalAllocSize);
db->SortL(sortOrder);
heapCellsDifference -= User::AllocSize(totalAllocSize);
CleanupStack::Pop(sortOrder);
// fetch and print contact IDs. Expected order: 2, 1
items = db->SortedItemsL(); // doesn't take ownership
_LIT(KFormattedIdList2, "Contact IDs *after* sorting: %d, %d\n");
test.Printf(KFormattedIdList2, (*items)[0], (*items)[1]);
TInt item1AfterSort = (*items)[0];
TInt item2AfterSort = (*items)[1];
//check the sort order to make sure
test(item1BeforeSort == item2AfterSort);
test(item2BeforeSort == item1AfterSort);
// check to see if sortOrder is still usable
if (heapCellsDifference == 0)
{
// attempt to re-use sortOrder -- should be allowed after workaround
CContactDatabase::TSortPref sortPref( (*sortOrder)[0]);
_LIT(KSortOrderInfo, "The first sort order preference's field type is: %d.\n");
test.Printf(KSortOrderInfo, sortPref.iFieldType);
_LIT(KYesSame, "Yes, have successfully re-used sortOrder.\n");
test.Printf(KYesSame);
}
else
{
// looks like sortOrder has been deleted so don't try to use it
_LIT(KNoDifferent, "No, have not reused sortOrder as it has probably been deleted.\n");
test.Printf(KNoDifferent);
}
// cleanup
CleanupStack::PopAndDestroy(3, db); // and contact1, contact2
CContactDatabase::DeleteDatabaseL(KDbName);
test.End();
test.Close();
}