/*!
 Tests albumArt() request when album art is not in local cache.
 Single request.
 */
void TestMpCollectionAlbumArtManager::testAlbumArtNoCache()
{
    const HbIcon icon = mTest->albumArt(1);
    // Verify that:
    // - It returned default icon
    // - A request has been made to thumbnail manager
    QVERIFY(icon.isNull() == false);
    QCOMPARE(mTest->mPendingRequest, true);
    QCOMPARE(mTest->mThumbnailManager->mThumbnailReqCounter, 1);
}
/*!
 Tests albumArt() request when thumbnail request fails.
 */
void TestMpCollectionAlbumArtManager::testAlbumArtFail()
{
    mTest->mThumbnailManager->mGetThumbFails = true;
    const HbIcon icon = mTest->albumArt(0);
    // Verify that:
    // - It returned default icon
    // - There is no request pending from thumbnail manager
    QVERIFY(icon.isNull() == false);
    QCOMPARE(mTest->mPendingRequest, false);
    QCOMPARE(mTest->mRequestQueue.count(), 0);
}
/*!
 Tests albumArt() request when art is in local cache.
 */
void TestMpCollectionAlbumArtManager::testAlbumArtCache()
{
    mTest->mImageCache.insert(0, new HbIcon(mIcon));

    const HbIcon icon = mTest->albumArt(0);
    // Verify that:
    // - A valid icon has been returned
    // - No request has been sent to thumbnail manager
    QVERIFY(icon.isNull() == false);
    QCOMPARE(mTest->mPendingRequest, false);
    QCOMPARE(mTest->mRequestQueue.count(), 0);
    QCOMPARE(mTest->mThumbnailManager->mThumbnailReqCounter, 0);
}
/*!
 Tests albumArt() request when art is not in local cache.
 Request more than 1 to test request queue.
 */
void TestMpCollectionAlbumArtManager::testAlbumArtNoCacheQueue()
{
    for ( int i = 0; i < 3; i++) {
        const HbIcon icon = mTest->albumArt(i);
        QVERIFY(icon.isNull() == false);
    }
    // Verify that:
    // - Max number of requests were sent to thumbnail manager
    // - A request has been queued
    QCOMPARE(mTest->mPendingRequest, true);
    QCOMPARE(mTest->mRequestQueue.count(), 2);
    QCOMPARE(mTest->mThumbnailManager->mThumbnailReqCounter, 1);
}
/*!
 Get icon.
 \param entry const reference to CaEntry.
 \param sie const reference to icon size.
 \retval icon.
 */
HbIcon CaMenuIconUtility::getEntryIcon(const CaEntry& entry,
        const QSizeF &size)
{
    HbIcon icon;
    QString filename(entry.iconDescription().filename());
    if (!filename.isEmpty()) {
        icon = HbIcon(filename);
    }
    if (icon.isNull() || !(icon.size().isValid())) {
        icon = HbIcon(QDir(".").absoluteFilePath("resource/application.png"));
    }
    if (entry.entryTypeName() == "widget") {
        icon.addBadge(Qt::AlignBottom | Qt::AlignLeft,
                    HbIcon("qtg_small_homescreen"));
    }
    return icon;
}
/*!
 Tests cancel() request.
 */
void TestMpCollectionAlbumArtManager::testCancel()
{
    // First send enough requests to trigger requests to be queued.
    for ( int i = 0; i < 3; i++) {
        const HbIcon icon = mTest->albumArt(i);
        QVERIFY(icon.isNull() == false);
    }
    QCOMPARE(mTest->mPendingRequest, true);
    QCOMPARE(mTest->mRequestQueue.count(), 2);
    QCOMPARE(mTest->mThumbnailManager->mThumbnailReqCounter, 1);

    // Verify that:
    // - All requests to thumbnail manager are cancelled
    // - Queue is emptied
    mTest->cancel();
    QCOMPARE(mTest->mPendingRequest, false);
    QCOMPARE(mTest->mRequestQueue.count(), 0);
    QCOMPARE(mTest->mThumbnailManager->mCancelCounter, 1);
}
/*!
    @alpha

    Sets \a icon for the item at the given \a index in the combobox.
    This API will not work if applcation sets the model as QStringListModel.
*/
void HbComboBox::setItemIcon( int index, const HbIcon &icon )
{
    Q_D( const HbComboBox );
    if( d->mModel ) {
        QModelIndex item = d->mModel->index( index, 0 );
        if ( item.isValid( ) ) {
            d->mModel->setData( item, icon.qicon( ), Qt::DecorationRole );
        }
    }
}
CpSettingFormEntryItemData::CpSettingFormEntryItemData(HbDataForm *dataForm,
        const QString &text /*= QString()*/,
        const QString &description /*= QString()*/,
        const HbIcon &icon /*= HbIcon()*/,
        const HbDataFormModelItem *parent/* = 0*/) :
        CpSettingFormItemData(HbDataFormModelItem::CustomItemBase,QString(),parent),
        d_ptr(new CpSettingFormEntryItemDataPrivate(dataForm))
{
	setType ( static_cast<HbDataFormModelItem::DataItemType> (CpSettingFormEntryItemData::ListEntryItem) );
	
	d_ptr->init(this);
	
    setText(text);
    setDescription(description);
    setIcon(icon.iconName());
}
Beispiel #9
0
/*!
     Test Case Description: \n
         Verify this class could create the corresponding CpSettingFormEntryItemData. \n
	 <b>Function 1:</b> \n
     1. Fucntion Name: \n &nbsp;&nbsp;
            explicit CpSettingFormEntryItemDataImpl(CpItemDataHelper &itemDataHelper,const QString &text = QString(), \n
                                                    const QString &description = QString(),const HbIcon &icon = HbIcon(), \n
                                                    const HbDataFormModelItem *parent = 0) \n
     2. Case Descrition: \n &nbsp;&nbsp;
            Test the first constructor function. \n
     3. Input Parameters: \n &nbsp;&nbsp;
            <1> itemDataHelper = CpItemDataHelper, text = Qstring(XX),description = Qstring(XX),
            	  icon = HbIcon(), parent = new HbDataFormModelItem() \n &nbsp;&nbsp;
            <2> itemDataHelper = CpItemDataHelper , text = Qstring(),
            	  description = Qstring(), icon = HbIcon(), parent = 0 \n
     4. Expected result: \n &nbsp;&nbsp;
            <1>  pdataimp != 0 \n &nbsp;&nbsp;
            <2> no crash  \n
    <b>Function 2:</b> \n
	 1. Fucntion Name: \n &nbsp;&nbsp;
        explicit CpSettingFormEntryItemDataImpl(HbDataForm *dataForm,const QString &text = QString(), \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
        																				const QString &description = QString(),const HbIcon &icon = HbIcon(), \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
        																				   const HbDataFormModelItem *parent = 0) \n 
     2.  Case Descrition: \n &nbsp;&nbsp;
         Test the second constructor function. \n
     3.  Input Parameters: \n &nbsp;&nbsp;
            <1> dataform = new HbDataForm(), text = Qstring(XX), description Qstring(XX), 
            	  icon = HbIcon(XX), parent = new HbDataFormModelItem(), \n &nbsp;&nbsp;
						<2> dataForm = 0, text = Qstring(), description Qstring(), icon = HbIcon(), parent = 0 \n
     4.  Expected result: \n &nbsp;&nbsp;
            pdata != 0 \n      
     <b>Function 3:</b> \n
	 1. Fucntion Name: \n &nbsp;&nbsp;
         explicit CpSettingFormEntryItemDataImpl(EntryItemType type,CpItemDataHelper &itemDataHelper, \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
         																				 const QString &text = QString(),const QString &description = QString(), \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
         																				 const QString &icon = QString(),const HbDataFormModelItem *parent = 0)  \n 
     2. Case Descrition: \n &nbsp;&nbsp;
         Test the third constructor function. \n
     3. Input Parameters: \n &nbsp;&nbsp;
            <1> type = HbDataFormModelItem::DataItemType,  itemDataHelper = CpItemDataHelper, \n &nbsp;&nbsp; &nbsp;&nbsp;
            	  text = QString(XX),  description = QString(XX),  icon = QString(XX), parent = new HbDataFormModelItem() \n &nbsp;&nbsp;
			<2> type = HbDataFormModelItem::DataItemType,  itemDataHelper = CpItemDataHelper default, \n &nbsp;&nbsp;
							  text = QString(),  description = QString(),  icon = QString(), parent = 0 \n
     4. Expected result: \n &nbsp;&nbsp;
            <1> pdataimp != 0, pdataimp->icon() != icon,\n &nbsp;&nbsp;
			<2> pdataimp != 0, pdataimp->icon() == 0, \n            
     <b>Function 4:</b> \n
	 1. Fucntion Name: \n &nbsp;&nbsp;
         explicit CpSettingFormEntryItemDataImpl(EntryItemType type,HbDataForm *dataForm,const QString &text = QString(),\n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
            																		 const QString &description = QString(),const QString &icon = QString(),\n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
            																		 const HbDataFormModelItem *parent = 0) \n
     2. Case Descrition: \n &nbsp;&nbsp;
         Test the forth constructor function. \n
     3. Input Parameters: \n &nbsp;&nbsp;
            <1> type = HbDataFormModelItem::DataItemType, dataform = new HbDataForm(),   \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
            	  text = QString(XX),  description = QString(XX),  icon = QString(XX), parent = new HbDataFormModelItem() \n &nbsp;&nbsp;
            <2> type = HbDataFormModelItem::DataItemType,  dataform = 0, text = QString(),   \n &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
            		description = QString(),  icon = QString(), parent = 0 \n
     4. Expected result: \n &nbsp;&nbsp;
            <1> pdataimp != 0, pdataimp->icon() != icon,\n &nbsp;&nbsp;
			<2> pdataimp != 0, pdataimp->icon() == 0, \n   						    
*/
void TestCpAPI::testCpSettingFormEntryItemDataImpl()
{
    //Define the parameters for the constructors.
    QString strText = "testText";
    QString strDes = "testDescription";
    QString strIcon = "iconString";
    CpItemDataHelper *pHelper = new CpItemDataHelper();
    HbDataFormModelItem *aParent = new HbDataFormModelItem();
    HbIcon icon = HbIcon("icon");  
    HbDataForm *pDataform = new HbDataForm();
    CpSettingFormEntryItemData::EntryItemType EType1 = CpSettingFormEntryItemData::ListEntryItem;
    CpSettingFormEntryItemData::EntryItemType EType2 = CpSettingFormEntryItemData::ButtonEntryItem;
    // test the first constructor function.
    CpSettingFormEntryItemDataImpl<CpBaseSettingView> *pdataimp =
            new CpSettingFormEntryItemDataImpl<CpBaseSettingView>( *pHelper, strText, strDes, icon, aParent ); // first constructor
    QVERIFY (pdataimp != 0);
    QVERIFY( pdataimp->text() == strText );
    QVERIFY( pdataimp->description()==strDes );
    QVERIFY( pdataimp->icon() == icon.iconName() );
    delete pdataimp;
    pdataimp = 0; 
    pdataimp = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>( *pHelper, QString(), QString(), icon, 0);
    QVERIFY (pdataimp != 0);
    delete pdataimp;
    pdataimp = 0; 
        
    pdataimp = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>(0); // set parameter as "0"
    QVERIFY (pdataimp != 0);
    QVERIFY( pdataimp->text() == 0 );
    QVERIFY( pdataimp->description()==0 );
    delete pdataimp;
    pdataimp = 0;
    // test the second constructor function.
    pdataimp = new CpSettingFormEntryItemDataImpl <CpBaseSettingView> ( pDataform,strText, strDes, icon, aParent ); //second contructor
    QVERIFY( pdataimp->text() == strText );
    QVERIFY( pdataimp->description()==strDes );
    QVERIFY( pdataimp->icon() == icon.iconName() );
    delete pdataimp;
    pdataimp = 0;
    pdataimp = new CpSettingFormEntryItemDataImpl <CpBaseSettingView> ( 0, QString(), QString(), icon, 0 );
    QVERIFY (pdataimp != 0);
    delete pdataimp;
    pdataimp = 0; 
    // test the third constructor function.
    pdataimp = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>( EType1,*pHelper, strText, strDes, strIcon, aParent );// the third constructor
    HbDataFormModelItem::DataItemType EdataItmeTypeTemp1 = pdataimp->type();
    QVERIFY (EdataItmeTypeTemp1 == EType1);
    QVERIFY( pdataimp->text() == strText );
    QVERIFY( pdataimp->description()==strDes );
    QVERIFY( pdataimp->icon() == strIcon );
    delete pdataimp;
    pdataimp = 0;    
    // test the forth constructor function.
    pdataimp = new CpSettingFormEntryItemDataImpl<CpBaseSettingView>(EType2,pDataform, strText, strDes, strIcon, aParent );// the fourth constructor
    CpSettingFormEntryItemData::DataItemType EdataItmeTypeTemp2 = pdataimp->type();
    QVERIFY (EdataItmeTypeTemp2 == EType2);
    QVERIFY( pdataimp->text() == strText );
    QVERIFY( pdataimp->description()==strDes );
    QVERIFY( pdataimp->icon() == strIcon );
    delete pdataimp;
    pdataimp = 0;
  
    delete pHelper;
    pHelper=0;
    delete pDataform;
    pDataform = 0;
}
Beispiel #10
0
/*!
    @beta

    Inserts the \a text and \a icon into the combobox at the given \a index.
    If the index is equal to or higher than the total number of items, 
    the new item is appended to the list of existing items.
    If the index is zero or negative, the new item is prepended to the list of existing items.

    \sa insertItem
 */
void HbComboBox::insertItem( int index, const HbIcon &icon,
    const QString &text, const QVariant &userData )
{
    Q_D( HbComboBox );
    if( text.isEmpty( ) ) {
        return;
    }

    if( !d->mModel ) {
        QStandardItemModel* model = new QStandardItemModel( this );
        setModel( model );
    }
    if ( !d->mModel->rowCount( ) ) {
        d->mModel->insertRow( 0 );
        d->mModel->insertColumn( 0 );
        if( d->mModel->index( 0, 0 ).isValid( ) ) {
            d->mModel->setData( d->mModel->index( 0, 0 ), text, Qt::DisplayRole );
            setCurrentIndex( 0 );
        }
        if( !icon.isNull( ) && d->mModel->index( 0, 0 ).isValid( ) ) {
            d->mModel->setData( d->mModel->index( 0, 0 ), icon.qicon( ), Qt::DecorationRole );
        }
        if( userData.isValid( ) && d->mModel->index( 0, 0 ).isValid( ) ) {
            d->mModel->setData( d->mModel->index( 0, 0 ), userData, Qt::UserRole );
        }
    } else {
        int rowCount = d->mModel->rowCount( );
        if( index >= rowCount ) {
            d->mModel->insertRow( rowCount );
            d->mModel->setData( d->mModel->index( rowCount, 0 ), text, Qt::DisplayRole );
            if( !icon.isNull( ) ) {
                d->mModel->setData( d->mModel->index( rowCount, 0 ), icon, Qt::DecorationRole );
            }
            if( userData.isValid( ) ) {
                d->mModel->setData( d->mModel->index( rowCount, 0 ), userData, Qt::UserRole );
            }
            if( d->mCurrentIndex.row( ) == index ) {
                d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0 );
                d->currentIndexChanged( d->mCurrentIndex );
            }
        } else if( index <= 0 ) {
            d->mModel->insertRow( 0 );
            d->mModel->setData( d->mModel->index( 0, 0 ), text, Qt::DisplayRole );
            if( !icon.isNull( ) ) {
                d->mModel->setData( d->mModel->index( 0, 0 ), icon, Qt::DecorationRole );
            }
            if( userData.isValid( ) ) {
                d->mModel->setData( d->mModel->index( 0, 0 ), userData, Qt::UserRole );
            }
            if( d->mCurrentIndex.row( ) >= 0 ) {
                d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0 );
                d->currentIndexChanged( d->mCurrentIndex );
            }
        } else {
            d->mModel->insertRow( index );
            d->mModel->setData( d->mModel->index( index, 0 ), text, Qt::DisplayRole );
            if( !icon.isNull( ) ) {
                d->mModel->setData( d->mModel->index( index, 0 ), icon, Qt::DecorationRole );
            }
            if( userData.isValid( ) ) {
                d->mModel->setData( d->mModel->index( index, 0 ), userData, Qt::UserRole );
            }
            if( d->mCurrentIndex.row( ) <= index ) {
                d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0 );
                d->currentIndexChanged( d->mCurrentIndex );
            }
        }
    }
}