当前位置: 首页>>代码示例>>C++>>正文


C++ CContactDatabase::SortedItemsL方法代码示例

本文整理汇总了C++中CContactDatabase::SortedItemsL方法的典型用法代码示例。如果您正苦于以下问题:C++ CContactDatabase::SortedItemsL方法的具体用法?C++ CContactDatabase::SortedItemsL怎么用?C++ CContactDatabase::SortedItemsL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CContactDatabase的用法示例。


在下文中一共展示了CContactDatabase::SortedItemsL方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TestPhoneMatchingL

void TestPhoneMatchingL(CContactDatabase& aDb)
    {
    test.Next(_L("Test phone match"));

    CContactIdArray* array = aDb.MatchPhoneNumberL(KTelephoneNum,KMaxPhoneMatchLength);	
    test(array->Count() == 4);
    delete array;

    syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
    syncChecker->SetValidateResponseL(MContactSynchroniser::EEdit, KErrNone);
    syncChecker->SetValidateWriteResponseL(KErrNone);
    aDb.SetDbViewContactType(KUidContactICCEntry);
    TContactItemId id = (*aDb.SortedItemsL())[0];
    CContactItem* item = aDb.OpenContactLX(id);
    CleanupStack::PushL(item);
    CContactItemFieldSet& fieldset = item->CardFields();
    const TInt pos = fieldset.Find(KUidContactFieldPhoneNumber);	
    CContactItemField& field = fieldset[pos];
    CContactTextField* textfield = field.TextStorage();
    textfield->SetTextL(KTelephoneNumModified);
    aDb.CommitContactL(*item);
    CleanupStack::PopAndDestroy(2); //item, lock record

    CContactIdArray* array2 = aDb.MatchPhoneNumberL(KTelephoneNumModified,KMaxPhoneMatchLength);	
    test(array2->Count() == 1);
    delete array2;
    }
开发者ID:Esclapion,项目名称:qt-mobility,代码行数:27,代码来源:t_iccentry.cpp

示例2: 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();
    }
开发者ID:,项目名称:,代码行数:93,代码来源:


注:本文中的CContactDatabase::SortedItemsL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。