src/hbwidgets/itemviews/hbabstractitemview.cpp
changeset 34 ed14f46c0e55
parent 6 c3690ec91ef8
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    26 #include "hbabstractitemview.h"
    26 #include "hbabstractitemview.h"
    27 #include "hbabstractitemview_p.h"
    27 #include "hbabstractitemview_p.h"
    28 #include "hbabstractitemcontainer_p_p.h"
    28 #include "hbabstractitemcontainer_p_p.h"
    29 
    29 
    30 #include <hbabstractviewitem.h>
    30 #include <hbabstractviewitem.h>
       
    31 #include <hbabstractviewitem_p.h>
    31 #include <hbevent.h>
    32 #include <hbevent.h>
    32 #include <hbabstractitemcontainer_p.h>
    33 #include <hbabstractitemcontainer_p.h>
    33 #include <hbwidgetfeedback.h>
    34 #include <hbwidgetfeedback.h>
    34 #include <hbinstance.h>
    35 #include <hbinstance.h>
    35 #include <hbscrollbar.h>
    36 #include <hbscrollbar.h>
    36 #include <hbmodeliterator.h>
    37 #include <hbmodeliterator.h>
       
    38 #include <hbdataform.h>
    37 
    39 
    38 #include <QGraphicsSceneMouseEvent>
    40 #include <QGraphicsSceneMouseEvent>
    39 #include <QGraphicsScene>
    41 #include <QGraphicsScene>
    40 #include <QDebug>
    42 #include <QDebug>
    41 
    43 
    42 #include <QGesture>
    44 #include <QGesture>
    43 #include <QGestureEvent>
    45 #include <QGestureEvent>
    44 #include <QPanGesture>
    46 #include <QPanGesture>
    45 
    47 
       
    48 #include <QSortFilterProxyModel>
    46 
    49 
    47 /*!
    50 /*!
    48     @alpha
    51     @alpha
    49     @hbwidgets
    52     @hbwidgets
    50     \class HbAbstractItemView
    53     \class HbAbstractItemView
    51     \brief HbAbstractItemView provides basic functionality for item View Classes.  
    54     \brief The HbAbstractItemView class defines a set of common properties for the item view classes that derive from it.
    52     
    55     
    53     HbAbstractItemView is an abstract class and cannot itself be instantiated.
    56     The item view classes derived from %HbAbstractItemView are widgets used to display items of related data in a scrollable area. For example,
    54     HbAbstractItemView class can be used as the base class for every standard view that uses QAbstractItemModel.
    57     derived views are provided to display a sequential list, a tree, a grid and a form. The items of data are typically icons and text. 
    55     It provides a standard interface for interoperating with models(QAbstractItemModel and QItemSelectionModel)
    58     
    56     through signals and slots mechanism, enabling subclasses to be kept up-to-date with changes to their models.
    59     This class and its derived classes use Qt's model/view framework, which requires that the data to be displayed is stored first in the model. The only exception to this is the HbListWidget class, which does not require an existing model. The model can be any QAbstractItemModel-based model. This framework provides a standard interface for communicating with models through the signals and slots mechanism, which ensures the views are  updated when the model is changed. The QAbstractItemModel class describes the concepts of the model such as the \e index of the model, model \e items and \e roles.
    57     This class provides a default selection Model to work with. Application can set its own selection Model.
    60     
    58     There are several functions concerned with selection control like clearSelection(), selectAll(), setSelectionMode().
    61     The individual view items are objects derived from HbAbstractViewItem. %HbAbstractItemView stores a list of HbAbstractViewItems
    59     HbAbstractItemView provides standard support for mouse navigation and scrolling of items,
    62     and manages these view items for you. By changing this list the view items can be customized. The
    60     selections.
    63      %HbAbstractItemView class explains how this can be done.
    61 
    64     
    62     \b Subclassing
    65     %HbAbstractItemView is an abstract class and cannot itself be instantiated. Therefore please refer to the derived classes (HbListView, HbGridView, HbTreeView, HbDataForm) for examples of use.
    63     HbAbstractItemView can be subclassed for customization purposes. Derived class must provide
    66     
    64     implementation of scrollTo(). 
    67     %HbAbstractItemView provides properties that you can use to customize the following aspects of a view:  
    65 
    68 
    66     Each view item is represented by an instance of HbAbstractViewItem. HbAbstractViewItem
    69     - <b>Item sizes</b>. You can set the items to all display at the same size using setUniformItemSizes(), which  improves performance for some operations such as scrolling. 
    67     can be subclassed for customization purposes.
    70     
    68 
    71     - <b>Item recycling</b>. You can enable item recycling via setItemRecycling() to save memory. When item recycling is enabled, the view does not create a view item for every model item immediately after the view is launched. Instead, it creates view items for the visible area plus a few adjacent extra items. When the view is scrolled the existing view items are updated with new data from the model. By default item recycling is off.
    69     HbAbstractItemView can use item recycling. This means that only visible items
    72     
    70     plus a small buffer of items above and below the visible area are instantiated at a time. 
    73     - <b>Pixmap cache</b>. You can enable the pixmap cache via setItemPixmapCacheEnabled() to significantly improve scrolling speed. It 
    71     When the view is scrolled view items are recycled so that buffer size above and below the 
    74     is recommended that the cache is enabled except in cases where the cache would potentially cause problems. By default the pixmap cache is off.
    72     visible area is kept constant.By default this feature is disabled. 
    75     
       
    76     - <b>View scrolling</b>. You can scroll the view to ensure a particular item is shown by using scrollTo(). The function takes an optional hint parameter to define which part of the scroll area should contain the item, such as the middle or the top. Typically %scrollTo() is used after the creation of a view or to set a specific position for a newly added item.
       
    77     
       
    78     - <b>%Selection Mode</b>. You can change the selection mode to either single or multiple using setSelectionMode(). You can also modify the
       
    79     existing selection using clearSelection() and selectAll().
       
    80     
       
    81     - <b>%Selection Model</b>. You can change the selection model using setSelectionModel().
       
    82 
       
    83     - <b>Icon load policy</b>. You can change the icon load policy so that icons are loaded synchronously or asynchronously using setIconLoadPolicy(). By default icons are loaded asynchronously to improve performance, but this can result in empty areas being displayed while the icons are still being loaded.
       
    84     
       
    85     \section Subclassing
       
    86     %HbAbstractItemView can be subclassed for customization purposes.
       
    87     
       
    88 
       
    89     \sa  HbAbstractViewItem
    73 */
    90 */
    74 
    91 
    75 /*!
    92 /*!
    76     \fn void HbAbstractItemView::pressed(const QModelIndex &index)
    93     \fn void HbAbstractItemView::pressed(const QModelIndex &index)
    77 
    94 
    78     This signal is emitted when a touch down event is received within
    95     This signal is emitted when a touch down event is received within
    79     view item that is representing \a index.
    96     the view item that is representing \a index.
    80 
    97 
    81     See also released() and activated().
    98     \sa released() activated()
    82 */
    99 */
    83 
   100 
    84 /*!
   101 /*!
    85   \fn void HbAbstractItemView::released(const QModelIndex &index)
   102   \fn void HbAbstractItemView::released(const QModelIndex &index)
    86 
   103 
    87     This signal is emitted when a release event is received within
   104     This signal is emitted when a release event is received within
    88     Abstract view item that is representing \a index.
   105     the view item that is representing \a index.
    89 
   106 
    90     See also pressed() and activated().
   107     \sa pressed(), activated(), HbAbstractViewItem::released(const QPointF &position)
    91     \sa HbAbstractViewItem::released(const QPointF &position)
       
    92 */
   108 */
    93 
   109 
    94 /*!
   110 /*!
    95     \fn void HbAbstractItemView::activated(const QModelIndex &index)
   111     \fn void HbAbstractItemView::activated(const QModelIndex &index)
    96 
   112 
    97     This signal is emitted when the item specified by \a index is activated by the user.
   113     This signal is emitted when the item specified by \a index is activated by the user.
    98     How to activate items depends on the input method; e.g., with mouse by clicking the item
   114     An item is activated for example by clicking the item with a mouse
    99     or with touch input by tapping the item.
   115     or by tapping the item.
   100 
   116 
   101     See also pressed() and released().
   117     \sa pressed(), released()
   102 */
   118 */
   103 
   119 
   104 /*!
   120 /*!
   105     \fn void HbAbstractItemView::longPressed(HbAbstractViewItem *item, const QPointF &coords)
   121     \fn void HbAbstractItemView::longPressed(HbAbstractViewItem *item, const QPointF &coords)
   106 
   122 
   107     This signal is emitted when long press event is received within
   123     This signal is emitted when a long press event is received by a view item.
   108     Abstract view item \a viewItem. \a coords is scene position where the long press event happened.
   124     
       
   125     \param item The view item that received the long press event.
       
   126     \param coords The scene position where the long press event happened.
   109 */
   127 */
   110 
   128 
   111 /*!
   129 /*!
   112     \enum HbAbstractItemView::SelectionMode
   130     \enum HbAbstractItemView::SelectionMode
   113 
   131 
   114     selection types supported by HbAbstractItemView.
   132     Defines the available selection types.
   115 
       
   116     This enum describes different selection types available in LibHb.
       
   117 */
   133 */
   118 
   134 
   119 /*!
   135 /*!
   120     \var HbAbstractItemView::NoSelection
   136     \var HbAbstractItemView::NoSelection
   121 
   137 
   124 
   140 
   125 
   141 
   126 /*!
   142 /*!
   127     \var HbAbstractItemView::SingleSelection
   143     \var HbAbstractItemView::SingleSelection
   128 
   144 
   129     When the user selects an item, any already-selected item becomes unselected, and the user cannot
   145     When the user selects an item, all other items become deselected. The user cannot
   130     unselect the selected item. 
   146     deselect the selected item.
   131 */
   147 */
   132 
   148 
   133 /*!
   149 /*!
   134     \var HbAbstractItemView::MultiSelection
   150     \var HbAbstractItemView::MultiSelection
   135 
   151 
   136     When the user selects an item in the usual way, the selection state of that item
   152     When the user selects an item, the selection state of that item
   137     is toggled and the other items are left alone. 
   153     is toggled and the other items are left unchanged. 
   138 */
   154 */
   139 
   155 
   140 /*!
   156 /*!
   141     \enum HbAbstractItemView::ScrollHint
   157     \enum HbAbstractItemView::ScrollHint
   142 
   158 
   143     Enumeration specifies positions on the view, onto which an item can be scrolled. 
   159     Defines the positions on the view that an item can be scrolled to.
   144 
   160 
   145     \sa scrollTo(const QModelIndex &index, HbAbstractItemView::ScrollHint hint = EnsureVisible)
   161     \sa scrollTo()
   146 */
   162 */
   147 
   163 
   148 /*!
   164 /*!
   149     \var HbAbstractItemView::EnsureVisible
   165     \var HbAbstractItemView::EnsureVisible
   150 
   166 
   151     Item will be fully visible somewhere on the view. 
   167     The item will be fully visible in the view. 
   152 */
   168 */
   153 
   169 
   154 
   170 
   155 /*!
   171 /*!
   156     \var HbAbstractItemView::PositionAtTop
   172     \var HbAbstractItemView::PositionAtTop
   157 
   173 
   158     Item will be fully visible as topmost item.
   174     The item will be fully visible as the topmost item.
   159 */
   175 */
   160 
   176 
   161 
   177 
   162 /*!
   178 /*!
   163     \var HbAbstractItemView::PositionAtBottom
   179     \var HbAbstractItemView::PositionAtBottom
   164 
   180 
   165     Item will be fully visible as bottommost item.
   181     The item will be fully visible as the bottommost item.
   166 */
   182 */
   167 
   183 
   168 /*!
   184 /*!
   169     \var HbAbstractItemView::PositionAtCenter
   185     \var HbAbstractItemView::PositionAtCenter
   170 
   186 
   171     Item will be centered. 
   187     The item will be centered in the view.
   172 */
   188 */
   173 
   189 
   174 /*!
   190 /*!
   175     \enum HbAbstractItemView::ItemAnimation
   191     \enum HbAbstractItemView::ItemAnimation
   176 
   192 
   177     animations in HbAbstractItemView that can be disabled. By default all animations are enabled.
   193     Defines the types of animations in %HbAbstractItemView. The values are designed to be used as flags.
       
   194     By default all animations are enabled.
       
   195     
       
   196     The ItemAnimations type is a typedef for QFlags<ItemAnimation>. It stores an OR combination of the ItemAnimation values.
       
   197 
   178 */
   198 */
   179 
   199 
   180 /*!
   200 /*!
   181     \var HbAbstractItemView::None
   201     \var HbAbstractItemView::None
   182 
   202 
   183     Any animation is not applied. 
   203     No animations are applied. 
   184 */
   204 */
   185 
   205 
   186 /*!
   206 /*!
   187     \var HbAbstractItemView::Appear
   207     \var HbAbstractItemView::Appear
   188 
   208 
   189     Animation related to item appearance. Disable this animation in cases you expect many model items to appear,
   209     The animation displayed during item appearance. This animation can be disabled if desired. Disable this animation in cases where you expect many model items to appear,
   190     for example in case like insertion of a new data source, and you do not wish to see animations.
   210     such as during the insertion of a new data source. Note that the item appearance animations are not used directly after a call to setModel().
   191     
       
   192     Note that the item appearance animations are not used directly after a setModel call to force non-animated model change. 
       
   193 */
   211 */
   194 
   212 
   195 /*!
   213 /*!
   196     \var HbAbstractItemView::Disappear
   214     \var HbAbstractItemView::Disappear
   197 
   215 
   198     Animation related to item removal. Disable this animation in cases you expect many model items to disappear,
   216     The animation displayed during item removal. This animation can be disabled if desired. Disable this animation in cases where you expect many model items to disappear, such as during the filtering or removal of a data source.
   199 	for example in cases like filtering or removal of a data source, and you do not wish to see animations.
       
   200 */
   217 */
   201 
   218 
   202 /*!
   219 /*!
   203     \var HbAbstractItemView::TouchDown
   220     \var HbAbstractItemView::TouchDown
   204 
   221 
   205     Animation related to item press and release.
   222     The animations displayed during item press and release events. This animation can be disabled if desired.
   206 */
   223 */
   207 
   224 
   208 /*!
   225 /*!
   209     \var HbAbstractItemView::Expand
   226     \var HbAbstractItemView::Expand
   210 
   227 
   211     Animation related to setting item expand.
   228     The animation displayed when a setting item is expanded.
   212 */
   229 */
   213 
   230 
   214 /*!
   231 /*!
   215     \var HbAbstractItemView::Collapse
   232     \var HbAbstractItemView::Collapse
   216 
   233 
   217     Animation related to setting item collapsed.
   234     The animation displayed when a setting item is collapsed.
   218 */
   235 */
   219 
   236 
   220 /*!
   237 /*!
   221     \var HbAbstractItemView::All
   238     \var HbAbstractItemView::All
   222 
   239 
   223     Every animation is applied. 
   240     A combination of all the flags. Every animation is applied. 
   224 */
   241 */
   225 
   242 
   226 /*!
   243 
   227     Here are the main properties of the class:
   244 
   228 
   245 /*!
   229     \li HbAbstractItemView::itemRecycling: ItemRecycling.
   246     \enum HbAbstractItemView::IconLoadPolicy
   230     \li HbAbstractItemView::SelectionMode: Different selection types supported by view.
   247 
   231     \li HbAbstractItemView::bufferSize   : Buffer Size used for item recycling.
   248     Defines the icon load policies that are used to control how icon data is loaded into items.
   232     \li HbAbstractItemView::uniformItemSizes : This property holds whether all items in the item view have the same size.
   249 */
   233 */
   250 
   234 
   251 /*!
   235 
   252     \var HbAbstractItemView::LoadSynchronously
   236 /*!
   253 
   237     \fn void HbAbstractItemView::scrollTo(const QModelIndex &index,
   254     The icon data for items is always loaded synchronously. In this mode the items will block all other processing while they load their icons.  This can lead to longer item creation time and data update times which may result in poor performance especially while scrolling.
   238         HbAbstractItemView::ScrollHint hint = EnsureVisible)
   255     
   239 
   256     The benefit is that the icon content is guaranteed to be painted immediately so this avoids the possibility of empty areas that might appear if the data is loaded asynchronously.
   240     Scrolls the view if necessary to ensure that the item at \a index is visible
   257 */
   241     in a position according to \a hint. Default value just guarantees, that item will be fully visible. 
   258 
   242 
   259 /*!
   243     Scrolling is not animated but movement is immediate. 
   260     \var HbAbstractItemView::LoadAsynchronouslyWhenScrolling
   244 */
   261 
   245 
   262     The icon data is loaded asynchronously during scrolling but otherwise the data is loaded synchronously. 
   246 
   263 */
   247 /*!
   264 
   248     See also HbAbstractItemManager, HbAbstractViewItem, HbAbstractItemContainer.
   265 /*!
   249 
   266     \var HbAbstractItemView::LoadAsynchronouslyAlways
   250 */
   267 
   251 
   268     The icon data is always loaded asynchronously. In this mode the process of loading the icon data will not block other processing 
   252 /*!
   269     and so will not cause delays in item creation or data update times. This results in better scrolling 
   253     Constructs a new HbAbstractItemView with \a parent.
   270     performance since the item recycling delay is shared between different frames. 
       
   271 
       
   272     The disadvantage for this mode is that icon content is not guaranteed to be painted immediately and this may cause empty areas 
       
   273     to be painted while asynchronous data is being loaded.
       
   274 
       
   275     This is the default mode.
       
   276 */
       
   277 
       
   278 
       
   279 /*!
       
   280 
       
   281     Constructs a new %HbAbstractItemView with the given (private data) \a dd, \a container, \a model \a iterator and \a parent.
   254 */
   282 */
   255 HbAbstractItemView::HbAbstractItemView(HbAbstractItemViewPrivate &dd, 
   283 HbAbstractItemView::HbAbstractItemView(HbAbstractItemViewPrivate &dd, 
   256                                        HbAbstractItemContainer *container,
   284                                        HbAbstractItemContainer *container,
   257                                        HbModelIterator *modelIterator,
   285                                        HbModelIterator *modelIterator,
   258                                        QGraphicsItem *parent)
   286                                        QGraphicsItem *parent)
   264     d->q_ptr = this;
   292     d->q_ptr = this;
   265     d->init(container, modelIterator);
   293     d->init(container, modelIterator);
   266 }
   294 }
   267 
   295 
   268 /*!
   296 /*!
   269     Constructs a new HbAbstractItemView with \a parent.
   297     Constructs a new %HbAbstractItemView with \a container, \a modelIterator and \a parent.
   270 */
   298 */
   271 HbAbstractItemView::HbAbstractItemView(HbAbstractItemContainer *container,
   299 HbAbstractItemView::HbAbstractItemView(HbAbstractItemContainer *container,
   272                                        HbModelIterator *modelIterator,
   300                                        HbModelIterator *modelIterator,
   273                                        QGraphicsItem *parent)
   301                                        QGraphicsItem *parent)
   274     : HbScrollArea(*new HbAbstractItemViewPrivate, parent)
   302     : HbScrollArea(*new HbAbstractItemViewPrivate, parent)
   279     d->q_ptr = this;
   307     d->q_ptr = this;
   280     d->init(container, modelIterator);
   308     d->init(container, modelIterator);
   281 }
   309 }
   282 
   310 
   283 /*!
   311 /*!
   284     Destructs the abstract item view.
   312     Destructor.
   285 */
   313 */
   286 HbAbstractItemView::~HbAbstractItemView()
   314 HbAbstractItemView::~HbAbstractItemView()
   287 {
   315 {
   288 
   316 
   289 }
   317 }
   290 
   318 
   291 /*!
   319 /*!
   292     Returns model that view is currently presenting.
   320     Returns the model that the view is currently presenting.
       
   321     
       
   322     \sa setModel()
   293 */
   323 */
   294 QAbstractItemModel *HbAbstractItemView::model() const
   324 QAbstractItemModel *HbAbstractItemView::model() const
   295 {
   325 {
   296     Q_D(const HbAbstractItemView);
   326     Q_D(const HbAbstractItemView);
   297     return d->mModelIterator->model();
   327     return d->mModelIterator->model();
   298 }
   328 }
   299 
   329 
   300 /*!
   330 /*!
   301     Sets the model to \a model and replaces current item prototype with \a prototype.
   331     Sets the model to \a model and replaces the current item prototype with \a prototype.
   302     Ownership of the model is not taken. Ownership of the prototype is taken. 
   332     Ownership of the model is not taken. Ownership of the prototype is taken. 
   303     If no prototype has been passed, default prototype is used.
   333     If no prototype has been passed, the default prototype for the item view is used.
   304 
   334     
   305     Note! Itemview may create view items asynchronously.
   335     \note This function may cause existing view items to be recreated. The recreated view items are created asynchronously.
       
   336     
       
   337     \sa model(), setItemPrototype
       
   338 
   306 */
   339 */
   307 void HbAbstractItemView::setModel(QAbstractItemModel *model, HbAbstractViewItem *prototype)
   340 void HbAbstractItemView::setModel(QAbstractItemModel *model, HbAbstractViewItem *prototype)
   308 {
   341 {
   309     Q_D(HbAbstractItemView);
   342     Q_D(HbAbstractItemView);
   310     if(prototype) {
   343     if(prototype) {
   312     }
   345     }
   313     d->setModel(model);
   346     d->setModel(model);
   314 }
   347 }
   315 
   348 
   316 /*!
   349 /*!
   317     Returns the list of item prototypes.
   350     Returns the list of item prototypes. How to use item prototypes is described in HbAbstractViewItem.
       
   351     
       
   352     \sa setItemPrototype(), setItemPrototypes()
   318 */
   353 */
   319 QList<HbAbstractViewItem *> HbAbstractItemView::itemPrototypes() const
   354 QList<HbAbstractViewItem *> HbAbstractItemView::itemPrototypes() const
   320 {
   355 {
   321     Q_D(const HbAbstractItemView);
   356     Q_D(const HbAbstractItemView);
   322     return d->mContainer->itemPrototypes();
   357     return d->mContainer->itemPrototypes();
   323 }
   358 }
   324 
   359 
   325 /*!
   360 /*!
   326     Replaces current item prototypes with \a prototype. Ownership is taken.
   361     Replaces the current item prototypes with \a prototype and takes ownership of the prototype.
   327     
   362     
   328     Concrete item views provided by library have view specific view item prototype set by default.
   363     \note This function may cause existing view items to be recreated. The recreated view items are created asynchronously.
   329     
   364     
   330     Note! This function may cause that view items are recreated. They may be created asynchronously.
   365     \note Supplied item views such as HbListView have default prototypes which are set when the item view class is created.
       
   366     
       
   367     \sa itemPrototypes(), setItemPrototypes()
   331 
   368 
   332 */
   369 */
   333 void HbAbstractItemView::setItemPrototype(HbAbstractViewItem *prototype)
   370 void HbAbstractItemView::setItemPrototype(HbAbstractViewItem *prototype)
   334 {
   371 {
   335     Q_D(HbAbstractItemView);
   372     Q_D(HbAbstractItemView);
   336     if (prototype && d->mContainer->setItemPrototype(prototype))  {
   373     if (prototype && d->mContainer->setItemPrototype(prototype))  {
   337         d->resetContainer();
   374         d->resetContainer();
   338     }
   375     }
   339 }
   376 }
   340 
   377 
   341 /*!
   378 /*! 
   342     To support multiple Abstractview items within single AbstractItemview.
   379     Replaces the current item prototypes with the list of \a prototypes and takes ownership of the \a prototypes.
   343     Replace current item prototypes with list of \a prototypeList. Ownership is taken.
   380     
   344     Setting more than one prototype will disable item recycling feature.
   381     This allows multiple abstract view items within %HbAbstractItemView.
   345 
   382     
   346     When list view item is being created, HbAbstractViewItem::canSetModelIndex()
   383     When list view items are being created, the choice of which prototype to use for each item is 
   347     is called for every item until item is found, which can create an item for
   384     based on the order of the prototypes and each prototype's response to the view calling HbAbstractViewItem::canSetModelIndex().
   348     a model index. The prototype list is gone through from end to the beginning. 
   385     The prototype list is read from the end to the beginning. 
   349     
   386     
   350     Thus specialized prototypes should be in the end of the list and 
   387     The recommended list order is to place specialized prototypes at the end of the list and a
   351     'default' prototype first one. The specialized prototypes usually can create
   388     default prototype at the list head. The specialized prototypes would create
   352     only certain types of list view items. The default prototype usually return always true,
   389     only certain types of list view items and so would implement HbAbstractViewItem::canSetModelIndex().
   353     meaning that it can create any type of list view item. 
   390      The default prototype would always return \c true for HbAbstractViewItem::canSetModelIndex() and would be capable of creating
   354 
   391      any type of list view item. The specialized prototypes would be expected to create more complex items from extra data in the
   355     Concrete item views provided by library have view specific view item prototype set.
   392      model that the default prototype would otherwise ignore.
   356 
   393 
   357     Note! This function may cause that view items are recreated. They may be created asynchronously.
   394     Supplied item views such as HbListView have default prototypes which are set when the item view class is created.
   358 
   395     
   359     \sa HbAbstractViewItem::canSetModelIndex()
   396     \note Setting more than one prototype will disable the item recycling feature.
       
   397 
       
   398     \note This function may cause existing view items to be recreated. The recreated view items are created asynchronously.
       
   399 
       
   400     \sa setItemPrototype(), itemPrototypes()
   360 */
   401 */
   361 void HbAbstractItemView::setItemPrototypes(const QList<HbAbstractViewItem *> &prototypes)
   402 void HbAbstractItemView::setItemPrototypes(const QList<HbAbstractViewItem *> &prototypes)
   362 {
   403 {
   363     Q_D(HbAbstractItemView);
   404     Q_D(HbAbstractItemView);
   364     if(prototypes.count() > 0) {
   405     if(prototypes.count() > 0) {
   369     
   410     
   370 }
   411 }
   371 
   412 
   372 /*!
   413 /*!
   373     Returns the current selection model.
   414     Returns the current selection model.
       
   415     
       
   416     \sa setSelectionModel
   374 */
   417 */
   375 QItemSelectionModel *HbAbstractItemView::selectionModel() const
   418 QItemSelectionModel *HbAbstractItemView::selectionModel() const
   376 {
   419 {
   377     Q_D(const HbAbstractItemView);
   420     Q_D(const HbAbstractItemView);
   378     return d->mSelectionModel;
   421     return d->mSelectionModel;
   379 }
   422 }
   380 
   423 
   381 /*!
   424 /*!
   382     Sets the current selection model to \a selectionModel.
   425     Sets the current selection model to \a selectionModel.
   383     Note: If setModel() is called after this function, the given selectionModel will be
   426     
   384     replaced by default selection model of the view.
   427     \note If setModel() is called after this function, the selection model will be
       
   428     replaced by the default selection model of the view.
       
   429     
       
   430     \sa selectionModel
   385 */
   431 */
   386 void HbAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel)
   432 void HbAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel)
   387 {
   433 {
   388     Q_D(HbAbstractItemView);
   434     Q_D(HbAbstractItemView);
   389     if (selectionModel 
   435     if (selectionModel 
   391         d->setSelectionModel(selectionModel);
   437         d->setSelectionModel(selectionModel);
   392     }
   438     }
   393 }
   439 }
   394 
   440 
   395 /*!
   441 /*!
   396     If \a newMode is not same as current selection mode of view,
   442     Sets the current selection mode to \a newMode.
   397     updates selection mode, all viewitems and clears all existing selections.
   443     
       
   444     If \a newMode is different from the current selection mode for the view,
       
   445     this function updates all view items and clears all existing selections.
       
   446     
       
   447     \sa selectionMode()
   398 */
   448 */
   399 void HbAbstractItemView::setSelectionMode(SelectionMode newMode)
   449 void HbAbstractItemView::setSelectionMode(SelectionMode newMode)
   400 {
   450 {
   401     Q_D(HbAbstractItemView);
   451     Q_D(HbAbstractItemView);
   402     if (d->mSelectionMode != newMode) {
   452     if (d->mSelectionMode != newMode) {
   424         d->mSelectionModel->select(QItemSelection(firstIndex, lastIndex), QItemSelectionModel::Select);
   474         d->mSelectionModel->select(QItemSelection(firstIndex, lastIndex), QItemSelectionModel::Select);
   425     }
   475     }
   426 }
   476 }
   427 
   477 
   428 /*!
   478 /*!
   429     Deselects all selected items. The current index will not be changed.
   479     Deselects all selected items. The current index is not changed.
   430 */
   480  */
   431 void HbAbstractItemView::clearSelection()
   481 void HbAbstractItemView::clearSelection()
   432 {
   482 {
   433     Q_D(HbAbstractItemView);
   483     Q_D(HbAbstractItemView);
   434     if (d->mSelectionModel) {
   484     if (d->mSelectionModel) {
   435         d->mClearingSelection = true;
   485         d->mClearingSelection = true;
   437         d->mClearingSelection = false;
   487         d->mClearingSelection = false;
   438     }
   488     }
   439 }
   489 }
   440 
   490 
   441 /*!
   491 /*!
   442     Returns current selection mode used by view.
   492     Returns the current selection mode used by the view.
       
   493     
       
   494     \sa setSelectionMode
   443 */
   495 */
   444 HbAbstractItemView::SelectionMode HbAbstractItemView::selectionMode() const
   496 HbAbstractItemView::SelectionMode HbAbstractItemView::selectionMode() const
   445 {
   497 {
   446     Q_D(const HbAbstractItemView);
   498     Q_D(const HbAbstractItemView);
   447     return d->mSelectionMode;
   499     return d->mSelectionMode;
   448 }
   500 }
   449 
   501 
   450 /*!
   502 /*!
   451     Returns index of current item.
   503     Returns the index of the current item.
   452 */
   504 */
   453 QModelIndex HbAbstractItemView::currentIndex() const
   505 QModelIndex HbAbstractItemView::currentIndex() const
   454 {
   506 {
   455     Q_D(const HbAbstractItemView);
   507     Q_D(const HbAbstractItemView);
   456     return d->mCurrentIndex;
   508     return d->mCurrentIndex;
   457 }
   509 }
   458 
   510 
   459 /*!
   511 /*!
   460    Sets current index to \a index. The item is selected depending on the \a selectionFlag.
   512    Sets the current index to \a index. The item is selected depending on the \a selectionFlag.
   461    By default item is not selected. If current selection mode is NoSelection,
   513    By default the item is not selected. If the current selection mode (HbAbstractItemView::SelectionMode) is NoSelection,
   462    item is not selected irrespective of the selection flag.
   514    the item is not selected irrespective of the selection flag.
       
   515    
       
   516    \sa setSelectionMode()
   463 */
   517 */
   464 void HbAbstractItemView::setCurrentIndex(const QModelIndex &index, 
   518 void HbAbstractItemView::setCurrentIndex(const QModelIndex &index, 
   465                                          QItemSelectionModel::SelectionFlags selectionFlag)
   519                                          QItemSelectionModel::SelectionFlags selectionFlag)
   466 {
   520 {
   467     Q_D(HbAbstractItemView);
   521     Q_D(HbAbstractItemView);
   477     }
   531     }
   478 }
   532 }
   479 
   533 
   480 
   534 
   481 /*!
   535 /*!
   482     Returns model index of the model's root item. 
   536     Returns the model index of the model's root item. 
   483     The root item is parent item to view's top level items.
   537     The root item is the parent item to the view's top level items.
   484     The root can be invalid.
   538     The root can be invalid.
       
   539     
       
   540     \sa setRootIndex
   485 */
   541 */
   486 QModelIndex HbAbstractItemView::rootIndex() const
   542 QModelIndex HbAbstractItemView::rootIndex() const
   487 {
   543 {
   488     Q_D(const HbAbstractItemView);
   544     Q_D(const HbAbstractItemView);
   489     return d->mModelIterator->rootIndex();
   545     return d->mModelIterator->rootIndex();
   490 }
   546 }
   491 
   547 
   492 /*!
   548 /*!
   493     Sets root index to \a index.
   549     Sets the root index to \a index.
   494     All view items are deleted and recreated
   550     All view items are deleted and recreated.
   495 
   551 
   496     Note! View items may be created asynchronously.
   552     \note View items may be created asynchronously.
       
   553     
       
   554     \sa rootIndex
   497 */
   555 */
   498 void HbAbstractItemView::setRootIndex(const QModelIndex &index)
   556 void HbAbstractItemView::setRootIndex(const QModelIndex &index)
   499 {
   557 {
   500     Q_D(HbAbstractItemView);
   558     Q_D(HbAbstractItemView);
   501     if (d->mModelIterator->rootIndex() != index ) {
   559     if (d->mModelIterator->rootIndex() != index ) {
   505         setCurrentIndex(QModelIndex(), QItemSelectionModel::NoUpdate);
   563         setCurrentIndex(QModelIndex(), QItemSelectionModel::NoUpdate);
   506     }
   564     }
   507 }
   565 }
   508 
   566 
   509 /*!
   567 /*!
   510     Resets Item view.
   568     Resets the item view. This resets all animations, scrolls the view to the original position, but preserves any existing selections.
   511 */
   569 */
   512 void HbAbstractItemView::reset()
   570 void HbAbstractItemView::reset()
   513 {
   571 {
   514     Q_D(HbAbstractItemView);    
   572     Q_D(HbAbstractItemView);    
   515 
   573 
       
   574     d->stopAnimating();
   516     d->mModelIterator->setRootIndex(QPersistentModelIndex());
   575     d->mModelIterator->setRootIndex(QPersistentModelIndex());
   517     d->resetContainer();
   576     d->resetContainer();
   518 
   577 
   519     setCurrentIndex(QModelIndex(), QItemSelectionModel::NoUpdate);
   578     setCurrentIndex(QModelIndex(), QItemSelectionModel::NoUpdate);
   520 }
   579 }
   521 
   580 
   522 /*!
   581 /*!
   523     \reimp
   582     
   524     It should be always called by child class if overridden.
   583     If overridden, the child class should always call this function to ensure the events related to the abstract item view
       
   584     and scroll area are handled.
   525 */
   585 */
   526 bool HbAbstractItemView::event(QEvent *e)
   586 bool HbAbstractItemView::event(QEvent *e)
   527 {
   587 {
   528     Q_D(HbAbstractItemView);
   588     Q_D(HbAbstractItemView);
   529 
   589 
   530     bool result = HbScrollArea::event(e);
   590     bool result = HbScrollArea::event(e);
   531 
   591 
   532     // The two above statements have to be executed before these
   592     // The two above statements have to be executed before these
   533     if (e->type() == HbEvent::ChildFocusIn) {
   593     if (e->type() == QEvent::LayoutRequest) {
   534         HbAbstractViewItem *item = 0;
       
   535         QList<HbAbstractViewItem *> items = d->mContainer->items();
       
   536 
       
   537         for (QGraphicsItem *currentItem = scene()->focusItem(); currentItem != 0; currentItem = currentItem->parentItem()) {
       
   538             item = d->viewItem(currentItem);
       
   539             if (item) {
       
   540                 if (items.indexOf(item) == -1) {
       
   541                     item = 0;
       
   542                 } else {
       
   543                     break;
       
   544                 }
       
   545             }
       
   546         }
       
   547         if (item && item->modelIndex() != d->mCurrentIndex) {
       
   548             setCurrentIndex(item->modelIndex());
       
   549         }
       
   550         result = true;
       
   551     } else if (e->type() == QEvent::LayoutRequest) {
       
   552         d->mContainer->resizeContainer();
   594         d->mContainer->resizeContainer();
   553         if (d->mPostponedScrollIndex.isValid()) { 
   595         if (d->mPostponedScrollIndex.isValid()) { 
   554            d->scrollTo(d->mPostponedScrollIndex, d->mPostponedScrollHint);
   596            d->scrollTo(d->mPostponedScrollIndex, d->mPostponedScrollHint);
       
   597            if (scrollDirections() | Qt::Vertical) {
       
   598                d->updateScrollBar(Qt::Vertical);
       
   599            }
       
   600            if (scrollDirections() | Qt::Horizontal) {
       
   601                d->updateScrollBar(Qt::Horizontal);
       
   602            }
   555         } 
   603         } 
   556         result = true;
   604         result = true;
   557     }
   605     }
   558 
   606 
   559     return result;
   607     return result;
   560 }
   608 }
   561 
   609 
   562 /*!
   610 /*!
   563     \reimp
   611     
   564 
   612 
   565     This slot is called when orientation is changed.
   613     This slot is called when the orientation is changed.
   566     \a newOrientation has the currentOrientation mode.
   614     \param newOrientation The current orientation mode.
   567     Note: Currently platform dependent orientation support is not available
   615     
       
   616     \sa Qt:Orientation
   568 */
   617 */
   569 void HbAbstractItemView::orientationChanged(Qt::Orientation newOrientation)
   618 void HbAbstractItemView::orientationChanged(Qt::Orientation newOrientation)
   570 {
   619 {
   571     Q_UNUSED(newOrientation);
   620     Q_UNUSED(newOrientation);
   572 
   621 
   585 
   634 
   586     d->mVisibleIndex = QModelIndex();
   635     d->mVisibleIndex = QModelIndex();
   587 }
   636 }
   588 
   637 
   589 /*!
   638 /*!
   590     This slot is called just before orientation is to be changed.
   639     This slot is called just before the orientation is changed.
   591     Note: Currently platform dependent orientation support is not available
   640     
       
   641     \sa orientationChanged()
   592 */
   642 */
   593 void HbAbstractItemView::orientationAboutToBeChanged()
   643 void HbAbstractItemView::orientationAboutToBeChanged()
   594 {
   644 {
   595     Q_D(HbAbstractItemView);
   645     Q_D(HbAbstractItemView);
   596     d->saveIndexMadeVisibleAfterMetricsChange();
   646     d->saveIndexMadeVisibleAfterMetricsChange();
   597 }
   647 }
   598 
   648 
   599 /*!
   649 /*!
   600     Sets item recycling to \a enabled.
   650     Sets item recycling to \a enabled.
   601     By default recycling is off.
   651     By default recycling is off.
       
   652     
       
   653     \sa itemRecycling
   602 */
   654 */
   603 void HbAbstractItemView::setItemRecycling(bool enabled)
   655 void HbAbstractItemView::setItemRecycling(bool enabled)
   604 {
   656 {
   605     Q_D(HbAbstractItemView);
   657     Q_D(HbAbstractItemView);
   606     d->mContainer->setItemRecycling(enabled);
   658     d->mContainer->setItemRecycling(enabled);
   607 }
   659 }
   608 
   660 
   609 /*!
   661 /*!
   610     Returns whether item recycling feature is in use.
   662     Returns whether the item recycling feature is in use.
       
   663     
       
   664     \sa setItemRecycling
   611 */
   665 */
   612 bool HbAbstractItemView::itemRecycling() const
   666 bool HbAbstractItemView::itemRecycling() const
   613 {
   667 {
   614     Q_D(const HbAbstractItemView);
   668     Q_D(const HbAbstractItemView); 
   615     return d->mContainer->itemRecycling();
   669     return d->mContainer->itemRecycling();
   616 }
   670 }
   617 
   671 
   618 /*!
   672 /*!
   619     Returns view item representing current model index. This can be NULL if
   673     Returns the view item representing the current model index. This can be \c NULL if
   620     index has no view item representing it.
   674     the index has no view item representing it.
   621 */
   675 */
   622 HbAbstractViewItem *HbAbstractItemView::currentViewItem() const
   676 HbAbstractViewItem *HbAbstractItemView::currentViewItem() const
   623 {
   677 {
   624     Q_D(const HbAbstractItemView);
   678     Q_D(const HbAbstractItemView);
   625     return d->currentItem();
   679     return d->currentItem();
   626 }
   680 }
   627 
   681 
   628 
   682 
   629 /*!
   683 /*!
   630     Returns view item representing given model \a index. This can be NULL if
   684     Returns the view item representing the given  \a index in the model. This can be \c NULL if
   631     index has no view item representing it.
   685     the index has no view item representing it.
   632 */
   686 */
   633 HbAbstractViewItem *HbAbstractItemView::itemByIndex(const QModelIndex &index) const
   687 HbAbstractViewItem *HbAbstractItemView::itemByIndex(const QModelIndex &index) const
   634 {
   688 {
   635     Q_D(const HbAbstractItemView);
   689     Q_D(const HbAbstractItemView);
   636     return d->mContainer->itemByIndex(index);
   690     return d->mContainer->itemByIndex(index);
   637 }
   691 }
   638 
   692 
   639 /*!
   693 /*!
   640    Returns true if item with model index is fully or partially visible in view.
   694    Returns \c true if the item in the model at \a index is fully or partially visible in the view.
   641 */
   695 */
   642 bool HbAbstractItemView::isVisible(const QModelIndex & index) const
   696 bool HbAbstractItemView::isVisible(const QModelIndex & index) const
   643 {
   697 {
   644     Q_D( const HbAbstractItemView );
   698     Q_D( const HbAbstractItemView );
   645     return d->visible(d->mContainer->itemByIndex(index), false);
   699     return d->visible(d->mContainer->itemByIndex(index), false);
   646 }
   700 }
   647 
   701 
   648 /*!
   702 /*!
   649     Base class implemmentation. Take care about scrollTo when it was
   703     Scrolls the view to ensure that the item at \a index is visible.
   650     called before view was visible (first scrollTo can be done after
   704     
   651     first layoutRequest).
   705     The optional \a hint parameter defines which part of the scroll area should contain the item. 
   652     It should be always called by child class if overridden.
   706     The view is only scrolled if necessary, and the scrolling is not animated. Any child class implementations
   653 
   707     must be called if they override this function.
   654     Note! If item recycling is enabled, view item may not have reached its final 
   708     
   655     position, when this function returns. Then its position is fine tuned asynchronously. 
   709     The base class implementation is able to scroll an indexed item to make it visible if a view item has already been populated with the indexed item from the model. If recycling is enabled, derived classes must perform any recycling required. 
   656 
   710     
   657     \sa HbAbstractItemView::itemRecycling()
   711     \note If item recycling is enabled, the view item may not have reached its final 
   658 */
   712     position when this function returns. Item positions can still be changed while the items are in the process of being layed out,
       
   713      which takes place asynchronously. 
       
   714 
       
   715     \sa itemRecycling(), QEvent
       
   716 */
       
   717 
   659 void HbAbstractItemView::scrollTo(const QModelIndex &index, ScrollHint hint)
   718 void HbAbstractItemView::scrollTo(const QModelIndex &index, ScrollHint hint)
   660 {
   719 {
   661     Q_D(HbAbstractItemView);
   720     Q_D(HbAbstractItemView);
   662     if (    index.isValid()
   721     if (    index.isValid()
   663         &&  d->mModelIterator->model() == index.model()) {
   722         &&  d->mModelIterator->model() == index.model()) {
   674         QCoreApplication::postEvent(this, new QEvent(QEvent::LayoutRequest));
   733         QCoreApplication::postEvent(this, new QEvent(QEvent::LayoutRequest));
   675     }
   734     }
   676 }
   735 }
   677 
   736 
   678 /*!
   737 /*!
   679     Returns list of currently visible view items.
   738     Returns the list of fully or partially visible view items.
   680 */
   739 */
   681 QList<HbAbstractViewItem *> HbAbstractItemView::visibleItems() const
   740 QList<HbAbstractViewItem *> HbAbstractItemView::visibleItems() const
   682 {
   741 {
   683     Q_D(const HbAbstractItemView);
   742     Q_D(const HbAbstractItemView);
   684     QList<HbAbstractViewItem *> visibleItems;
   743     QList<HbAbstractViewItem *> visibleItems;
   691     }
   750     }
   692     return visibleItems;
   751     return visibleItems;
   693 }
   752 }
   694 
   753 
   695 /*!
   754 /*!
   696     Returns SelectionFlags to be used when updating selection of a item.
   755     Called when the selection is being updated as a result of user input. This might be the start of a selection or a change to the selection. Returns the selection flags to be used when updating the selection of an item.
   697     The event is a user input event, such as a mouse or keyboard event.
   756     Subclasses should override this function to define their own selection behavior.
   698     contiguousArea is true, if selectiontype is not single or no selection and
   757 
   699     user has pressed on contiguousArea of viewItem i.e CheckBox.
   758     \param item The view item that emitted the event.
   700     By default this is false.
   759     \param event The event such as a mouse or keyboard event. Touch events are received as mouse events. The event parameter does not always have all its properties set. For mouse events the event parameter always has the event type and position set.
   701     Subclasses should overide this function to define their own selection behavior.
   760     
   702 
   761     \sa HbAbstractViewItem::selectionAreaContains(), HbAbstractViewItem
   703     Note: The \a event parameter is not necessary a full event. For mouse events
       
   704     it is quaranteed to contain the event type and position.
       
   705 
       
   706     \sa HbAbstractViewItem::selectionAreaContains(const QPointF &scenePosition) const
       
   707 */
   762 */
   708 QItemSelectionModel::SelectionFlags HbAbstractItemView::selectionCommand(const HbAbstractViewItem *item,
   763 QItemSelectionModel::SelectionFlags HbAbstractItemView::selectionCommand(const HbAbstractViewItem *item,
   709                                                                          const QEvent *event)
   764                                                                          const QEvent *event)
   710 { 
   765 { 
   711     Q_D(HbAbstractItemView);
   766     Q_D(HbAbstractItemView);
   712     // When the parameter contiguousArea is removed, copy paste 'd ->selectionFlags()' into here.
   767     // When the parameter contiguousArea is removed, copy paste 'd ->selectionFlags()' into here.
   713     return d->selectionFlags(item, event);
   768     return d->selectionFlags(item, event);
   714 }
   769 }
   715 
   770 
   716 /*!
   771 /*!
   717     This slot is called when items are changed in model. 
   772     This slot is called when items are changed in the model. 
   718     The changed items are those from \a topLeft to \a bottomRight inclusive.
   773     The changed items are those from \a topLeft to \a bottomRight inclusive.
   719     If just one item is changed topLeft == bottomRight.
   774     If only one item is changed \a topLeft will equal \a bottomRight.
   720 */
   775 */
   721 void  HbAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
   776 void  HbAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
   722 {
   777 {
   723     Q_D(HbAbstractItemView);
   778     Q_D(HbAbstractItemView);
   724 
   779 
   766         }
   821         }
   767     }
   822     }
   768 }
   823 }
   769 
   824 
   770 /*!
   825 /*!
   771     This slot is called when current index is changed in selection model.
   826     This slot is called when the current index is changed in the selection model.
   772     current is the changed or current index and previous in the old current index.
   827     Changing the current index does not affect which items are selected.
   773     current index may not be selected.
   828 
       
   829     \param current New current index.
       
   830     \param previous Previous current index.
   774 */
   831 */
   775 void HbAbstractItemView::currentIndexChanged(const QModelIndex &current, const QModelIndex &previous)
   832 void HbAbstractItemView::currentIndexChanged(const QModelIndex &current, const QModelIndex &previous)
   776 {
   833 {
   777     Q_D(HbAbstractItemView);
   834     Q_UNUSED(previous);
       
   835     Q_D(HbAbstractItemView);
       
   836 
   778 
   837 
   779     if (current != d->mCurrentIndex) {
   838     if (current != d->mCurrentIndex) {
   780         d->mCurrentIndex = current;
   839         d->mCurrentIndex = current;
   781                
   840     }
   782         if (previous.isValid()) {
   841 }
   783            d->mContainer->setItemTransientStateValue(previous, "focused", false);
   842 
   784         }
   843 /*!
   785         
   844     This slot is called whenever the selection changes. The change in the selection is represented as an item selection
   786         if (d->mCurrentIndex.isValid()) {
   845     of \a selected items and an item selection of \a deselected items.
   787             d->mContainer->setItemTransientStateValue(d->mCurrentIndex, "focused", true);
   846     Note that the current index changes independently from the selection. Also note that this signal will not be emitted when the item model is reset.
   788         }
   847     
   789 
       
   790     }
       
   791 }
       
   792 
       
   793 /*!
       
   794     This slot is called when selection of items has changed.
       
   795     selected contains all selected items, deselected contains
       
   796     all deselected items.
       
   797 */
   848 */
   798 void HbAbstractItemView::currentSelectionChanged(const QItemSelection &selected, 
   849 void HbAbstractItemView::currentSelectionChanged(const QItemSelection &selected, 
   799                                                  const QItemSelection &deselected)
   850                                                  const QItemSelection &deselected)
   800 {
   851 {
   801     Q_D(HbAbstractItemView);
   852     Q_D(HbAbstractItemView);
   803     int count = selectedIndexes.count();
   854     int count = selectedIndexes.count();
   804     for (int i = 0; i < count; ++i) {
   855     for (int i = 0; i < count; ++i) {
   805         HbAbstractViewItem *item = d->mContainer->itemByIndex(selectedIndexes.at(i));
   856         HbAbstractViewItem *item = d->mContainer->itemByIndex(selectedIndexes.at(i));
   806         if (item) {
   857         if (item) {
   807             item->setCheckState(Qt::Checked);
   858             item->setCheckState(Qt::Checked);
   808             if (!d->mClearingSelection && !d->mDoingContiguousSelection) {
   859             if (d->mContSelectionAction) {
       
   860                 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged, Hb::ModifierScrolling);
       
   861             }
       
   862             else {
   809                 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged); 
   863                 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged); 
   810             }
   864             }
   811         } 
   865         } 
   812         d->mContainer->setItemTransientStateValue(selectedIndexes.at(i),
   866         d->mContainer->setItemTransientStateValue(selectedIndexes.at(i),
   813                                          "checkState",
   867                                          "checkState",
   818     count = deselectedIndexes.count();
   872     count = deselectedIndexes.count();
   819     for (int i = 0; i < count; ++i) {
   873     for (int i = 0; i < count; ++i) {
   820         HbAbstractViewItem *item = d->mContainer->itemByIndex(deselectedIndexes.at(i));
   874         HbAbstractViewItem *item = d->mContainer->itemByIndex(deselectedIndexes.at(i));
   821         if (item) {
   875         if (item) {
   822             item->setCheckState(Qt::Unchecked);
   876             item->setCheckState(Qt::Unchecked);
   823             if (!d->mClearingSelection && !d->mDoingContiguousSelection) {
   877 
       
   878             if (d->mContSelectionAction) {
       
   879                 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged, Hb::ModifierScrolling);
       
   880             }
       
   881             else {
   824                 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged);
   882                 HbWidgetFeedback::triggered(item, Hb::InstantSelectionChanged);
   825             }
   883             }
   826         } 
   884         } 
   827         d->mContainer->setItemTransientStateValue(deselectedIndexes.at(i),
   885         d->mContainer->setItemTransientStateValue(deselectedIndexes.at(i),
   828                                          "checkState",
   886                                          "checkState",
   830     }
   888     }
   831 }
   889 }
   832 
   890 
   833 /*!
   891 /*!
   834     This slot is called when rows are inserted. 
   892     This slot is called when rows are inserted. 
   835     The new rows are those under the given parent from start to end inclusive
   893     The new rows are those between \a start and \a end inclusive, under the given \a parent item.
   836 */
   894 */
   837 void HbAbstractItemView::rowsInserted(const QModelIndex &parent, int start, int end)
   895 void HbAbstractItemView::rowsInserted(const QModelIndex &parent, int start, int end)
   838 {
   896 {
   839     Q_D(HbAbstractItemView);
   897     Q_D(HbAbstractItemView);
   840 
   898 
   853     }
   911     }
   854 }
   912 }
   855 
   913 
   856 /*!
   914 /*!
   857     This slot is called after rows have been removed from the model.
   915     This slot is called after rows have been removed from the model.
   858     The removed items are those between start and end inclusive, under the given parent item.
   916     The removed items are those between \a start and \a end inclusive, under the given \a parent item.
   859 */
   917 */
   860 void HbAbstractItemView::rowsRemoved(const QModelIndex &parent,int start,int end)
   918 void HbAbstractItemView::rowsRemoved(const QModelIndex &parent,int start,int end)
   861 {
   919 {
   862     Q_D(HbAbstractItemView);
   920     Q_D(HbAbstractItemView);
   863     d->rowsRemoved(parent, start, end);
   921     d->rowsRemoved(parent, start, end);
   864 }
   922 }
   865 
   923 
   866 /*!
   924 /*!
   867     This slot is called just before rows are removed from the model.
   925     This slot is called just before rows are removed from the model.
   868     The items that will be removed are those between \a start and \a end inclusive, under the given \a parent item.
   926     The items that will be removed are those between \a start and \a end inclusive, under the given \a index item.
   869     Default implementation is empty
   927     The base implementation is empty.
   870 */
   928 */
   871 void HbAbstractItemView::rowsAboutToBeRemoved(const QModelIndex &index, int start, int end)
   929 void HbAbstractItemView::rowsAboutToBeRemoved(const QModelIndex &index, int start, int end)
   872 {
   930 {
   873     Q_UNUSED(index);
   931     Q_UNUSED(index);
   874     Q_UNUSED(start);
   932     Q_UNUSED(start);
   875     Q_UNUSED(end);
   933     Q_UNUSED(end);
   876 }
   934 }
   877 
   935 
   878 /*!
   936 /*!
   879     This slot is called just before rows are inserted into the model.
   937     This slot is called just before rows are inserted into the model.
   880     The items that will be inserted are those between \a start and \a end inclusive, under the given \a parent item.
   938     The items that will be inserted are those between \a start and \a end inclusive, under the given \a index item.
   881     Default implementation is empty.
   939     The base implementation is empty.
   882 */
   940 */
   883 void HbAbstractItemView::rowsAboutToBeInserted(const QModelIndex &index, int start, int end)
   941 void HbAbstractItemView::rowsAboutToBeInserted(const QModelIndex &index, int start, int end)
   884 {
   942 {
   885     Q_UNUSED(index);
   943     Q_UNUSED(index);
   886     Q_UNUSED(start);
   944     Q_UNUSED(start);
   887     Q_UNUSED(end);
   945     Q_UNUSED(end);
   888 }
   946 }
   889 
   947 
   890 /*!
   948 /*!
   891     This slot is called when columns are inserted. 
   949     This slot is called when columns are inserted. 
   892     The new rows are those under the given parent from start to end inclusive
   950     The new columns are those under the given \a parent from \a start to \a end inclusive.
   893 */
   951 */
   894 void HbAbstractItemView::columnsInserted(const QModelIndex &parent, int start, int end)
   952 void HbAbstractItemView::columnsInserted(const QModelIndex &parent, int start, int end)
   895 {
   953 {
   896     Q_UNUSED(end)
   954     Q_UNUSED(end)
   897     Q_UNUSED(start)
   955     Q_UNUSED(start)
   906     }
   964     }
   907 }
   965 }
   908 
   966 
   909 /*!
   967 /*!
   910     This slot is called after columns have been removed from the model.
   968     This slot is called after columns have been removed from the model.
   911     The removed items are those between start and end inclusive, under the given parent item.
   969     The removed items are those between \a start and \a end inclusive, under the given \a parent item.
   912 */
   970 */
   913 void HbAbstractItemView::columnsRemoved(const QModelIndex &parent, int start, int end)
   971 void HbAbstractItemView::columnsRemoved(const QModelIndex &parent, int start, int end)
   914 {
   972 {
   915     Q_UNUSED(end)
   973     Q_UNUSED(end)
   916     Q_UNUSED(start)
   974     Q_UNUSED(start)
   926 
   984 
   927 }
   985 }
   928 
   986 
   929 /*!
   987 /*!
   930     This slot is called just before columns are removed from the model.
   988     This slot is called just before columns are removed from the model.
   931     The items that will be removed are those between \a start and \a end inclusive, under the given \a parent item.
   989     The items that will be removed are those between \a start and \a end inclusive, under the given \a index item.
   932     Default implementation is empty
   990     The base implementation is empty.
   933 */
   991 */
   934 void HbAbstractItemView::columnsAboutToBeRemoved(const QModelIndex &index, int start, int end)
   992 void HbAbstractItemView::columnsAboutToBeRemoved(const QModelIndex &index, int start, int end)
   935 {
   993 {
   936     Q_UNUSED(index);
   994     Q_UNUSED(index);
   937     Q_UNUSED(start);
   995     Q_UNUSED(start);
   938     Q_UNUSED(end);
   996     Q_UNUSED(end);
   939 }
   997 }
   940 
   998 
   941 /*!
   999 /*!
   942     This slot is called just before columns are inserted into the model.
  1000     This slot is called just before columns are inserted into the model.
   943     The items that will be inserted are those between \a start and \a end inclusive, under the given \a parent item.
  1001     The items that will be inserted are those between \a start and \a end inclusive, under the given \a index item.
   944     Default implementation is empty.
  1002     The base implementation is empty.
   945 */
  1003 */
   946 void HbAbstractItemView::columnsAboutToBeInserted(const QModelIndex &index, int start, int end)
  1004 void HbAbstractItemView::columnsAboutToBeInserted(const QModelIndex &index, int start, int end)
   947 {
  1005 {
   948     Q_UNUSED(index);
  1006     Q_UNUSED(index);
   949     Q_UNUSED(start);
  1007     Q_UNUSED(start);
   950     Q_UNUSED(end);
  1008     Q_UNUSED(end);
   951 }
  1009 }
   952 
  1010 
   953 /*!
  1011 /*!
   954     Emits the activated signal.
  1012     Emits the activated() signal.
       
  1013 
   955 */
  1014 */
   956 void HbAbstractItemView::emitActivated(const QModelIndex &modelIndex)
  1015 void HbAbstractItemView::emitActivated(const QModelIndex &modelIndex)
   957 {
  1016 {
   958     emit activated(modelIndex);
  1017     emit activated(modelIndex);
   959 }
  1018 }
   960 
  1019 
   961 /*!
  1020 /*!
   962     Emits the pressed signal.
  1021     Emits the pressed() signal.
       
  1022 
   963 */
  1023 */
   964 void HbAbstractItemView::emitPressed(const QModelIndex &modelIndex)
  1024 void HbAbstractItemView::emitPressed(const QModelIndex &modelIndex)
   965 {
  1025 {
   966     emit pressed(modelIndex);
  1026     emit pressed(modelIndex);
   967 }
  1027 }
   968 
  1028 
   969 /*!
  1029 /*!
   970     Emits the released signal.
  1030     Emits the released() signal.
       
  1031 
   971 */
  1032 */
   972 void HbAbstractItemView::emitReleased(const QModelIndex &modelIndex)
  1033 void HbAbstractItemView::emitReleased(const QModelIndex &modelIndex)
   973 {
  1034 {
   974     emit released(modelIndex);
  1035     emit released(modelIndex);
   975 }
  1036 }
   976 
  1037 
   977 /*!
  1038 /*!
   978     \reimp
  1039     The abstract item view implementation handles item recycling.
   979 */
  1040 */
   980 bool HbAbstractItemView::scrollByAmount(const QPointF &delta)
  1041 bool HbAbstractItemView::scrollByAmount(const QPointF &delta)
   981 {
  1042 {
   982     Q_D(HbAbstractItemView);
  1043     Q_D(HbAbstractItemView);
   983 
  1044 
   992 
  1053 
   993     return HbScrollArea::scrollByAmount(newDelta);
  1054     return HbScrollArea::scrollByAmount(newDelta);
   994 }
  1055 }
   995 
  1056 
   996 /*!
  1057 /*!
   997     \reimp
  1058     The abstract item view responds to QGraphicsItem::ItemSceneHasChanged to check if this item view has been added
       
  1059     or removed from the window. This is to ensure scene filters and signals are connected only when necessary.
       
  1060     
       
  1061     \sa QGraphicsItem
   998 */
  1062 */
   999 QVariant HbAbstractItemView::itemChange(GraphicsItemChange change, const QVariant &value)
  1063 QVariant HbAbstractItemView::itemChange(GraphicsItemChange change, const QVariant &value)
  1000 {
  1064 {
  1001     if (change == QGraphicsItem::ItemSceneHasChanged) {
  1065     if (change == QGraphicsItem::ItemSceneHasChanged) {
  1002         HbMainWindow *window = mainWindow();
  1066         HbMainWindow *window = mainWindow();
  1029     }
  1093     }
  1030     return HbScrollArea::itemChange(change, value);
  1094     return HbScrollArea::itemChange(change, value);
  1031 }
  1095 }
  1032 
  1096 
  1033 /*!
  1097 /*!
  1034     Returns the current name of layout definition of view items of this view.
  1098     Returns the current name of the layout definition for the view items of this view.
  1035 
  1099 
  1036     \sa setLayoutName()
  1100     \sa setLayoutName()
  1037 */
  1101 */
  1038 QString HbAbstractItemView::layoutName() const
  1102 QString HbAbstractItemView::layoutName() const
  1039 {
  1103 {
  1041     
  1105     
  1042     return d->mLayoutOptionName;
  1106     return d->mLayoutOptionName;
  1043 }
  1107 }
  1044 
  1108 
  1045 /*!
  1109 /*!
  1046     Sets the name of layout definition \a layoutName for selecting 
  1110     Sets the name of the layout definition for this view to \a layoutName. This specifies that 
  1047     the layout of view items of this view from css/xml files.
  1111     the layout of the view items comes from the css/xml files.
  1048 
  1112 
  1049     This layoutName is accessible from css file as layoutName property
  1113     This layoutName property is accessible from the css file as the \c layoutName property
  1050     of the view item.
  1114     of the view item.
  1051 
  1115 
  1052     This can be used for customization purposes. By default the layout name
  1116     This can be used for customization purposes. By default the layout name
  1053     is "default".
  1117     is set to "default".
  1054 
  1118 
  1055     \sa layoutOption()
  1119     \sa layoutName()
  1056 */
  1120 */
  1057 void HbAbstractItemView::setLayoutName(const QString &layoutName)
  1121 void HbAbstractItemView::setLayoutName(const QString &layoutName)
  1058 {
  1122 {
  1059     Q_D(HbAbstractItemView);
  1123     Q_D(HbAbstractItemView);
  1060     
  1124     
  1061     d->mLayoutOptionName = layoutName;
  1125     d->mLayoutOptionName = layoutName;
  1062     
  1126     
  1063     QList<HbAbstractViewItem *> items = d->mContainer->items();
  1127     QList<HbAbstractViewItem *> items = d->mContainer->items();
  1064     foreach (HbAbstractViewItem *item, items) {
  1128     foreach (HbAbstractViewItem *item, items) {
  1065         QEvent* polishEvent = new QEvent( QEvent::Polish );
  1129         HbAbstractViewItemPrivate::d_ptr(item)->repolishItem();
  1066         QCoreApplication::postEvent(item, polishEvent);
       
  1067     }
  1130     }
  1068 } 
  1131 } 
  1069 
  1132 
  1070 /*!
  1133 /*!
  1071     Sets the property informing whether all items in the item view have the same size.
  1134     Sets the items to all display at the same size if \a enabled is \c true.
  1072     
  1135     
  1073     This property should only be set to true if it is guaranteed that all items in the view have 
  1136     This property should only be set to \c true if it is guaranteed that all items in the view have 
  1074     the same size. This enables the view to do some optimizations for performance purposes.
  1137     the same size. This enables the view to do some optimizations for performance purposes.
  1075 
  1138 
  1076     By default, this property is false.
  1139     By default, this property is \c false.
  1077 
  1140 
  1078     \sa uniformItemSizes
  1141     \sa uniformItemSizes
  1079 */
  1142 */
  1080 void HbAbstractItemView::setUniformItemSizes(bool enable)
  1143 void HbAbstractItemView::setUniformItemSizes(bool enable)
  1081 {
  1144 {
  1082     Q_D(HbAbstractItemView);
  1145     Q_D(HbAbstractItemView);
  1083     d->mContainer->setUniformItemSizes(enable);
  1146     d->mContainer->setUniformItemSizes(enable);
  1084 }
  1147 }
  1085 
  1148 
  1086 /*!
  1149 /*!
  1087     Returns the current value of the uniformItemsSizes property.
  1150     Returns whether the uniform item sizes feature is in use.
  1088 
  1151 
  1089     By default, this property is false.
  1152     The default value is \c false.
       
  1153     
       
  1154     \sa setUniformItemSizes
  1090 */
  1155 */
  1091 bool HbAbstractItemView::uniformItemSizes() const
  1156 bool HbAbstractItemView::uniformItemSizes() const
  1092 {
  1157 {
  1093     Q_D(const HbAbstractItemView);
  1158     Q_D(const HbAbstractItemView);
  1094     return d->mContainer->uniformItemSizes();
  1159     return d->mContainer->uniformItemSizes();
  1095 }
  1160 }
  1096 
  1161 
  1097 /*!
  1162 /*!
  1098     Returns pointer to HbModelIterator. It provides functions to work with QModelIndex.
  1163     Returns the model iterator used by this item view.
  1099 */
  1164 */
  1100 HbModelIterator *HbAbstractItemView::modelIterator() const
  1165 HbModelIterator *HbAbstractItemView::modelIterator() const
  1101 {
  1166 {
  1102     Q_D(const HbAbstractItemView);
  1167     Q_D(const HbAbstractItemView);
  1103     return d->mModelIterator;
  1168     return d->mModelIterator;
  1104 }
  1169 }
  1105 
  1170 
  1106 /*!
  1171 /*!
  1107     Sets the bitmask controlling the item animations.
  1172     Sets the bit mask controlling the item animations.
  1108 */
  1173     
  1109 void HbAbstractItemView::setEnabledAnimations(HbAbstractItemView::ItemAnimations flags)
  1174     \sa enabledAnimations()
       
  1175 */
       
  1176 void HbAbstractItemView::setEnabledAnimations(ItemAnimations flags)
  1110 {
  1177 {
  1111     Q_D(HbAbstractItemView);
  1178     Q_D(HbAbstractItemView);
  1112     d->mEnabledAnimations = flags;
  1179     d->mEnabledAnimations = flags;
  1113 }
  1180 }
  1114 
  1181 
  1115 /*!
  1182 /*!
  1116     Returns the mask controlling the item animations.
  1183     Returns the mask controlling the item animations.
       
  1184     
       
  1185     \sa ItemAnimation, setEnabledAnimations()
  1117 */
  1186 */
  1118 HbAbstractItemView::ItemAnimations HbAbstractItemView::enabledAnimations() const
  1187 HbAbstractItemView::ItemAnimations HbAbstractItemView::enabledAnimations() const
  1119 {
  1188 {
  1120     Q_D(const HbAbstractItemView);
  1189     Q_D(const HbAbstractItemView);
  1121     return d->mEnabledAnimations;
  1190     return d->mEnabledAnimations;
  1122 }
  1191 }
  1123 
  1192 
  1124 /*!
  1193 /*!
  1125     \reimp
  1194    The abstract item view implementation accepts panning events.
  1126 */
  1195 */
  1127 void HbAbstractItemView::gestureEvent(QGestureEvent *event)
  1196 void HbAbstractItemView::gestureEvent(QGestureEvent *event)
  1128 {
  1197 {
  1129     if (event->gesture(Qt::PanGesture)) {
  1198     if (event->gesture(Qt::PanGesture)) {
  1130         Q_D(HbAbstractItemView);
  1199         Q_D(HbAbstractItemView);
  1137         HbScrollArea::gestureEvent(event);
  1206         HbScrollArea::gestureEvent(event);
  1138     }
  1207     }
  1139 }
  1208 }
  1140 
  1209 
  1141 /*! 
  1210 /*! 
  1142     This slot is called when touch down event occurs. Default implementation handles selection 
  1211     This slot is called when a touch down event occurs.
  1143     and calls emitPressed().
  1212     
  1144 
  1213     The base implementation handles selection      and calls emitPressed().
  1145     \sa HbAbstractViewItem::pressed(const QPointF &position)
  1214 
  1146     \sa emitPressed()
  1215     \sa HbAbstractViewItem::pressed(const QPointF &position),  emitPressed()
  1147 */
  1216 */
  1148 void HbAbstractItemView::itemPressed(const QPointF &pos)
  1217 void HbAbstractItemView::itemPressed(const QPointF &pos)
  1149 {
  1218 {
  1150     Q_D(HbAbstractItemView);
  1219     Q_D(HbAbstractItemView);
  1151 
  1220 
  1154     d->mPreviousSelectedCommand = QItemSelectionModel::NoUpdate;
  1223     d->mPreviousSelectedCommand = QItemSelectionModel::NoUpdate;
  1155     d->mSelectionSettings &= ~HbAbstractItemViewPrivate::Selection;
  1224     d->mSelectionSettings &= ~HbAbstractItemViewPrivate::Selection;
  1156     d->mContSelectionAction = QItemSelectionModel::NoUpdate;
  1225     d->mContSelectionAction = QItemSelectionModel::NoUpdate;
  1157 
  1226 
  1158     HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender()); 
  1227     HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender()); 
  1159     QModelIndex index = item->modelIndex();
  1228     if (item) {
  1160 
  1229         QModelIndex index = item->modelIndex();
  1161     if (d->mSelectionMode != HbAbstractItemView::NoSelection) {
  1230 
  1162         QGraphicsSceneMouseEvent mousePressEvent(QEvent::GraphicsSceneMousePress);
  1231         if (d->mSelectionMode != HbAbstractItemView::NoSelection) {
  1163         mousePressEvent.setPos(pos);
  1232             QGraphicsSceneMouseEvent mousePressEvent(QEvent::GraphicsSceneMousePress);
  1164         d->mSelectionModel->select(index, selectionCommand(item, &mousePressEvent));
  1233             mousePressEvent.setPos(pos);
  1165     }
  1234             d->mSelectionModel->select(index, selectionCommand(item, &mousePressEvent));
  1166 
  1235         }
  1167     emitPressed(item->modelIndex());
  1236         emitPressed(item->modelIndex());
       
  1237     }
  1168 }
  1238 }
  1169 
  1239 
  1170 /*! 
  1240 /*! 
  1171     This slot is called when release event occurs for view item.
  1241     This slot is called by a view item when a release event occurs for that item.
  1172     Default implementation calls emitReleased().
  1242     
  1173 
  1243     The base implementation calls emitReleased().
  1174     \sa HbAbstractViewItem::released(const QPointF &position)
  1244 
  1175     \sa emitReleased()
  1245     \sa HbAbstractViewItem::released(const QPointF &position),   emitReleased(),  itemPressed()
  1176 */
  1246 */
  1177 void HbAbstractItemView::itemReleased(const QPointF &pos)
  1247 void HbAbstractItemView::itemReleased(const QPointF &pos)
  1178 {
  1248 {
  1179     Q_UNUSED(pos);
  1249     Q_UNUSED(pos);
  1180 
  1250 
  1181     HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender()); 
  1251     HbAbstractViewItem *item = qobject_cast<HbAbstractViewItem *>(sender()); 
  1182     emitReleased(item->modelIndex());
  1252     emitReleased(item->modelIndex());
  1183 }
  1253 }
  1184 
  1254 
  1185 /*! 
  1255 /*! 
  1186     This slot is called when view item is activated.
  1256     This slot is called when a view item is activated.
  1187     Default implementation handles selection and calls emitActivated().
  1257     
  1188 
  1258     The base implementation handles selection and calls emitActivated().
  1189     \sa HbAbstractViewItem::itemActivated(const QPointF &position)
  1259 
  1190     \sa emitActivated()
  1260     \sa HbAbstractViewItem::activated(const QPointF &position), emitActivated()
  1191 */
  1261 */
  1192 void HbAbstractItemView::itemActivated(const QPointF &pos)
  1262 void HbAbstractItemView::itemActivated(const QPointF &pos)
  1193 {
  1263 {
  1194     Q_D(HbAbstractItemView);
  1264     Q_D(HbAbstractItemView);
  1195 
  1265 
  1203         mouseReleaseEvent.setPos(pos);
  1273         mouseReleaseEvent.setPos(pos);
  1204         d->mSelectionModel->select(index, selectionCommand(item, &mouseReleaseEvent));
  1274         d->mSelectionModel->select(index, selectionCommand(item, &mouseReleaseEvent));
  1205     }
  1275     }
  1206 
  1276 
  1207     emitActivated(index);
  1277     emitActivated(index);
       
  1278 
       
  1279     setCurrentIndex(index);
  1208 }
  1280 }
  1209 
  1281 
  1210 /*! 
  1282 /*! 
  1211     This slot is called when view item is long pressed and long press is enabled in itemview.
  1283     This slot is called when the view item is long pressed and long press events are allowed for this item view.
  1212     Default implementation calls longPressed().
  1284     
  1213 
  1285     The base implementation calls longPressed().
  1214     \sa HbAbstractViewItem::longPressed(const QPointF &position)
  1286 
  1215     \sa longPressEnabled()
  1287     \sa HbAbstractViewItem::longPressed(const QPointF &position),  longPressEnabled(),  longPressed()
  1216     \sa longPressed()
       
  1217 */
  1288 */
  1218 void HbAbstractItemView::itemLongPressed(const QPointF &pos)
  1289 void HbAbstractItemView::itemLongPressed(const QPointF &pos)
  1219 {
  1290 {
  1220     Q_D(HbAbstractItemView);
  1291     Q_D(HbAbstractItemView);
  1221 
  1292 
  1223     QModelIndex index = item->modelIndex();
  1294     QModelIndex index = item->modelIndex();
  1224 
  1295 
  1225     d->mSelectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
  1296     d->mSelectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
  1226 
  1297 
  1227     emit longPressed(item, item->mapToScene(pos));
  1298     emit longPressed(item, item->mapToScene(pos));
       
  1299 
       
  1300     setCurrentIndex(index);
  1228 }
  1301 }
  1229 
  1302 
  1230 /*! 
  1303 /*! 
  1231     This slot is called when concrete view item has been created. Default implementation connects
  1304     This slot is called when \a item has been created.
  1232     touch event related signals of HbAbstractViewItem to respective slots in this class.
  1305     
  1233 
  1306     The base implementation connects
  1234     \sa HbAbstractViewItem::pressed(const QPointF &position)
  1307     the touch event signals of HbAbstractViewItem to the respective slots in this class.
  1235     \sa HbAbstractViewItem::released(const QPointF &position)
  1308 
  1236     \sa HbAbstractViewItem::itemActivated(const QPointF &position)
  1309     \sa HbAbstractViewItem, itemPressed(), itemReleased(), itemActivated(), itemLongPressed()
  1237     \sa HbAbstractViewItem::longPressed(const QPointF &position)
       
  1238     \sa itemPressed()
       
  1239     \sa itemReleased()
       
  1240     \sa itemActivated()
       
  1241     \sa itemLongPressed()
       
  1242 */
  1310 */
  1243 void HbAbstractItemView::itemCreated(HbAbstractViewItem *item)
  1311 void HbAbstractItemView::itemCreated(HbAbstractViewItem *item)
  1244 {
  1312 {
  1245     QObject::connect(item, SIGNAL(pressed(QPointF)), this, SLOT(itemPressed(QPointF)));
  1313     QObject::connect(item, SIGNAL(pressed(QPointF)), this, SLOT(itemPressed(QPointF)));
  1246     QObject::connect(item, SIGNAL(released(QPointF)), this, SLOT(itemReleased(QPointF)));
  1314     QObject::connect(item, SIGNAL(released(QPointF)), this, SLOT(itemReleased(QPointF)));
  1247     QObject::connect(item, SIGNAL(activated(QPointF)), this, SLOT(itemActivated(QPointF)));
  1315     QObject::connect(item, SIGNAL(activated(QPointF)), this, SLOT(itemActivated(QPointF)));
  1248     QObject::connect(item, SIGNAL(longPressed(QPointF)), this, SLOT(itemLongPressed(QPointF))); 
  1316     QObject::connect(item, SIGNAL(longPressed(QPointF)), this, SLOT(itemLongPressed(QPointF))); 
  1249 }
  1317 
  1250 
  1318 
  1251 /*!
  1319     Q_D(HbAbstractItemView);
  1252     \reimp
  1320     if (d->mContainer->items().count() == 0) {
       
  1321         d->mEmptyView->setVisible(false);
       
  1322     }
       
  1323 }
       
  1324 
       
  1325 /*!
       
  1326    \sa QGraphicsItem::sceneEventFilter()
  1253 */
  1327 */
  1254 bool HbAbstractItemView::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
  1328 bool HbAbstractItemView::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
  1255 {
  1329 {
  1256     Q_D(HbAbstractItemView);
  1330     Q_D(HbAbstractItemView);
  1257     if (    d->mPostponedScrollIndex.isValid()
  1331     if (    d->mPostponedScrollIndex.isValid()
  1262     }
  1336     }
  1263     return false;
  1337     return false;
  1264 }
  1338 }
  1265 
  1339 
  1266 /*!
  1340 /*!
  1267     Sets the value of the longPressEnabled property.  This value is set
  1341     Sets the long press gestures feature to \a enabled.  Set this value 
  1268     to true if the widget is to respond to long press gestures, false otherwise.
  1342     to \c true if the widget is to respond to long press gestures, or to \c false otherwise.
  1269 
  1343 
  1270     The default value is true.
  1344     The default value is \c true.
  1271 
  1345 
  1272     \sa HbAbstractItemView::longPressEnabled()
  1346     \sa longPressEnabled()
  1273 */
  1347 */
  1274 void HbAbstractItemView::setLongPressEnabled(bool enabled)
  1348 void HbAbstractItemView::setLongPressEnabled(bool enabled)
  1275 {
  1349 {
  1276     Q_D(HbAbstractItemView);
  1350     Q_D(HbAbstractItemView);
  1277     d->mLongPressEnabled = enabled;
  1351     d->mLongPressEnabled = enabled;
  1278 }
  1352 }
  1279 
  1353 
  1280 /*!
  1354 /*!
  1281     Returns true if the item view handles long press gestures, false otherwise.
  1355     Returns whether the long press gestures feature is enabled.
  1282 
  1356 
  1283     \sa HbAbstractItemView::setLongPressEnabled()
  1357     \sa setLongPressEnabled()
  1284 */
  1358 */
  1285 bool HbAbstractItemView::longPressEnabled() const
  1359 bool HbAbstractItemView::longPressEnabled() const
  1286 {
  1360 {
  1287     Q_D(const HbAbstractItemView);
  1361     Q_D(const HbAbstractItemView);
  1288     return d->mLongPressEnabled;
  1362     return d->mLongPressEnabled;
  1289 }
  1363 }
  1290 
  1364 
  1291 /*!
  1365 /*!
  1292     Slot handles QAbstractItemModel::layoutChanged() signal. 
  1366     Sets the pixmap cache feature to \a enabled. When this is set to \c true, it enables the item view's pixmap cache.
  1293     Default implementation sets first model item visible as first view item. 
  1367     
       
  1368     Enabling the item view's pixmap cache will significantly improve the item view scrolling speed.
       
  1369     It is recommended that the cache is enabled except 
       
  1370     in cases where the cache would potentially cause problems. Examples of situations where the cache should not be used are when a custom view item prototype cannot update the pixmap properly, or an effect is applied to a widget within a view item.
       
  1371     
       
  1372     By default the item pixmap cache is disabled. 
       
  1373 
       
  1374     \note The item pixmap cache is not supported by HbDataForm.
       
  1375 
       
  1376     \sa itemPixmapCacheEnabled(), HbAbstractViewItem::updatePixmapCache()
       
  1377 */
       
  1378 void HbAbstractItemView::setItemPixmapCacheEnabled(bool enabled)
       
  1379 {
       
  1380     Q_D(HbAbstractItemView);
       
  1381     
       
  1382     if (qgraphicsitem_cast<HbDataForm*>(this) == 0) {
       
  1383         d->mItemPixmapCacheEnabled = enabled;
       
  1384     }
       
  1385 }
       
  1386 
       
  1387 /*!
       
  1388     Returns whether the pixmap cache is in use.
       
  1389 
       
  1390     \sa setItemPixmapCacheEnabled()
       
  1391 */
       
  1392 bool HbAbstractItemView::itemPixmapCacheEnabled() const
       
  1393 {
       
  1394     Q_D(const HbAbstractItemView);
       
  1395     return d->mItemPixmapCacheEnabled;
       
  1396 }
       
  1397 
       
  1398 /*!
       
  1399     Sets the icon load policy to \a policy.
       
  1400 
       
  1401     The default value is HbAbstractItemView::LoadAsynchronouslyAlways.
       
  1402 
       
  1403     \sa iconLoadPolicy()
       
  1404 */
       
  1405 void HbAbstractItemView::setIconLoadPolicy(IconLoadPolicy policy)
       
  1406 {
       
  1407     Q_D(HbAbstractItemView);
       
  1408     if (d->mIconLoadPolicy != policy) {
       
  1409         d->mIconLoadPolicy = policy;
       
  1410         
       
  1411         foreach (HbAbstractViewItem *prototype, itemPrototypes()) {
       
  1412             HbAbstractViewItemPrivate::d_ptr(prototype)->mSharedData->updateIconItemsAsyncMode();
       
  1413         }
       
  1414     }
       
  1415 }
       
  1416 
       
  1417 /*!
       
  1418     Returns the current icon load policy used by the view.
       
  1419 
       
  1420     \sa setIconLoadPolicy()
       
  1421 */
       
  1422 HbAbstractItemView::IconLoadPolicy HbAbstractItemView::iconLoadPolicy() const
       
  1423 {
       
  1424     Q_D(const HbAbstractItemView);
       
  1425     return d->mIconLoadPolicy;
       
  1426 }
       
  1427 
       
  1428 
       
  1429 /*!
       
  1430     Returns the current text displayed in the item view when there are no items.
       
  1431 
       
  1432     \sa HbAbstractItemView::setEmptyText()
       
  1433 */
       
  1434 QString HbAbstractItemView::emptyText() const
       
  1435 {
       
  1436     Q_D(const HbAbstractItemView);
       
  1437     return d->mEmptyView->emptyViewText();
       
  1438 }
       
  1439 
       
  1440 /*!
       
  1441     Sets the text displayed in the item view when there are no items. The default value is empty.
       
  1442 
       
  1443     \sa HbAbstractItemView::emptyText()
       
  1444 */
       
  1445 void HbAbstractItemView::setEmptyText(const QString &emptyText)
       
  1446 {
       
  1447     Q_D(HbAbstractItemView);
       
  1448     d->mEmptyView->setEmptyViewText(emptyText);
       
  1449 }
       
  1450 
       
  1451 /*!
       
  1452     This slot handles the QAbstractItemModel::layoutChanged() signal. 
       
  1453     
       
  1454     The base implementation checks if the buffer items need to be updated and if so after the update sets the first model item visible 
       
  1455     as the first view item.
       
  1456     
       
  1457     
       
  1458     QSortFilterProxyModel sends the layoutChanged 
       
  1459     signal whenever there is a data change in the model but in that case the view should
       
  1460     not be scrolled. 
  1294 */
  1461 */
  1295 void HbAbstractItemView::modelLayoutChanged()
  1462 void HbAbstractItemView::modelLayoutChanged()
  1296 {
  1463 {
  1297     Q_D(HbAbstractItemView);
  1464     Q_D(HbAbstractItemView);
       
  1465     QModelIndex firstItemIndex;
       
  1466 
       
  1467     QSortFilterProxyModel *proxyModel = qobject_cast<QSortFilterProxyModel *>(d->mModelIterator->model());
       
  1468     if (proxyModel && proxyModel->dynamicSortFilter()) {
       
  1469         QList<HbAbstractViewItem *> items = d->mContainer->items();
       
  1470 
       
  1471         if (!items.isEmpty() && !size().isEmpty()) {
       
  1472             // Try maintaining first visible item as first visible item.
       
  1473             int itemCount = items.count();
       
  1474 
       
  1475             for (int currentIndex = 0; currentIndex < itemCount; ++currentIndex) {
       
  1476                 HbAbstractViewItem *item = items.at(currentIndex);
       
  1477                 if (d->visible(item, true)) {
       
  1478                     // Resolve new first item index when first visible item is known.
       
  1479                     firstItemIndex = d->mModelIterator->index(d->mModelIterator->indexPosition(item->modelIndex()) - currentIndex);
       
  1480                     break;
       
  1481                 }
       
  1482             }
       
  1483         }
       
  1484     }
       
  1485 
       
  1486     if (!firstItemIndex.isValid()) {
       
  1487         // New first item index not fount (e.g. when items are not visible) -> take first index.
       
  1488         firstItemIndex = d->mModelIterator->nextIndex(firstItemIndex);
       
  1489     }
       
  1490 
  1298     d->mContainer->d_func()->updateItemBuffer();
  1491     d->mContainer->d_func()->updateItemBuffer();
  1299     d->mContainer->setModelIndexes(d->mModelIterator->nextIndex(QModelIndex()));
  1492 
  1300     if (d->mContainer->items().count() > 0) {
  1493     if (!d->mContainer->items().isEmpty()) {
  1301         scrollTo(d->mContainer->items().at(0)->modelIndex(), PositionAtTop);
  1494         if (d->mContainer->items().first()->modelIndex() != firstItemIndex) {
       
  1495             d->mContainer->setModelIndexes(firstItemIndex);
       
  1496             scrollTo(firstItemIndex, PositionAtTop);
       
  1497         } else {
       
  1498             d->mContainer->setModelIndexes(firstItemIndex);
       
  1499         }
  1302     }
  1500     }
  1303 }
  1501 }
  1304 
  1502 
  1305 #include "moc_hbabstractitemview.cpp"
  1503 #include "moc_hbabstractitemview.cpp"
  1306 
  1504