src/hbwidgets/widgets/hbcombobox.cpp
changeset 3 11d3954df52a
parent 2 06ff229162e9
child 5 627c4a0fd0e7
equal deleted inserted replaced
2:06ff229162e9 3:11d3954df52a
    45 
    45 
    46     A HbComboBox provides a means of presenting a list of options to the user
    46     A HbComboBox provides a means of presenting a list of options to the user
    47     in a way that takes up the minimum amount of screen space.
    47     in a way that takes up the minimum amount of screen space.
    48 
    48 
    49     A combobox is a selection widget that displays the currently selected item,
    49     A combobox is a selection widget that displays the currently selected item,
    50     and can provides a drop-down list that permits selecting an item.
    50     and provides a drop-down list that permits selecting an item.
    51     
    51     
    52     A HbComboBox with currently Selected item
    52     A HbComboBox with currently selected item
    53     \image html noneditablecombobox.png.
    53     \image html noneditablecombobox.png.
    54 
    54 
    55 
    55 
    56     A HbComboBox with drop-down list to select an item from list of options
    56     A HbComboBox with drop-down list to select an item from list of options
    57     \image html comboboxdropdownlist.png.
    57     \image html comboboxdropdownlist.png.
    58 
    58 
    59 
    59 
    60     HbComboBox are of two types. 
    60     HbComboBox are of two types:
    61 
    61 
    62     Editable:
    62     1: Editable:
    63 
    63 
    64     If the comboBox is set to editable, touching the ComboBox label field invokes the VKB in
    64     If combobox is set to editable, tapping on combobox label field invokes the VKB in
    65     touch environments or accepts input from an attached keyboard.
    65     touch environments or accepts input from an attached keyboard. Tapping on 
    66     choosing an element from the ComboBox dropdown list replaces the label 
    66     button area of combobox launches dropdown list. Choosing an element from 
    67     area with the chosen item.
    67     the combobox dropdown list replaces the label with the chosen item. Touch events on
    68     on touching button area of the comboBox launches the drop-down list to select
    68     combobox button behaves same in both editable and non-editable combobox.
    69     the list of options 
    69 
    70     ( button area in comboBox behaves same in both editable and Non Editable comboBox ).
    70     2: Non Editable:
    71 
       
    72     Non Editable:
       
    73     
    71     
    74     If the comboBox is set to Non Editable widget that displays the currently selected item
    72     If the combobox is set to non-editable then even tapping on label field will launch 
    75     in the label field of ComboBox.
    73     drop down unlike editable combobox. Tapping on combobox button area behaves in 
    76     Touching the comboBox label field or button area of the comboBox will opens
    74     same way as in editable combobox.
    77     the drop-down list to select an item from list of options.
    75 
    78 
    76     By default combobox is non-editable. 
    79     By Default comboBox is Non Editable. 
    77 
    80 
    78     Application is responsible for setting the model in combobox. If no model is set or model
    81     Application is responsible for setting the model to the HbComboBox,
    79     set is empty then drop down list will not be displayed at all. Combobox owns the model set 
    82     If no model is set, the drop down list cannot be displayed at all.
    80     by application.
    83 
    81 
    84     HbComboBox owns the model set by the Application.
    82     The number of rows to be displayed in HbComboBox drop down can be configured by overriding
    85 
    83     HbComboBox css. By default number of items in drop down is 8 in portrait mode and 5 in
    86     HbComboBox provides three signals:
    84     landscape mode.
       
    85 
       
    86     HbComboBox provides four signals:
    87 
    87 
    88     \li currentIndexChanged( index ) is emitted when the current selection in the combobox is
    88     \li currentIndexChanged( index ) is emitted when the current selection in the combobox is
    89     changed by user interaction. If application is setting a index/text then this signal is
    89     changed either by user interaction or programmatically.
    90     not emmitted. In case of an editable combobox on combobox loosing focus if the current
       
    91     selection has changed then this signal is emitted with the new model index.
       
    92 
    90 
    93     \li currentIndexChanged( const QString& ) is emitted when the curret selection in the combobox
    91     \li currentIndexChanged( const QString& ) is emitted when the curret selection in the combobox
    94     is changed by user interaction. If application is setting a differnet index/text
    92     is changed by user interaction. If application is setting a differnet index/text
    95     then this signal is not emmitted. 
    93     then this signal is not emmitted.
    96     In case of an editable combobox on combobox loosing focus if the current selection
    94 
    97     has changed then this signal is emitted with the new string.
    95     \li editTextChanged( const QString& ) is emitted when text is changed in editable combobox.
    98 
    96 
    99     \li editTextChanged( QString& ) is emitted when combobox looses focus and user has typed a text
    97     \li editingFinished( ) is emitted either because editable combobox lost focus or Return/Enter 
   100     for which there is no matching item found in the model with the text typed by the user.
    98     is pressed.
   101 
    99 
   102     The following is an example of how to create a model and adding item to the created model.
   100     The following is an example of how to create a model and adding item in the model.
   103     How to set the model on the HbcomboBox.
   101     HbComboBox takes ownership of model.
   104     Here the model is ownership transfer to the widget.
       
   105     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,37}
   102     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,37}
   106 
   103 
   107     An example how to add strings into HbComboBox and setting currentIndex.
   104     An example of how to add strings in HbComboBox and setting currentIndex.
   108     HbComboBox will creates the model internally if model is not created.
   105     HbComboBox will creates model internally if model is not created.
   109     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,38}
   106     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,38}
   110 
   107 
   111     An example how to add stringsList into HbComboBox and setting currentIndex.
   108     An example of how to add stringsList into HbComboBox and setting currentIndex.
   112     HbComboBox will creates the model internally if model is not created.
   109     HbComboBox will creates the model internally if model is not created.
   113     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,39}
   110     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,39}
   114 
   111 
   115     An example how to insert String at index into HbComboBox.
   112     An example of how to insert string at some index in HbComboBox.
   116     HbComboBox will creates the model internally if model is not created.
   113     HbComboBox will creates the model internally if model is not created.
   117     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,40}
   114     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,40}
   118 
   115 
   119     An example how to insert StringList at index into HbComboBox.
   116     An example of how to insert StringList at index into HbComboBox.
   120     HbComboBox will creates the model internally if model is not created.
   117     HbComboBox will creates the model internally if model is not created.
   121     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,41}
   118     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,41}
   122 
   119 
   123     An example how to set the items into HbComboBox.
   120     An example of how to set the items into HbComboBox.
   124     HbComboBox will replces the existing model.
   121     HbComboBox will replace the existing model.
   125     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,42}
   122     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,42}
   126 
   123 
   127 */
   124 */
   128 
   125 
   129 
   126 
   134     HbWidget( *new HbComboBoxPrivate, parent )
   131     HbWidget( *new HbComboBoxPrivate, parent )
   135 {
   132 {
   136     Q_D( HbComboBox );
   133     Q_D( HbComboBox );
   137     d->init( );
   134     d->init( );
   138     updatePrimitives( );
   135     updatePrimitives( );
   139     setProperty("state", "normal");
   136     setProperty( "state", "normal" );
   140 }
   137 }
   141 
   138 
   142 /*!
   139 /*!
   143     Destructor.
   140     Destructor.
   144  */
   141  */
   153     HbWidget( dd, parent )
   150     HbWidget( dd, parent )
   154 {
   151 {
   155     Q_D( HbComboBox );
   152     Q_D( HbComboBox );
   156     d->init( );
   153     d->init( );
   157     updatePrimitives( );
   154     updatePrimitives( );
   158     setProperty("state", "normal");
   155     setProperty( "state", "normal" );
   159 }
   156 }
   160 
   157 
   161 /*!
   158 /*!
   162     @beta
   159     @beta
       
   160 
   163     \property HbComboBox::items
   161     \property HbComboBox::items
   164     \brief list of comboBox items
   162 
   165     It replaces the existing list.
   163     It replaces the existing list with \a texts.
   166 */
   164 */
   167 void HbComboBox::setItems( const QStringList &texts )
   165 void HbComboBox::setItems( const QStringList &texts )
   168 {  
   166 {  
   169     if ( texts.isEmpty( ) ) {
   167     if ( texts.isEmpty( ) ) {
   170         return;
   168         return;
   180    setModel( model );
   178    setModel( model );
   181 }
   179 }
   182 
   180 
   183 /*!
   181 /*!
   184     @beta
   182     @beta
       
   183 
   185     This property holds the list added in the combobox.
   184     This property holds the list added in the combobox.
   186     By default, for an empty combo box, this property has a empty StringList. 
   185     By default, for an empty combo box, this property has a empty StringList. 
   187  */
   186  */
   188 QStringList HbComboBox::items( ) const
   187 QStringList HbComboBox::items( ) const
   189 {
   188 {
   190     Q_D( const HbComboBox );
   189     Q_D( const HbComboBox );
   191     if( d->mModel && d->mModel->rowCount( )) {
   190     if( d->mModel && d->mModel->rowCount( ) ) {
   192         QStringList list;
   191         QStringList list;
   193         int rowCount = d->mModel->rowCount();
   192         int rowCount = d->mModel->rowCount( );
   194         for(int i = 0; i < rowCount; i++)
   193         for(int i = 0; i < rowCount; i++) {
   195         {
   194             list<<( d->mModel->data( d->mModel->index( i, 0 ) ) ).toString( );
   196             list<<( d->mModel->data( d->mModel->index( i, 0 ) ) ).toString();
       
   197         }
   195         }
   198         return list;
   196         return list;
   199     } else {
   197     } else {
   200       return QStringList();
   198       return QStringList( );
   201     }
   199     }
   202 }
   200 }
   203 
   201 
   204 /*!
   202 /*!
   205     @alpha
   203     @alpha
   206     Sets the \a icon for the item on the given \a index in the combobox.
   204 
   207     this API will not work if applcation sets the model as QStringlistModel.
   205     Sets \a icon for the item at the given \a index in the combobox.
       
   206     This API will not work if applcation sets the model as QStringListModel.
   208 */
   207 */
   209 void HbComboBox::setItemIcon( int index, const HbIcon &icon )
   208 void HbComboBox::setItemIcon( int index, const HbIcon &icon )
   210 {
   209 {
   211     Q_D(const HbComboBox);
   210     Q_D( const HbComboBox );
   212     if(d->mModel) {
   211     if( d->mModel ) {
   213         QModelIndex item = d->mModel->index( index, 0 );
   212         QModelIndex item = d->mModel->index( index, 0 );
   214         if ( item.isValid( ) ) {        
   213         if ( item.isValid( ) ) {
   215             d->mModel->setData( item, icon.qicon(), Qt::DecorationRole );
   214             d->mModel->setData( item, icon.qicon( ), Qt::DecorationRole );
   216         }
   215         }
   217     }
   216     }
   218 }
   217 }
   219 
   218 
   220 /*!
   219 /*!
   221     @alpha
   220     @alpha
   222     returns the HbIcon for the given \a index in the combobox.
   221 
       
   222     Returns HbIcon at \a index in the combobox.
   223 */
   223 */
   224 HbIcon HbComboBox::itemIcon( int index ) const
   224 HbIcon HbComboBox::itemIcon( int index ) const
   225 {
   225 {
   226     Q_D( const HbComboBox );
   226     Q_D( const HbComboBox );
   227     if( d->mModel ) {
   227     if( d->mModel ) {
   233     return HbIcon( );
   233     return HbIcon( );
   234 }
   234 }
   235 
   235 
   236 /*!
   236 /*!
   237     @beta
   237     @beta
   238     Returns the data for the given \a role in the given \a index in the
   238 
   239     combobox, or QVariant::Invalid if there is no data for this role.
   239     Either returns the \a role data at this \a index in HbComboBox, or QVariant::Invalid 
       
   240     if there is no data for this role.
   240 */
   241 */
   241 QVariant HbComboBox::itemData( int index, int role ) const
   242 QVariant HbComboBox::itemData( int index, int role ) const
   242 {
   243 {
   243     Q_D( const HbComboBox );
   244     Q_D( const HbComboBox );
   244     if( d->mModel ) {
   245     if( d->mModel ) {
   245         QModelIndex mi = d->mModel->index( index, 0 );
   246         QModelIndex mi = d->mModel->index( index, 0 );
   246         if( mi.isValid ( ) ) {
   247         if( mi.isValid ( ) ) {
   247             return d->mModel->data( mi, role );
   248             return d->mModel->data( mi, role );
   248         } 
   249         }
   249     }
   250     }
   250     return QVariant( );
   251     return QVariant( );
   251 }
   252 }
   252 
   253 
   253 /*!
   254 /*!
   254     @beta
   255     @beta
   255     Sets the data \a role for the item on the given \a index in the combobox
   256 
       
   257     Sets the \a role data for the item at the given \a index in HbComboBox
   256     to the specified \a value.
   258     to the specified \a value.
   257 */
   259 */
   258 void HbComboBox::setItemData( int index, const QVariant &value, int role )
   260 void HbComboBox::setItemData( int index, const QVariant &value, int role )
   259 {
   261 {
   260     Q_D( const HbComboBox );
   262     Q_D( const HbComboBox );
   265         }
   267         }
   266     }
   268     }
   267 }
   269 }
   268 
   270 
   269 /*!
   271 /*!
   270     @proto
   272     @beta
   271     This case is valid only for Editable comboBox
   273 
   272     Returns the validator that is used to constraint text input to the
   274     This API is valid only for editable combobox.
   273     combobox and returns NULL if it is invalid.
   275     Either returns the validator that is used to constraint text input in
       
   276     combobox or returns NULL if it is invalid.
   274 
   277 
   275     \sa editable
   278     \sa editable
   276 */
   279 */
   277 const HbValidator *HbComboBox::validator() const
   280 const HbValidator *HbComboBox::validator( ) const
   278 {
   281 {
   279     Q_D( const HbComboBox );
   282     Q_D( const HbComboBox );
   280     if( d->mEditable) {
   283     if( d->mEditable) {
   281         return d->mLineEdit->validator( );
   284         return d->mLineEdit->validator( );
   282     }
   285     }
   283     return 0;
   286     return 0;
   284 }
   287 }
   285 
   288 
   286 /*!
   289 /*!
   287     @proto
   290     @beta
   288     This case is only valid for the Editable comboBox.
   291 
   289     Sets the \a validator to use instead of the current validator.
   292     This API is only valid for the editable combobox.
       
   293     Sets the \a validator to be used in editable combobox.
   290 */
   294 */
   291 void HbComboBox::setValidator( HbValidator *validator )
   295 void HbComboBox::setValidator( HbValidator *validator )
   292 {
   296 {
   293     Q_D( HbComboBox );
   297     Q_D( HbComboBox );
   294     if( d->mEditable ) {
   298     if( d->mEditable ) {
   295         disconnect( d->mLineEdit, SIGNAL( textChanged ( QString ) ), 
   299         disconnect( d->mLineEdit, SIGNAL( textChanged ( QString ) ),
   296             this, SLOT( _q_textChanged( QString ) ) );
   300             this, SLOT( _q_textChanged( QString ) ) );
   297         d->mLineEdit->setValidator( validator );
   301         d->mLineEdit->setValidator( validator );
   298         connect( d->mLineEdit, SIGNAL( textChanged ( QString ) ), 
   302         connect( d->mLineEdit, SIGNAL( textChanged ( QString ) ),
   299             this, SLOT( _q_textChanged( QString ) ) );
   303             this, SLOT( _q_textChanged( QString ) ) );
   300     }
   304     }
   301 }
   305 }
   302 
   306 
   303 /*!
   307 /*!
   304     This property holds the number of items in the combobox.
   308     @beta
   305     By default, for an empty combo box, this property has a value of 0.
   309 
       
   310     This property holds the number of items in combobox.
       
   311     For an empty combo box, this property is equal to 0.
   306  */
   312  */
   307 int HbComboBox::count( ) const
   313 int HbComboBox::count( ) const
   308 {
   314 {
   309     Q_D( const HbComboBox );
   315     Q_D( const HbComboBox );
   310     if( d->mModel ) {
   316     if( d->mModel ) {
   313     return 0;
   319     return 0;
   314 }
   320 }
   315 
   321 
   316 /*!
   322 /*!
   317     @beta
   323     @beta
       
   324 
   318     Sets the model to \a model 
   325     Sets the model to \a model 
   319     comboBox Owns the model set by the Application.
   326     Ownership of \a model is taken by HbComboBox.
   320     It replaces the old model if exists.
   327     It replaces the old model if exists.
   321     please do not pass 0(NULL) as \a model instead call clear() to clear the contens of the model.
   328     Do not pass 0(NULL) as \a model to clear contents of model instead call clear( ).
       
   329     \sa clear
   322  */
   330  */
   323 void HbComboBox::setModel( QAbstractItemModel * model )
   331 void HbComboBox::setModel( QAbstractItemModel * model )
   324 {
   332 {
   325     Q_D( HbComboBox );
   333     Q_D( HbComboBox );
   326     if ( d->mModel != model ) {
   334     if ( d->mModel != model ) {
   332     }
   340     }
   333 }
   341 }
   334 
   342 
   335 /*!
   343 /*!
   336     @beta
   344     @beta
   337     Returns model that view is currently presenting.
   345 
       
   346     Returns current model.
   338  */
   347  */
   339 QAbstractItemModel* HbComboBox::model( ) const
   348 QAbstractItemModel* HbComboBox::model( ) const
   340 {
   349 {
   341     Q_D( const HbComboBox );
   350     Q_D( const HbComboBox );
   342     return d->mModel;
   351     return d->mModel;
   343 }
   352 }
   344 
   353 
   345 /*!
   354 /*!
   346     @beta
   355     @beta
       
   356 
   347     Sets current index to \a index.
   357     Sets current index to \a index.
   348     By default no item is selected.
   358     By default no item is selected.
   349  */
   359  */
   350 void HbComboBox::setCurrentIndex( int index )
   360 void HbComboBox::setCurrentIndex( int index )
   351 {
   361 {
   358     }
   368     }
   359 }
   369 }
   360 
   370 
   361 /*!
   371 /*!
   362     @beta
   372     @beta
   363     Returns index of current item and returns -1 for invalid current index.
   373 
       
   374     Either returns index of current item if valid or else returns -1 for invalid current index.
   364  */
   375  */
   365 int HbComboBox::currentIndex( ) const
   376 int HbComboBox::currentIndex( ) const
   366 {
   377 {
   367     Q_D( const HbComboBox );
   378     Q_D( const HbComboBox );
   368     return d->mCurrentIndex.row( );
   379     return d->mCurrentIndex.row( );
   369 }
   380 }
   370 
   381 
   371 /*!
   382 /*!
   372     @beta
   383     @beta
       
   384 
   373     \fn int HbComboBox::findText(const QString &text, Qt::MatchFlags 
   385     \fn int HbComboBox::findText(const QString &text, Qt::MatchFlags 
   374                                       flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const
   386                                       flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const
   375 
   387 
   376     Returns the index of the item containing the given \a text; otherwise
   388     Returns the index of the item containing the given \a text; otherwise
   377     returns -1.
   389     returns -1.
   378 
   390 
   379     The \a flags specify how the items in the combobox are searched.
   391     The \a flags specify how the items in the combobox are searched.
   380 */
   392 */
   381 
   393 
   382 /*!
   394 /*!
       
   395     @beta
       
   396 
   383     Returns the index of the item containing the given \a data for the
   397     Returns the index of the item containing the given \a data for the
   384     given \a role; otherwise returns -1.
   398     given \a role if valid, otherwise returns -1.
   385 
   399 
   386     The \a flags specify how the items in the combobox are searched.
   400     The \a flags specify how the items in the combobox are searched.
   387 */
   401 */
   388 int HbComboBox::findData( const QVariant &data, int role, Qt::MatchFlags flags ) const
   402 int HbComboBox::findData( const QVariant &data, int role, Qt::MatchFlags flags ) const
   389 {
   403 {
   390     Q_D( const HbComboBox );
   404     Q_D( const HbComboBox );
   391     if(d->mModel) {
   405     if( d->mModel ) {
   392         QModelIndexList result;
   406         QModelIndexList result;
   393         QModelIndex start = d->mModel->index( 0, 0 );
   407         QModelIndex start = d->mModel->index( 0, 0 );
   394         result = d->mModel->match( start, role, data, 1, flags );
   408         result = d->mModel->match( start, role, data, 1, flags );
   395         if ( result.isEmpty( ) )
   409         if ( result.isEmpty( ) ) {
   396             return -1;
   410             return -1;
       
   411         }
   397         return result.first( ).row( );
   412         return result.first( ).row( );
   398     }
   413     }
   399     return -1;
   414     return -1;
   400 }
   415 }
   401 
   416 
   402 /*!
   417 /*!
   403     @beta
   418     @beta
   404     This is specific to the Editable comboBox only.
   419 
   405     Sets the text in the combobox's text edit 
   420     This API is valid for editable combobox.
       
   421     Sets the \a text in editable combobox's line edit.
   406  */
   422  */
   407 void HbComboBox::setEditText( const QString &text )
   423 void HbComboBox::setEditText( const QString &text )
   408 {
   424 {
   409     Q_D( HbComboBox );
   425     Q_D( HbComboBox );
   410     if( d->mEditable ) {
   426     if( d->mEditable ) {
   411         disconnect( d->mLineEdit, SIGNAL( textChanged ( QString ) ), 
   427         disconnect( d->mLineEdit, SIGNAL( textChanged ( QString ) ),
   412             this, SLOT( _q_textChanged( QString ) ) );
   428             this, SLOT( _q_textChanged( QString ) ) );
   413         d->mLineEdit->setText( text );
   429         d->mLineEdit->setText( text );
   414         connect( d->mLineEdit, SIGNAL( textChanged ( QString ) ), 
   430         connect( d->mLineEdit, SIGNAL( textChanged ( QString ) ),
   415             this, SLOT( _q_textChanged( QString ) ) );
   431             this, SLOT( _q_textChanged( QString ) ) );
   416     }
   432     }
   417 }
   433 }
   418 
   434 
   419 /*!
   435 /*!
   420     @beta
   436     @beta
       
   437 
   421     \property HbComboBox::currentText
   438     \property HbComboBox::currentText
   422     \brief the text of the current item
   439 
   423      combo box with model count \0 returns an empty string.
   440     In case of non-editable combobox it returns the text at current index.
       
   441     In case of editable combobox it returns the text in line edit.
   424 */
   442 */
   425 QString HbComboBox::currentText( ) const
   443 QString HbComboBox::currentText( ) const
   426 {
   444 {
   427     Q_D( const HbComboBox );
   445     Q_D( const HbComboBox );
   428     if( d->mEditable ) {
   446     if( d->mEditable ) {
   434     }
   452     }
   435 }
   453 }
   436 
   454 
   437 /*!
   455 /*!
   438     @beta
   456     @beta
   439     Removes the item at the given index from the combobox.
   457 
   440     This will update the current index if the index is removed. 
   458     Removes the item at the given \a index from HbComboBox.
       
   459     If \a index passed is current index then current index will be updated accordingly.
   441  */
   460  */
   442 void HbComboBox::removeItem( int index )
   461 void HbComboBox::removeItem( int index )
   443 {
   462 {
   444     Q_D( HbComboBox );
   463     Q_D( HbComboBox );
   445     if( d->mModel ) {
   464     if( d->mModel ) {
   446         int rowCount = d->mModel->rowCount( );
   465         int rowCount = d->mModel->rowCount( );
   447         if( index >=0 && index < rowCount ) {
   466         if( index >=0 && index < rowCount ) {
   448             bool currentText = false;
   467             bool currentText = false;
   449             if ( d->mModel->index(index, 0) == d->mCurrentIndex ) {
   468             if ( d->mModel->index( index, 0 ) == d->mCurrentIndex ) {
   450                 currentText = true;
   469                 currentText = true;
   451                 d->mModel->removeRow( index );
   470                 d->mModel->removeRow( index );
   452             } else if( d->mCurrentIndex.row() > index ) {
   471             } else if( d->mCurrentIndex.row( ) > index ) {
   453                  int row = d->mCurrentIndex.row();
   472                  int row = d->mCurrentIndex.row( );
   454                  d->mModel->removeRow( index );
   473                  d->mModel->removeRow( index );
   455                  d->mCurrentIndex = d->mModel->index( --row, 0 );
   474                  d->mCurrentIndex = d->mModel->index( --row, 0 );
   456                  d->currentIndexChanged( d->mCurrentIndex );
   475                  d->currentIndexChanged( d->mCurrentIndex );
   457             } else {
   476             } else {
   458                 d->mModel->removeRow( index );
   477                 d->mModel->removeRow( index );
   459             }
   478             }
   460             if( d->mModel->rowCount( ) == 0 ) {
   479             if( d->mModel->rowCount( ) == 0 ) {
   461                 if( d->mEditable ) {
   480                 if( d->mEditable ) {
   462                     clearEditText();
   481                     clearEditText( );
   463                 } else {
   482                 } else {
   464                     if( d->mLineEdit ) {
   483                     if( d->mLineEdit ) {
   465                         d->mLineEdit->setText( QString() );
   484                         d->mLineEdit->setText( QString( ) );
   466                     } else {
   485                     } else {
   467                         d->mText.clear();
   486                         d->mText.clear( );
   468                         HbStyleOptionComboBox comboBoxOption;
   487                         HbStyleOptionComboBox comboBoxOption;
   469                         initStyleOption(&comboBoxOption);
   488                         initStyleOption( &comboBoxOption );
   470                         style()->updatePrimitive( d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption);
   489                         style( )->updatePrimitive(
       
   490                             d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption );
   471                     }
   491                     }
   472                 }
   492                 }
       
   493                 d->mCurrentIndex = QModelIndex();
   473                 return;
   494                 return;
   474             }
   495             }
   475             if( currentText ) {
   496             if( currentText ) {
   476                 d->mCurrentIndex = d->mModel->index( 0, 0 );
   497                 d->mCurrentIndex = d->mModel->index( 0, 0 );
   477                 if( d->mEditable ) {
   498                 if( d->mEditable ) {
   478                     disconnect(d->mLineEdit, SIGNAL( textChanged ( QString ) ),
   499                     disconnect(d->mLineEdit, SIGNAL( textChanged ( QString ) ),
   479                                  this, SLOT( _q_textChanged( QString ) ) );
   500                         this, SLOT( _q_textChanged( QString ) ) );
   480                     d->mLineEdit->setText( d->mModel->data( d->mCurrentIndex ).toString( ) );
   501                     d->mLineEdit->setText( d->mModel->data( d->mCurrentIndex ).toString( ) );
   481                     connect(d->mLineEdit, SIGNAL( textChanged ( QString ) ), 
   502                     connect(d->mLineEdit, SIGNAL( textChanged ( QString ) ), 
   482                                  this, SLOT( _q_textChanged( QString ) ) );
   503                         this, SLOT( _q_textChanged( QString ) ) );
   483                 } else {
   504                 } else {
   484                     if( d->mLineEdit ) {
   505                     if( d->mLineEdit ) {
   485                         d->mLineEdit->setText( QString() );
   506                         d->mLineEdit->setText( QString( ) );
   486                     } else {
   507                     } else {
   487                         d->mText = d->mModel->data( d->mCurrentIndex ).toString( );
   508                         d->mText = d->mModel->data( d->mCurrentIndex ).toString( );
   488                         HbStyleOptionComboBox comboBoxOption;
   509                         HbStyleOptionComboBox comboBoxOption;
   489                         initStyleOption(&comboBoxOption);
   510                         initStyleOption( &comboBoxOption );
   490                         style()->updatePrimitive( d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption);
   511                         style( )->updatePrimitive(
       
   512                             d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption);
   491                     }
   513                     }
   492                 }
   514                 }
   493                 d->currentIndexChanged( d->mCurrentIndex );
   515                 d->currentIndexChanged( d->mCurrentIndex );
   494             }
   516             }
   495         }
   517         }
   501  */
   523  */
   502 void HbComboBox::resizeEvent( QGraphicsSceneResizeEvent *event )
   524 void HbComboBox::resizeEvent( QGraphicsSceneResizeEvent *event )
   503 {
   525 {
   504     Q_UNUSED( event )
   526     Q_UNUSED( event )
   505     Q_D( HbComboBox );
   527     Q_D( HbComboBox );
   506     if ( d->mDropDown && d->mDropDown->isVisible() ){
   528     if ( d->mDropDown && d->mDropDown->isVisible( ) ) {
   507         d->positionDropDown( );
   529         d->positionDropDown( );
   508     }
   530     }
   509 }
   531 }
   510 
   532 
   511 /*!
   533 /*!
   553  */
   575  */
   554 QGraphicsItem* HbComboBox::primitive( HbStyle::Primitive primitive ) const
   576 QGraphicsItem* HbComboBox::primitive( HbStyle::Primitive primitive ) const
   555 {
   577 {
   556     Q_D( const HbComboBox );
   578     Q_D( const HbComboBox );
   557 
   579 
   558     switch( primitive ){
   580     switch( primitive ) {
   559         case HbStyle::P_ComboBox_text:
   581         case HbStyle::P_ComboBox_text:
   560             return d->mTextItem;
   582             return d->mTextItem;
   561         case HbStyle::P_ComboBox_background:
   583         case HbStyle::P_ComboBox_background:
   562             return d->mBackgroundItem;
   584             return d->mBackgroundItem;
   563         case HbStyle::P_ComboBox_button:
   585         case HbStyle::P_ComboBox_button:
   567         default:
   589         default:
   568             return 0;
   590             return 0;
   569     }
   591     }
   570 }
   592 }
   571 
   593 
       
   594 /*!
       
   595     \reimp
       
   596  */
   572 void HbComboBox::initStyleOption( HbStyleOptionComboBox *option )const
   597 void HbComboBox::initStyleOption( HbStyleOptionComboBox *option )const
   573 {
   598 {
   574     Q_D( const HbComboBox );    
   599     Q_D( const HbComboBox );
   575     option->text = d->mText;
   600     option->text = d->mText;
   576     HbWidget::initStyleOption( option );  
   601     HbWidget::initStyleOption( option );
   577 }
   602 }
   578 
   603 
   579 /*!
   604 /*!
   580     \reimp
   605     \reimp
   581  */
   606  */
   582 void HbComboBox::updatePrimitives( )
   607 void HbComboBox::updatePrimitives( )
   583 {
   608 {
   584     Q_D( HbComboBox );    
   609     Q_D( HbComboBox );
   585     HbStyleOption styleOption;
   610     HbStyleOption styleOption;
   586     HbWidget::initStyleOption( &styleOption );
   611     HbWidget::initStyleOption( &styleOption );
   587     if ( d->mIsDown ) {
   612     if ( d->mIsDown ) {
   588         styleOption.state |= QStyle::State_Sunken;
   613         styleOption.state |= QStyle::State_Sunken;
   589     }
   614     }
   595     }
   620     }
   596 }
   621 }
   597 
   622 
   598 /*!
   623 /*!
   599     @beta
   624     @beta
   600     Clears the combobox, removes all items from model. 
   625 
       
   626     Removes all items from model. 
   601  */
   627  */
   602 void HbComboBox::clear( )
   628 void HbComboBox::clear( )
   603 {
   629 {
   604     Q_D( HbComboBox );
   630     Q_D( HbComboBox );
   605     if( d->mModel ) {
   631     if( d->mModel ) {
   606         d->mModel->removeRows(0, d->mModel->rowCount());
   632         d->mModel->removeRows( 0, d->mModel->rowCount( ) );
   607         d->mCurrentIndex = QModelIndex( );
   633         d->mCurrentIndex = QModelIndex( );
   608         if( d->mEditable ) {
   634         if( d->mEditable ) {
   609             clearEditText();
   635             clearEditText( );
   610         } else {
   636         } else {
   611             if( d->mLineEdit ) {
   637             if( d->mLineEdit ) {
   612                 d->mLineEdit->setText( QString() );
   638                 d->mLineEdit->setText( QString( ) );
   613             } else {
   639             } else {
   614                 d->mText.clear();
   640                 d->mText.clear( );
   615                 HbStyleOptionComboBox comboBoxOption;
   641                 HbStyleOptionComboBox comboBoxOption;
   616                 initStyleOption(&comboBoxOption);
   642                 initStyleOption( &comboBoxOption );
   617                 style()->updatePrimitive( d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption);
   643                 style( )->updatePrimitive( d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption );
   618             }
   644             }
   619         }
   645         }
   620     }
   646     }
   621 }
   647 }
   622 
   648 
   623 /*!
   649 /*!
   624     @beta
   650     @beta
   625     Clears the contents of the line edit used for editing in the combobox.
   651 
       
   652     This API is valid only for editable combobox.
       
   653     Clears the contents of line edit in editable combobox.
   626  */
   654  */
   627 void HbComboBox::clearEditText( )
   655 void HbComboBox::clearEditText( )
   628 {
   656 {
   629     Q_D( HbComboBox );
   657     Q_D( HbComboBox );
   630     if( d->mEditable ) {
   658     if( d->mEditable ) {
   636     }
   664     }
   637 }
   665 }
   638 
   666 
   639 /*!
   667 /*!
   640     @beta
   668     @beta
       
   669 
   641     \property HbComboBox::editable
   670     \property HbComboBox::editable
   642     \brief Set editable the property of the combobox.
   671     
   643     True, Editable, user can type in the combobox to search for items from 
   672     If \a editable is true then combobox will be editable else it will be
   644     the list of items. Shows the prediction. If user types a text which does not match
   673     non-editable.
   645     to any items in the model then slection is not changed.
   674 
   646     False, Non editable user canot enter text using keyboard.
   675     \sa isEditable
   647  */
   676  */
   648 void HbComboBox::setEditable( bool editable )
   677 void HbComboBox::setEditable( bool editable )
   649 {
   678 {
   650     Q_D( HbComboBox ); 
   679     Q_D( HbComboBox ); 
   651     d->setEditable( editable );
   680     d->setEditable( editable );
   652     setProperty("state", "normal");
   681     setProperty( "state", "normal" );
   653 }
   682 }
   654 
   683 
   655 /*!
   684 /*!
   656     @beta
   685     @beta
   657     Returns whether or not the combobox is editable
   686 
   658     True if editable, else false
   687     Returns combobox is editable or not. If editable then returns true else returns
       
   688     false.
       
   689 
       
   690     \sa setEditable
   659  */
   691  */
   660 bool HbComboBox::isEditable( ) const
   692 bool HbComboBox::isEditable( ) const
   661 {
   693 {
   662     Q_D( const HbComboBox );
   694     Q_D( const HbComboBox );
   663     return d->mEditable;
   695     return d->mEditable;
   664 }
   696 }
   665 
   697 
   666 /*!
   698 /*!
   667     @beta
   699     @beta
   668     Adds an item to the combobox with the given text,
   700 
   669     and containing the specified userData (stored in the Qt::UserRole).
   701     Adds an item in combobox with the given \a text, containing the specified \a userData 
       
   702     (stored in the Qt::UserRole). The item is appended to the list of existing items.
       
   703 
       
   704     \sa insertItem
       
   705  */
       
   706 void HbComboBox::addItem( const QString &text, const QVariant &userData )
       
   707 {
       
   708     insertItem( count( ), text, userData );
       
   709 }
       
   710 
       
   711 /*!
       
   712     @beta
       
   713 
       
   714     Adds an item in combobox with the given \a icon and \a text,
       
   715     and containing the specified \a userData (stored in the Qt::UserRole). 
   670     The item is appended to the list of existing items.
   716     The item is appended to the list of existing items.
   671  */
   717 
   672 void HbComboBox::addItem( const QString &text, const QVariant &userData)
   718     \sa insertItem
   673 {
       
   674     insertItem( count( ), text, userData );
       
   675 }
       
   676 
       
   677 /*!
       
   678     @beta
       
   679     Adds an item to the combobox with the given icon and text,
       
   680     and containing the specified userData (stored in the Qt::UserRole). 
       
   681     The item is appended to the list of existing items.
       
   682  */
   719  */
   683 void HbComboBox::addItem( const HbIcon &icon, const QString &text, const QVariant &userData )
   720 void HbComboBox::addItem( const HbIcon &icon, const QString &text, const QVariant &userData )
   684 {
   721 {
   685     insertItem( count( ), icon, text, userData );
   722     insertItem( count( ), icon, text, userData );
   686 }
   723 }
   687 
   724 
   688 /*!
   725 /*!
   689     @beta
   726     @beta
   690     Adds each of the strings in the given texts to the combobox.
   727 
       
   728     Adds each of the strings in the given \a texts to combobox.
   691     Each item is appended to the list of existing items in turn.
   729     Each item is appended to the list of existing items in turn.
       
   730 
       
   731     \sa insertItem
   692  */
   732  */
   693 void HbComboBox::addItems( const QStringList &texts )
   733 void HbComboBox::addItems( const QStringList &texts )
   694 {
   734 {
   695     insertItems( count(), texts );
   735     insertItems( count( ), texts );
   696 }
   736 }
   697 
   737 
   698 
   738 
   699 /*!
   739 /*!
   700     @beta
   740     @beta
   701     Inserts the text into the combobox at the given index.
   741 
       
   742     Inserts the \a text in combobox at the given \a index.
   702     If the index is equal to or higher than the total number of items, 
   743     If the index is equal to or higher than the total number of items, 
   703     the new item is appended to the list of existing items.
   744     the new item is appended to the list of existing items.
   704     If the index is zero or negative, the new item is prepended to the list of existing items.
   745     If the index is zero or negative, the new item is prepended to the list of existing items.
       
   746 
       
   747     \sa addItems addItem
   705  */
   748  */
   706 void HbComboBox::insertItem( int index, const QString &text, const QVariant &userData )
   749 void HbComboBox::insertItem( int index, const QString &text, const QVariant &userData )
   707 {
   750 {
   708     Q_D( HbComboBox );
   751     Q_D( HbComboBox );
   709     if( text.isNull( ) ){
   752     if( text.isNull( ) ) {
   710         return;
   753         return;
   711     }
   754     }
   712     if( !d->mModel ) {
   755     if( !d->mModel ) {
   713         QStandardItemModel* model = new QStandardItemModel(this );
   756         QStandardItemModel* model = new QStandardItemModel( this );
   714         setModel( model );
   757         setModel( model );
   715     }
   758     }
   716     if (  !d->mModel->rowCount( ) ) {
   759     if ( !d->mModel->rowCount( ) ) {
   717         d->mModel->insertRow( 0 );
   760         d->mModel->insertRow( 0 );
   718         d->mModel->insertColumn( 0 );
   761         d->mModel->insertColumn( 0 );
   719         if( d->mModel->index( 0, 0 ).isValid( ) ) {
   762         if( d->mModel->index( 0, 0 ).isValid( ) ) {
   720             d->mModel->setData( d->mModel->index( 0, 0 ), text, Qt::DisplayRole );
   763             d->mModel->setData( d->mModel->index( 0, 0 ), text, Qt::DisplayRole );
   721             if( userData.isValid( ) ) {
   764             if( userData.isValid( ) ) {
   731             if( userData.isValid( ) ) {
   774             if( userData.isValid( ) ) {
   732                 d->mModel->setData( d->mModel->index( rowCount, 0 ), userData, Qt::UserRole );
   775                 d->mModel->setData( d->mModel->index( rowCount, 0 ), userData, Qt::UserRole );
   733             }
   776             }
   734         } else if(index <= 0) {
   777         } else if(index <= 0) {
   735             d->mModel->insertRow( 0 );
   778             d->mModel->insertRow( 0 );
   736             d->mModel->setData( d->mModel->index(0,0), text, Qt::DisplayRole );
   779             d->mModel->setData( d->mModel->index( 0, 0 ), text, Qt::DisplayRole );
   737             if( userData.isValid( ) ) {
   780             if( userData.isValid( ) ) {
   738                 d->mModel->setData( d->mModel->index( 0, 0 ), userData, Qt::UserRole );
   781                 d->mModel->setData( d->mModel->index( 0, 0 ), userData, Qt::UserRole );
   739             }
   782             }
   740             if( d->mCurrentIndex.row() >= 0 ) {
   783             if( d->mCurrentIndex.row( ) >= 0 ) {
   741                 d->mCurrentIndex = d->mModel->index(d->mCurrentIndex.row()+1, 0);
   784                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0);
   742                 d->currentIndexChanged(d->mCurrentIndex);
   785                 d->currentIndexChanged( d->mCurrentIndex );
   743             }
   786             }
   744         } else {
   787         } else {
   745            d->mModel->insertRow( index );
   788            d->mModel->insertRow( index );
   746            d->mModel->setData( d->mModel->index( index, 0 ), text, Qt::DisplayRole );
   789            d->mModel->setData( d->mModel->index( index, 0 ), text, Qt::DisplayRole );
   747            if( userData.isValid( ) ) {
   790            if( userData.isValid( ) ) {
   748                 d->mModel->setData( d->mModel->index( index, 0 ), userData, Qt::UserRole );                
   791                 d->mModel->setData( d->mModel->index( index, 0 ), userData, Qt::UserRole );
   749             }
   792             }
   750            if( d->mCurrentIndex.row() <= index ) {
   793            if( d->mCurrentIndex.row( ) >= index ) {
   751                 d->mCurrentIndex = d->mModel->index(d->mCurrentIndex.row()+1, 0);
   794                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0);
   752                 d->currentIndexChanged(d->mCurrentIndex);
   795                 d->currentIndexChanged( d->mCurrentIndex );
   753             }
   796             }
   754         }
   797         }
   755     }
   798     }
   756 }
   799 }
   757 
   800 
   758 /*!
   801 /*!
   759     @beta
   802     @beta
   760     Inserts the text and icon into the combobox at the given index.
   803 
       
   804     Inserts the \a text and \a icon into the combobox at the given \a index.
   761     If the index is equal to or higher than the total number of items, 
   805     If the index is equal to or higher than the total number of items, 
   762     the new item is appended to the list of existing items.
   806     the new item is appended to the list of existing items.
   763     If the index is zero or negative, the new item is prepended to the list of existing items.
   807     If the index is zero or negative, the new item is prepended to the list of existing items.
   764  */
   808 
   765 void HbComboBox::insertItem( int index, const HbIcon &icon, const QString &text, const QVariant &userData)
   809     \sa insertItem
   766 {
   810  */
   767     Q_D( HbComboBox );
   811 void HbComboBox::insertItem( int index, const HbIcon &icon,
   768     if( text.isEmpty( ) ){
   812     const QString &text, const QVariant &userData )
       
   813 {
       
   814     Q_D( HbComboBox );
       
   815     if( text.isEmpty( ) ) {
   769         return;
   816         return;
   770     }
   817     }
   771 
   818 
   772     if( !d->mModel ) {
   819     if( !d->mModel ) {
   773         QStandardItemModel* model = new QStandardItemModel( this );
   820         QStandardItemModel* model = new QStandardItemModel( this );
   774         setModel( model );
   821         setModel( model );
   775     }
   822     }
   776     if (  !d->mModel->rowCount( ) ) {
   823     if ( !d->mModel->rowCount( ) ) {
   777         d->mModel->insertRow( 0 );
   824         d->mModel->insertRow( 0 );
   778         d->mModel->insertColumn( 0 );
   825         d->mModel->insertColumn( 0 );
   779         if( d->mModel->index( 0, 0 ).isValid( ) ) {
   826         if( d->mModel->index( 0, 0 ).isValid( ) ) {
   780             d->mModel->setData( d->mModel->index(0,0), text, Qt::DisplayRole );
   827             d->mModel->setData( d->mModel->index( 0, 0 ), text, Qt::DisplayRole );
   781             setCurrentIndex( 0 );
   828             setCurrentIndex( 0 );
   782         }
   829         }
   783         if(!icon.isNull() && d->mModel->index( 0, 0 ).isValid( ) ) {
   830         if( !icon.isNull( ) && d->mModel->index( 0, 0 ).isValid( ) ) {
   784             d->mModel->setData(d->mModel->index( 0, 0 ), icon.qicon( ), Qt::DecorationRole);
   831             d->mModel->setData( d->mModel->index( 0, 0 ), icon.qicon( ), Qt::DecorationRole );
   785         }
   832         }
   786         if( userData.isValid( ) && d->mModel->index( 0, 0 ).isValid( ) ) {
   833         if( userData.isValid( ) && d->mModel->index( 0, 0 ).isValid( ) ) {
   787             d->mModel->setData( d->mModel->index( 0, 0 ), userData, Qt::UserRole );                
   834             d->mModel->setData( d->mModel->index( 0, 0 ), userData, Qt::UserRole );
   788         }
   835         }
   789     } else {
   836     } else {
   790         int rowCount = d->mModel->rowCount( );
   837         int rowCount = d->mModel->rowCount( );
   791         if( index >= rowCount ) {
   838         if( index >= rowCount ) {
   792             d->mModel->insertRow( rowCount );
   839             d->mModel->insertRow( rowCount );
   793             d->mModel->setData( d->mModel->index( rowCount, 0 ), text, Qt::DisplayRole );
   840             d->mModel->setData( d->mModel->index( rowCount, 0 ), text, Qt::DisplayRole );
   794             if(!icon.isNull()) {
   841             if( !icon.isNull( ) ) {
   795                 d->mModel->setData( d->mModel->index( rowCount, 0 ), icon, Qt::DecorationRole );
   842                 d->mModel->setData( d->mModel->index( rowCount, 0 ), icon, Qt::DecorationRole );
   796             }
   843             }
   797             if( userData.isValid( ) ) {
   844             if( userData.isValid( ) ) {
   798                 d->mModel->setData( d->mModel->index( rowCount, 0 ), userData, Qt::UserRole );
   845                 d->mModel->setData( d->mModel->index( rowCount, 0 ), userData, Qt::UserRole );
   799             }
   846             }
   800             if( d->mCurrentIndex.row() == index ) {
   847             if( d->mCurrentIndex.row( ) == index ) {
   801                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0 );
   848                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0 );
   802                 d->currentIndexChanged( d->mCurrentIndex );
   849                 d->currentIndexChanged( d->mCurrentIndex );
   803             }
   850             }
   804         } else if(index <= 0) {
   851         } else if( index <= 0 ) {
   805             d->mModel->insertRow( 0 );
   852             d->mModel->insertRow( 0 );
   806             d->mModel->setData( d->mModel->index( 0, 0 ), text, Qt::DisplayRole );
   853             d->mModel->setData( d->mModel->index( 0, 0 ), text, Qt::DisplayRole );
   807             if(!icon.isNull()) {
   854             if( !icon.isNull( ) ) {
   808                 d->mModel->setData(d->mModel->index( 0, 0 ), icon, Qt::DecorationRole);
   855                 d->mModel->setData( d->mModel->index( 0, 0 ), icon, Qt::DecorationRole );
   809             }
   856             }
   810             if( userData.isValid( ) ) {
   857             if( userData.isValid( ) ) {
   811                 d->mModel->setData( d->mModel->index( 0, 0 ), userData, Qt::UserRole );
   858                 d->mModel->setData( d->mModel->index( 0, 0 ), userData, Qt::UserRole );
   812             }
   859             }
   813             if( d->mCurrentIndex.row() >= 0 ) {
   860             if( d->mCurrentIndex.row( ) >= 0 ) {
   814                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0);
   861                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0 );
   815                 d->currentIndexChanged( d->mCurrentIndex );
   862                 d->currentIndexChanged( d->mCurrentIndex );
   816             }
   863             }
   817         } else {
   864         } else {
   818             d->mModel->insertRow( index );
   865             d->mModel->insertRow( index );
   819             d->mModel->setData( d->mModel->index( index, 0 ), text, Qt::DisplayRole );
   866             d->mModel->setData( d->mModel->index( index, 0 ), text, Qt::DisplayRole );
   820             if(!icon.isNull( ) ) {
   867             if( !icon.isNull( ) ) {
   821                 d->mModel->setData( d->mModel->index( index, 0 ), icon, Qt::DecorationRole );
   868                 d->mModel->setData( d->mModel->index( index, 0 ), icon, Qt::DecorationRole );
   822             }
   869             }
   823             if( userData.isValid( ) ) {
   870             if( userData.isValid( ) ) {
   824                 d->mModel->setData( d->mModel->index( index, 0 ), userData, Qt::UserRole );
   871                 d->mModel->setData( d->mModel->index( index, 0 ), userData, Qt::UserRole );
   825             }
   872             }
   826             if( d->mCurrentIndex.row() <= index ) {
   873             if( d->mCurrentIndex.row( ) <= index ) {
   827                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0);
   874                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + 1, 0 );
   828                 d->currentIndexChanged( d->mCurrentIndex );
   875                 d->currentIndexChanged( d->mCurrentIndex );
   829             }
   876             }
   830         }
   877         }
   831     }
   878     }
   832 }
   879 }
   833 
   880 
   834 /*!
   881 /*!
   835     @beta
   882     @beta
   836     Inserts the strings from the list into the combobox as separate items, starting at the index.
   883 
       
   884     Inserts the strings in \a texts into combobox as separate items, starting at the given \a index.
   837     If the index is equal to or higher than the total number of items, 
   885     If the index is equal to or higher than the total number of items, 
   838     the new item is appended to the list of existing items.
   886     the new item is appended to the list of existing items.
   839     If the index is zero or negative, the new item is prepended to the list of existing items.
   887     If the index is zero or negative, the new item is prepended to the list of existing items.
   840  */
   888  */
   841 void HbComboBox::insertItems( int index, const QStringList &texts )
   889 void HbComboBox::insertItems( int index, const QStringList &texts )
   845         QStandardItemModel* model = new QStandardItemModel( this );
   893         QStandardItemModel* model = new QStandardItemModel( this );
   846         setModel( model );
   894         setModel( model );
   847     }
   895     }
   848     if ( !d->mModel->rowCount( ) ) {
   896     if ( !d->mModel->rowCount( ) ) {
   849         int textCount = texts.count( );
   897         int textCount = texts.count( );
   850         for( int i = 0; i < textCount; i++)
   898         for( int i = 0; i < textCount; i++) {
   851         {
       
   852             d->mModel->insertRow( i );
   899             d->mModel->insertRow( i );
   853             if( i == 0)
   900             if( i == 0) {
   854                 d->mModel->insertColumn( 0 );
   901                 d->mModel->insertColumn( 0 );
       
   902             }
   855             if( d->mModel->index( i, 0 ).isValid( ) ) {
   903             if( d->mModel->index( i, 0 ).isValid( ) ) {
   856                 d->mModel->setData( d->mModel->index( i, 0 ),  texts.at( i ), Qt::DisplayRole );
   904                 d->mModel->setData( d->mModel->index( i, 0 ),  texts.at( i ), Qt::DisplayRole );
   857                 if( i == 0) {
   905                 if( i == 0) {
   858                     setCurrentIndex( 0 );
   906                     setCurrentIndex( 0 );
   859                 }
   907                 }
   860             }
   908             }
   861         }
   909         }
   862     }  else {
   910     } else {
   863         int rowCount = -1;
   911         int rowCount = -1;
   864         rowCount = d->mModel->rowCount( );
   912         rowCount = d->mModel->rowCount( );
   865         int textCount = texts.count( );
   913         int textCount = texts.count( );
   866         if ( index >= rowCount ) {
   914         if ( index >= rowCount ) {
   867             d->mModel->insertRows( rowCount, textCount );
   915             d->mModel->insertRows( rowCount, textCount );
   868             int temp = 0;
   916             int temp = 0;
   869             for ( int i = rowCount; i < ( rowCount + textCount ); i++ ) {
   917             for ( int i = rowCount; i < ( rowCount + textCount ); i++ ) {
   870                 d->mModel->setData ( d->mModel->index( i, 0 ), texts.at( temp++ ) );
   918                 d->mModel->setData ( d->mModel->index( i, 0 ), texts.at( temp++ ) );
   871             }
   919             }
   872             if( d->mCurrentIndex.row() == index ) {
   920             if( d->mCurrentIndex.row( ) == index ) {
   873                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + textCount, 0);
   921                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + textCount, 0 );
   874                 d->currentIndexChanged( d->mCurrentIndex );
   922                 d->currentIndexChanged( d->mCurrentIndex );
   875             }
   923             }
   876         } else if( index <= 0 ) {
   924         } else if( index <= 0 ) {
   877             d->mModel->insertRows( 0, textCount );
   925             d->mModel->insertRows( 0, textCount );
   878             for ( int i = 0; i < textCount; i++ ) {
   926             for ( int i = 0; i < textCount; i++ ) {
   879                 d->mModel->setData( d->mModel->index( i, 0 ), texts.at( i ) );
   927                 d->mModel->setData( d->mModel->index( i, 0 ), texts.at( i ) );
   880             }
   928             }
   881             if( d->mCurrentIndex.row() >= 0 ) {
   929             if( d->mCurrentIndex.row( ) >= 0 ) {
   882                 d->mCurrentIndex = d->mModel->index(d->mCurrentIndex.row() + textCount, 0);
   930                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + textCount, 0 );
   883                 d->currentIndexChanged( d->mCurrentIndex );
   931                 d->currentIndexChanged( d->mCurrentIndex );
   884             }
   932             }
   885         } else {
   933         } else {
   886             d->mModel->insertRows( index, texts.count( ) );
   934             d->mModel->insertRows( index, texts.count( ) );
   887             int temp = 0;
   935             int temp = 0;
   888             for ( int i = index; i < ( textCount + index ); i++ ) {
   936             for ( int i = index; i < ( textCount + index ); i++ ) {
   889                 d->mModel->setData( d->mModel->index( i, 0 ), texts.at( temp++ ) );
   937                 d->mModel->setData( d->mModel->index( i, 0 ), texts.at( temp++ ) );
   890             }
   938             }
   891             if( d->mCurrentIndex.row() <= index ) {
   939             if( d->mCurrentIndex.row( ) <= index ) {
   892                 d->mCurrentIndex = d->mModel->index(d->mCurrentIndex.row() + textCount, 0);
   940                 d->mCurrentIndex = d->mModel->index( d->mCurrentIndex.row( ) + textCount, 0 );
   893                 d->currentIndexChanged( d->mCurrentIndex );
   941                 d->currentIndexChanged( d->mCurrentIndex );
   894             }
   942             }
   895         }
   943         }
   896     }
   944     }
   897 }
   945 }
   898 
   946 
   899 /*!
   947 /*!
   900     @beta
   948     @beta
   901     Returns the text for the given index in the combobox.
   949 
       
   950     Returns text at given \a index in combobox.
       
   951 
       
   952     \sa setItemText
   902  */
   953  */
   903 QString HbComboBox::itemText( int index ) const
   954 QString HbComboBox::itemText( int index ) const
   904 {
   955 {
   905     Q_D( const HbComboBox );
   956     Q_D( const HbComboBox );
   906     if(d->mModel) {
   957     if( d->mModel ) {
   907         QModelIndex mi = d->mModel->index( index, 0 );
   958         QModelIndex mi = d->mModel->index( index, 0 );
   908         if( mi.isValid() ) {
   959         if( mi.isValid( ) ) {
   909             return d->itemText( mi );
   960             return d->itemText( mi );
   910         }
   961         }
   911      }
   962      }
   912      return QString( );
   963      return QString( );
   913 }
   964 }
   914 
   965 
   915 /*!
   966 /*!
   916     @beta
   967     @beta
   917     Sets the text for the item on the given index in the combobox.
   968 
       
   969     Sets the \a text for item at given \a index in combobox.
       
   970 
       
   971     \sa itemText
   918  */
   972  */
   919 void HbComboBox::setItemText( int index, const QString &text )
   973 void HbComboBox::setItemText( int index, const QString &text )
   920 {
   974 {
   921     Q_D( HbComboBox );
   975     Q_D( HbComboBox );
   922     if (d->mModel) {
   976     if ( d->mModel ) {
   923         QModelIndex item = d->mModel->index( index, 0 );
   977         QModelIndex item = d->mModel->index( index, 0 );
   924         if ( item.isValid( ) ) {
   978         if ( item.isValid( ) ) {
   925             if(d->mModel->setData( item, text, Qt::EditRole )) {
   979             if( d->mModel->setData( item, text, Qt::EditRole ) ) {
   926                 if(d->mCurrentIndex.row() == index) {
   980                 if( d->mCurrentIndex.row( ) == index ) {
   927                     if( d->mLineEdit ) {
   981                     if( d->mLineEdit ) {
   928                         d->mLineEdit->setText( text );
   982                         d->mLineEdit->setText( text );
   929                     } else {                    
   983                     } else {
   930                         d->mText = text ;
   984                         d->mText = text ;
   931                         HbStyleOptionComboBox comboBoxOption;
   985                         HbStyleOptionComboBox comboBoxOption;
   932                         initStyleOption(&comboBoxOption);
   986                         initStyleOption( &comboBoxOption );
   933                         style()->updatePrimitive( d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption);
   987                         style( )->updatePrimitive(
       
   988                             d->mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption );
   934                     }
   989                     }
   935                 }
   990                 }
   936             }
   991             }
   937             
       
   938         }
   992         }
   939     }
   993     }
   940 }
   994 }
   941 
   995 
   942 /*!
   996 /*!
   944 */
   998 */
   945 bool HbComboBox::eventFilter( QObject* obj, QEvent* event )
   999 bool HbComboBox::eventFilter( QObject* obj, QEvent* event )
   946 {
  1000 {
   947     Q_D( HbComboBox );
  1001     Q_D( HbComboBox );
   948     bool accepted = false;
  1002     bool accepted = false;
   949     if ( !isEnabled() ) {
  1003     if ( !isEnabled( ) ) {
   950         return false ;
  1004         return false ;
   951     }
  1005     }
   952     if(obj == static_cast<HbTouchArea*>(d->mButtonTouchAreaItem)) {
  1006     if( obj == static_cast<HbTouchArea*>( d->mButtonTouchAreaItem ) ) {
   953         if(event->type() == QEvent::Gesture ) {
  1007         if( event->type( ) == QEvent::Gesture ) {
   954             QGestureEvent *gestureEvent = static_cast<QGestureEvent *>( event );
  1008             QGestureEvent *gestureEvent = static_cast<QGestureEvent *>( event );
   955             if(gestureEvent->gesture(Qt::TapGesture)) {
  1009             if( gestureEvent->gesture( Qt::TapGesture ) ) {
   956                 HbTapGesture *tap = static_cast<HbTapGesture *>(gestureEvent->gesture(Qt::TapGesture));
  1010                 HbTapGesture *tap =
   957                 switch(tap->state()) {
  1011                     static_cast<HbTapGesture *>( gestureEvent->gesture( Qt::TapGesture ) );
       
  1012                 switch( tap->state( ) ) {
   958                 case Qt::GestureStarted:
  1013                 case Qt::GestureStarted:
   959                     {
  1014                     {
   960                         d->touchAreaPressEvent( );
  1015                         d->touchAreaPressEvent( );
   961                         accepted = true;
  1016                         accepted = true;
   962                         break;
  1017                         break;
   963                     }                
  1018                     }
   964                 case Qt::GestureCanceled:
  1019                 case Qt::GestureCanceled:
   965                     {
  1020                     {
   966                         d->mIsDown = false;
  1021                         d->mIsDown = false;
   967                         updatePrimitives();
  1022                         updatePrimitives( );
   968                         setProperty("state", "normal");
  1023                         setProperty( "state", "normal" );
   969                         accepted = true;
  1024                         accepted = true;
   970                         break;
  1025                         break;
   971                     }
  1026                     }
   972                 case Qt::GestureFinished:
  1027                 case Qt::GestureFinished:
   973                     {
  1028                     {
   988 /*!
  1043 /*!
   989     \reimp
  1044     \reimp
   990  */
  1045  */
   991 void HbComboBox::changeEvent( QEvent *event )
  1046 void HbComboBox::changeEvent( QEvent *event )
   992 {
  1047 {
   993     switch ( event->type( ) ){
  1048     switch ( event->type( ) ) {
   994         case QEvent::EnabledChange:
  1049         case QEvent::EnabledChange:
   995             updatePrimitives( );
  1050             updatePrimitives( );
   996             break;
  1051             break;
   997         default:
  1052         default:
   998             break;
  1053             break;