src/hbwidgets/dataform/hbdataform.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include <hbdataform.h>
       
    27 #include <hbdataformmodelitem.h>
       
    28 #include <hbdataformmodel.h>
       
    29 #include "hbdataform_p.h"
       
    30 #include "hbdataformviewitem_p.h"
       
    31 #include "hbdataitemcontainer_p.h"
       
    32 #include "hbdatagroup_p.h"
       
    33 #include "hbdatagroup_p_p.h"
       
    34 #include <hbcombobox.h>
       
    35 #include "hbdataformheadingwidget_p.h"
       
    36 #include "hbtreemodeliterator_p.h"
       
    37 
       
    38 #include <QGraphicsSceneMouseEvent>
       
    39 #include <QCoreApplication>
       
    40 
       
    41 /*!
       
    42     @beta
       
    43     @hbwidgets
       
    44     \class HbDataForm
       
    45     \brief HbDataForm represents hierarchical dataitems in the form of groups,pages and 
       
    46     items.
       
    47     The HbDataForm class provides a default view implementation of dataform.
       
    48     A HbDataForm implements a hierarchical representation of data items from a model.
       
    49 
       
    50     HbDataForm implements the interfaces defined by the HbAbstractItemView class to allow 
       
    51     it to display data provided  by models derived from the QAbstractItemModel class.
       
    52 
       
    53     It is simple to construct a dataform displaying data from a model. The user has to create
       
    54     HbDataFormModel and create the hierarchy of HbDataFormModelItems .The hierarchy is 
       
    55     similar to the following.
       
    56     
       
    57     - HbDataForm
       
    58        - HbDataFormPage1
       
    59          - HbDataGroup1
       
    60            - HbDataGroupPage1
       
    61              - HbDataItem
       
    62              - HbDataItem
       
    63              - HbDataItem
       
    64              - HbDataItem
       
    65        - HbDataFormPage2
       
    66          - HbDataGroup2
       
    67            - HbDataGroupPage2
       
    68              - HbDataItem
       
    69              - HbDataItem
       
    70              - HbDataItem
       
    71              - HbDataItem
       
    72  
       
    73     HbDataItem can be the child of HbDataForm, HbDataFormPage,HbDataGroup and 
       
    74     HbDataGroupPage. An instance of HbDataForm has to be created and model should be set 
       
    75     to the form using setModel(HbDataFormModel) API.
       
    76     The properties of each DataItem node can be set using HbDataFormModelItem convenient
       
    77     API's. These data are parsed while the visualization instance of each item is created and 
       
    78     set on each item.
       
    79 
       
    80     The model/view architecture ensures that the contents of the data view are updated as the 
       
    81     model changes.
       
    82 
       
    83     Items that have children can be in expanded (children are visible) or collapsed 
       
    84     (children are hidden) state. DataItems of type HbDataFormPage, HbDataGroup and 
       
    85     HbDataGroupPage can be expanded and collapsed. HbDataItem of type FormPageItem, 
       
    86     GroupItem, GroupPageItem can only have children. Each item in model is represented by an 
       
    87     instance of HbDataFormViewItem. HbDataForm uses HbDataFormViewItem prototype to instantiate 
       
    88     the HbDataForm items. HbDataFormViewItem can be subclassed for customization purposes.
       
    89     
       
    90     The Model hierarchy can be created using the convenient API's provided on model class like
       
    91     appendDataFormPage , appendDataFormGroup ,appendDataFormGroupPage and 
       
    92     appendDataFormItem. All of these will return HbDataFormModelItem instance correspoding 
       
    93     to each type on which user can set item specific data. Otherwise each HbDataFormModelItem can 
       
    94     be created individually by passing the corresponding type of item (GroupItem, GroupPageItem, 
       
    95     FormPageItem) and create the tree of HbDataFormModelItem using setParent API 
       
    96     or by passing the parent HbDataFormModelItem in constructor. Later the top level 
       
    97     HbDataFormModelItem can be added inside the model.
       
    98 
       
    99     After doing the setModel, the visualization gets created . Only the items inside the expanded 
       
   100     group or group page instances are created. When an item's visualization is created , 
       
   101     DataForm emits activated(constQModelIndex&) signal. The application can get 
       
   102     HbDataFormViewItem and content widget from DataForm using QModelIndex.    
       
   103     
       
   104     The signal emitted by HbDataForm
       
   105     \li activated(const QModelIndex &index) Emitted when the HbDataFormViewItem corresponding to
       
   106     \a index is shown. User can connect to this signal and can fetch the instance of 
       
   107     HbDataFormViewItem from HbDataForm using the API dataFormViewItem(const QModelIndex &index).
       
   108     \li dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) emitted when the 
       
   109     HbDataFormModel is updated \atopLeft and \abottomRight will be same since every node has only one column.
       
   110     User can connect to this signal and can fetch the instance of HbDataFormViewItem from HbDataForm 
       
   111     using the API dataFormViewItem(const QModelIndex &index) or user can fetch HbDataFormModelItem using API 
       
   112     itemFromIndex(const QModelIndex &index) in HbDataFormModel .When user updates model using 
       
   113     setContentWidgetData API provided in HbDataFormModelItem class, then DataForm takes care of updating the 
       
   114     corresponding item's visualization.
       
   115 
       
   116     The user can also provide connection information to correspoding content widget of each HbDataFormModelItem
       
   117     using API addConnection(HbDataFormModelItem* item, const char* signal, QObject* receiver, consta char* slot)
       
   118     provided in HbDataForm class.The connection will be established when the item visualization is created .
       
   119     similar way removeConnection(HbDataFormModelItem *item, const char* signal, QObject *receiver, const char* slot)
       
   120     and removeAllConnection() API can be used. Connection can be established or removed even at runtime also.
       
   121     
       
   122     An example of how to create HbDataForm:
       
   123     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,31}
       
   124 
       
   125     The output generated by the above code looks like:
       
   126 
       
   127     \image html hbsettingform.png
       
   128 
       
   129     This is how HbDataForm will look like in landscape mode:
       
   130 
       
   131     \image html hbsettingform_landscape.png
       
   132 
       
   133     \sa HbDataFormViewItem, HbDataFormModel, HbDataFormModelItem
       
   134 
       
   135     Creating Custom Item:
       
   136     Application developer can create custom DataItem by deriving from HbDataFormViewItem and setting this as 
       
   137     prototype(setItemProtoType() API).
       
   138     Application has to override virtual API's createCustomWidget() , restore()and save(). 
       
   139     createCustomWidget() API should return the corresponding custom HbWidget which can also be a compound widget.
       
   140     Signal connection for child widgets inside the compound widget should taken care by the application. 
       
   141     restore() API will be called by the framework when the model data is changed.
       
   142     So restore() should take care of updating the visual items with correspoding data from model. 
       
   143     save() API should update the model.App developer should  connect respective widgets SIGNALs to SLOT save() 
       
   144     and update the data to model .
       
   145 
       
   146 */
       
   147 
       
   148 /*!
       
   149     \fn void HbAbstractItemView::activated(const QModelIndex &index)
       
   150 
       
   151     This signal is emitted when HbDataFormViewItem corresponding to \a index is shown.
       
   152 
       
   153 */
       
   154 
       
   155 /*!
       
   156     Constructs DataForm with given \a parent.
       
   157     \param parent parent .
       
   158  */
       
   159 HbDataForm::HbDataForm(QGraphicsItem *parent)
       
   160     : HbAbstractItemView(*new HbDataFormPrivate(), new HbDataItemContainer(),
       
   161                          new HbTreeModelIterator(0, QModelIndex(), false), parent)
       
   162 {
       
   163     Q_D( HbDataForm );
       
   164     d->q_ptr = this;
       
   165     d->init();
       
   166     setVerticalScrollBarPolicy(ScrollBarAlwaysOff);
       
   167     //d->mHeadingWidget->createPrimitives();
       
   168     //static_cast<HbDataItemContainer*>(container())->setFormHeading(d->mHeadingWidget);
       
   169 }
       
   170 
       
   171 /*!
       
   172     Constructs a data form with a private class object \a dd, 
       
   173     \a container and \a parent.
       
   174 */
       
   175 HbDataForm::HbDataForm(HbDataFormPrivate &dd, HbAbstractItemContainer *container,
       
   176                        QGraphicsItem * parent)
       
   177         : HbAbstractItemView(dd, container, new HbTreeModelIterator(0, QModelIndex(), false), parent)
       
   178 {
       
   179     Q_D( HbDataForm );
       
   180     d->q_ptr = this;
       
   181     d->init();
       
   182 }
       
   183 
       
   184 /*!
       
   185     Destructs the data form.
       
   186 */
       
   187 HbDataForm::~HbDataForm()
       
   188 {
       
   189 }
       
   190 
       
   191 /*!
       
   192     \reimp
       
   193 
       
   194     Scrolls the view so that the item represented by \a index comes at the middle of 
       
   195     screen. By default HbDataForm does not scrolls. Application developer is supposed to 
       
   196     call this API if he wants this behaviour. User can connect to activated signal and then
       
   197     can call this API.
       
   198 */
       
   199 void HbDataForm::scrollTo(const QModelIndex &index, ScrollHint hint)
       
   200 {
       
   201     //Q_D(HbDataForm);
       
   202     //d->revealItem(d->mContainer->itemByIndex(index), PositionAtCenter);
       
   203     HbAbstractItemView::scrollTo(index, hint);
       
   204 }
       
   205 
       
   206 /*!
       
   207     \deprecated HbDataForm::indexCount() const
       
   208         is deprecated. Use \a HbModelIterator::indexCount() const
       
   209 
       
   210     \reimp
       
   211     Returns the number of children visible in the hierarchy. Children of collapsed parents are
       
   212     not taken into account.
       
   213 */
       
   214 int HbDataForm::indexCount() const
       
   215 {
       
   216     qWarning("HbDataForm::indexCount() is deprecated! Use HbModelIterator::indexCount() const.");
       
   217 
       
   218     Q_D(const HbDataForm);
       
   219     int bufferSize = 0;
       
   220     if (model()) {
       
   221         QModelIndex root = rootIndex();
       
   222         int rowCount = d->treeModelIterator()->childCount(root);
       
   223         for (int row = 0; row < rowCount; ++row) {
       
   224             bufferSize += d->childCount(d->treeModelIterator()->child(row, root));
       
   225         }
       
   226         bufferSize += rowCount;
       
   227     }
       
   228     return bufferSize;
       
   229 }
       
   230 
       
   231 /*!
       
   232     \deprecated HbDataForm::nextIndex(const QModelIndex&) const
       
   233         is deprecated. Use \a HbModelIterator::nextIndex(const QModelIndex&) const
       
   234 
       
   235     \reimp
       
   236 
       
   237     Next index for valid index is determined in following way:
       
   238 
       
   239     - If index has children and it is expanded then first child is returned
       
   240     - Otherwise if index has next sibling then that is returned
       
   241     - Otherwise next valid sibling for parent is returned
       
   242     - Otherwise QModelIndex is returned
       
   243 */
       
   244 QModelIndex HbDataForm::nextIndex(const QModelIndex &index) const
       
   245 {
       
   246     qWarning("HbDataForm::nextIndex(const QModelIndex&) const is deprecated! Use HbModelIterator::nextIndex(const QModelIndex&).");
       
   247 
       
   248     Q_D(const HbDataForm);
       
   249     if (index.isValid() && index.column() == 0) {
       
   250         QModelIndex result;
       
   251         if (isExpanded(index)) {
       
   252             result = index.child(0, 0);
       
   253         }
       
   254 
       
   255         if (!result.isValid()) {
       
   256             result = index.sibling(index.row() + 1, 0);
       
   257         }
       
   258 
       
   259         if (!result.isValid()) {
       
   260             QModelIndex parentIndex(index.parent());
       
   261             while (!result.isValid()) {
       
   262                 if (parentIndex == rootIndex()) {
       
   263                     break;
       
   264                 }
       
   265                 result = parentIndex.sibling(parentIndex.row() + 1, 0);
       
   266                 parentIndex = parentIndex.parent();
       
   267             }
       
   268         }
       
   269         return result;
       
   270     } else {
       
   271         return d->treeModelIterator()->child(0, rootIndex());
       
   272     }
       
   273 }
       
   274 
       
   275 
       
   276 /*!
       
   277     \deprecated HbDataForm::previousIndex(const QModelIndex&) const
       
   278         is deprecated. Use \a HbTreeModelIterator::previousIndex(const QModelIndex&) const
       
   279 
       
   280     \reimp
       
   281 
       
   282     Previous index for valid index is determined in following way:
       
   283 
       
   284     - If index has previous sibling last child from it is returned
       
   285     - Otherwise previous sibling is returned
       
   286     - Otherwise parent index is returned
       
   287     - Otherwise QModelIndex is returned
       
   288 */
       
   289 QModelIndex HbDataForm::previousIndex(const QModelIndex &index) const
       
   290 {
       
   291     qWarning("HbDataForm::previousIndex(const QModelIndex&) const is deprecated! Use HbModelIterator::previousIndex(const QModelIndex&) const.");
       
   292 
       
   293     Q_D(const HbDataForm);
       
   294     if (index.isValid() && index.column() == 0) {
       
   295         QModelIndex result(index.sibling(index.row() - 1, 0));
       
   296         if (result.isValid()) {
       
   297             bool checkChild = true;
       
   298             while (checkChild) {
       
   299                 if (isExpanded(result)) {
       
   300                     result = result.child(model()->rowCount(result) - 1, 0);
       
   301                 } else {
       
   302                     checkChild = false;
       
   303                 }
       
   304             }
       
   305         }
       
   306         if (!result.isValid()) {
       
   307             result = index.parent();
       
   308             if (result == rootIndex()) {
       
   309                 result = QModelIndex();
       
   310             }
       
   311         }
       
   312         return result;
       
   313     } else {
       
   314         QModelIndex result(
       
   315                 d->treeModelIterator()->child(
       
   316                         d->treeModelIterator()->childCount(rootIndex())-1,
       
   317                         rootIndex()));
       
   318         QModelIndex childIndex;
       
   319         bool checkChild = true;
       
   320         while (checkChild) {
       
   321             if (!isExpanded(result)) {
       
   322                 checkChild = false;
       
   323             } else {
       
   324                 childIndex = d->treeModelIterator()->child(d->treeModelIterator()->childCount(result) - 1, result);
       
   325                 if (childIndex.isValid()) {
       
   326                     result = childIndex;
       
   327                 }
       
   328             }
       
   329         }
       
   330         return result;
       
   331     }
       
   332 }
       
   333 
       
   334 /*!
       
   335     @beta
       
   336 
       
   337     Sets the item referred to by \a index to either collapse or expanded, 
       
   338     depending on the value of \a expanded. If \a expanded is true then child item are 
       
   339     supposed to be visible.
       
   340 
       
   341     \sa isExpanded
       
   342 */
       
   343 void HbDataForm::setExpanded(const QModelIndex &index, bool expanded)
       
   344 {
       
   345     Q_D(HbDataForm);
       
   346 
       
   347     if (isExpanded(index) != expanded) {
       
   348         d->treeModelIterator()->itemStateChanged(index, HbDataFormViewItem::ExpansionKey);
       
   349 
       
   350         HbDataFormViewItem *item =
       
   351             static_cast<HbDataFormViewItem *>(d->mContainer->itemByIndex(index));
       
   352         if (item) {
       
   353             item->setExpanded(expanded);
       
   354         }
       
   355 
       
   356         d->mContainer->setItemStateValue(index, HbDataFormViewItem::ExpansionKey, expanded);
       
   357         d->mContainer->setModelIndexes();
       
   358     }
       
   359 }
       
   360 
       
   361 /*!
       
   362     @beta
       
   363 
       
   364     Returns true if the model item \a index is expanded otherwise returns false.
       
   365 
       
   366     \sa setExpanded
       
   367 */
       
   368 bool HbDataForm::isExpanded(const QModelIndex &index) const
       
   369 {
       
   370     Q_D(const HbDataForm);
       
   371     QVariant flags = d->mContainer->itemState(index).value(HbDataFormViewItem::ExpansionKey);
       
   372     if (flags.isValid() && flags.toBool() == true) {
       
   373         return true;
       
   374     } else {
       
   375         return false;
       
   376     }
       
   377 }
       
   378 
       
   379 /*!
       
   380     @beta
       
   381 
       
   382     Sets the heading of HbDataForm with the \a heading provided. Heading is displayed on 
       
   383     top of the HbDataForm. Heading is non-focusable.
       
   384 
       
   385     \sa heading
       
   386 */
       
   387 void HbDataForm::setHeading(const QString &heading)
       
   388 {
       
   389     Q_D(HbDataForm);
       
   390 
       
   391     if(heading.isEmpty() && d->mHeadingWidget) {
       
   392         if(!d->mHeadingWidget->mPageCombo && d->mHeadingWidget->mDescription.isEmpty()) {
       
   393             // delete the FormheadingWidget
       
   394             delete d->mHeadingWidget;
       
   395             d->mHeadingWidget = 0;
       
   396             // Remove FormheadingWidget from container layout
       
   397             HbStyle::setItemName(d->mHeadingWidget,"NULL");
       
   398             return;
       
   399         }
       
   400     }
       
   401 
       
   402     if(!d->mHeadingWidget) {
       
   403         d->mHeadingWidget = new HbDataFormHeadingWidget();
       
   404         HbStyle::setItemName(d->mHeadingWidget,"this");
       
   405     }
       
   406     d->mHeadingWidget->mHeading = heading;
       
   407     d->mHeadingWidget->createPrimitives();
       
   408 
       
   409     if(d->mHeadingWidget->mPageCombo || !d->mHeadingWidget->mDescription.isEmpty() || 
       
   410         !d->mHeadingWidget->mHeading.isEmpty()) {
       
   411         static_cast<HbDataItemContainer*>(container())->setFormHeading(d->mHeadingWidget);
       
   412     }
       
   413     d->mHeadingWidget->callPolish();
       
   414 }
       
   415 
       
   416 /*!
       
   417     @beta
       
   418 
       
   419     Returns heading of HbDataForm.
       
   420 
       
   421     \sa setHeading    
       
   422 */
       
   423 QString HbDataForm::heading() const
       
   424 {
       
   425     Q_D(const HbDataForm);
       
   426     if(d->mHeadingWidget) {
       
   427         return d->mHeadingWidget->mHeading;
       
   428     }
       
   429 
       
   430     return QString();
       
   431 }
       
   432 
       
   433 /*!
       
   434     @beta
       
   435 
       
   436     Sets the description of HbDataForm with the \a description. Description is displayed 
       
   437     below heading. Description is non-focusable.
       
   438 
       
   439     \sa description
       
   440 */
       
   441 void HbDataForm::setDescription(const QString &description)
       
   442 {
       
   443     Q_D(HbDataForm);
       
   444 
       
   445     if(description.isEmpty() && d->mHeadingWidget) {
       
   446         if(!d->mHeadingWidget->mPageCombo && d->mHeadingWidget->mHeading.isEmpty()) {
       
   447             // delete the FormheadingWidget
       
   448             delete d->mHeadingWidget;
       
   449             d->mHeadingWidget = 0;
       
   450             // Remove FormheadingWidget from container layout
       
   451             HbStyle::setItemName(d->mHeadingWidget,"NULL");
       
   452             return;
       
   453         }
       
   454     }
       
   455 
       
   456     if(!d->mHeadingWidget) {
       
   457         d->mHeadingWidget = new HbDataFormHeadingWidget();
       
   458         HbStyle::setItemName(d->mHeadingWidget,"this");
       
   459     }
       
   460     d->mHeadingWidget->mDescription = description;
       
   461     d->mHeadingWidget->createPrimitives();
       
   462 
       
   463     if(d->mHeadingWidget->mPageCombo || !d->mHeadingWidget->mDescription.isEmpty() || 
       
   464         !d->mHeadingWidget->mHeading.isEmpty()) {
       
   465         static_cast<HbDataItemContainer*>(container())->setFormHeading(d->mHeadingWidget);
       
   466     }
       
   467     d->mHeadingWidget->callPolish();
       
   468 }
       
   469 
       
   470 /*!
       
   471     @beta
       
   472 
       
   473     Returns description of HbDataForm.
       
   474 
       
   475     \sa setDescription
       
   476 */
       
   477 QString HbDataForm::description() const
       
   478 {
       
   479     Q_D(const HbDataForm);
       
   480     if(d->mHeadingWidget) {
       
   481         return d->mHeadingWidget->mDescription;
       
   482     }
       
   483     return QString();
       
   484 }
       
   485 
       
   486 /*!
       
   487     \reimp
       
   488 
       
   489     Returns the style primitive of HbDataForm depending upon the type \a primitive.
       
   490     If primitive passed is P_DataForm_background then NULL is returned.
       
   491     User cannot customize background of data form.
       
   492 
       
   493     \sa primitive
       
   494 */
       
   495 QGraphicsItem* HbDataForm::primitive(HbStyle::Primitive primitive) const
       
   496 {
       
   497     Q_D(const HbDataForm);
       
   498 
       
   499     switch (primitive) {
       
   500         case HbStyle::P_DataForm_heading:
       
   501             return d->mHeadingWidget->mHeadingItem;
       
   502         case HbStyle::P_DataForm_description:
       
   503             return d->mHeadingWidget->mDescriptionItem;
       
   504         default:
       
   505             return 0;
       
   506     }
       
   507 }
       
   508 
       
   509 /*!
       
   510     
       
   511     \deprecated HbDataForm::dataFormViewItem(const QModelIndex &index) const
       
   512         is deprecated. Please use HbAbstractItemView::itemByIndex instead.
       
   513 
       
   514     Returns HbDataFormViewItem for the correspoding \a index passed. Returns
       
   515     NULL is index passed is invalid. If \a index passed is not visible then NULL is returned.
       
   516     Ideally user should call this API when activate is called for \a index.    
       
   517 
       
   518 */
       
   519 HbDataFormViewItem* HbDataForm::dataFormViewItem(const QModelIndex &index) const
       
   520 {
       
   521     Q_D(const HbDataForm);
       
   522     if(index.isValid()) {
       
   523         return static_cast<HbDataFormViewItem*>(d->mContainer->itemByIndex(index));
       
   524     } else {
       
   525         return 0;
       
   526     }
       
   527 }
       
   528 
       
   529 
       
   530 /*!
       
   531     \reimp
       
   532 
       
   533     If \a model passed is NULL then all values of data form are reset. Calls the
       
   534     setModel of base class. This API does not clears the heading and description set
       
   535     for HbDataForm. If with new \a model user does not wants heading and description
       
   536     then he should call setHeading and setDescription with empty string.
       
   537 
       
   538     \sa setHeading, setDescription
       
   539 */
       
   540 void HbDataForm::setModel(QAbstractItemModel *model, HbAbstractViewItem *prototype)
       
   541 {
       
   542     Q_D(HbDataForm);
       
   543     if(d->mHeadingWidget) {
       
   544         if(model) {
       
   545             d->mHeadingWidget->mActivePage = -1;
       
   546         }
       
   547         if(d->mHeadingWidget->mPageCombo) {
       
   548             delete d->mHeadingWidget->mPageCombo;
       
   549             d->mHeadingWidget->mPageCombo = 0;
       
   550         }
       
   551     }
       
   552     HbAbstractItemView::setModel(model, prototype);
       
   553 }
       
   554 
       
   555 /*!
       
   556     \deprecated HbDataForm::loadSettings() 
       
   557         is deprecated. Please use HbDataFormViewItem::restore API instead..
       
   558                 
       
   559     Updates the values on each HbDataItem's stored in central repository.
       
   560     This function will be invoked when DataForm is shown .
       
   561 
       
   562     \sa storeSettings 
       
   563 */
       
   564 void HbDataForm::loadSettings()
       
   565 {
       
   566     //Q_D(HbDataForm);
       
   567 
       
   568     /*QList<HbAbstractViewItem *> items = d->mContainer->items();
       
   569     foreach(HbAbstractViewItem* item, items) {
       
   570         static_cast<HbDataFormViewItem*>(item)->load();
       
   571     }*/
       
   572 }
       
   573 
       
   574 /*!
       
   575      \deprecated HbDataForm::storeSettings() 
       
   576         is deprecated. Please use HbDataFormViewItem::save instead.
       
   577 
       
   578     Stores the values of each HbDataItem's in to the repository. This function invoked 
       
   579     when DataForm is exited.
       
   580 
       
   581     \sa loadSettings 
       
   582 */
       
   583 void HbDataForm::storeSettings()
       
   584 {
       
   585     Q_D(HbDataForm);
       
   586 
       
   587     QList<HbAbstractViewItem *> items = d->mContainer->items();
       
   588     foreach(HbAbstractViewItem* item, items) {
       
   589         static_cast<HbDataFormViewItem*>(item)->store();
       
   590     }
       
   591 
       
   592 }
       
   593 /*!
       
   594     \reimp
       
   595 */
       
   596 
       
   597 void HbDataForm::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
       
   598 {
       
   599     Q_UNUSED(bottomRight);
       
   600     if(topLeft.isValid()) {       
       
   601             HbDataFormViewItem* item = static_cast<HbDataFormViewItem*>(dataFormViewItem(topLeft));
       
   602             if(item){
       
   603                 item->load();
       
   604                 HbDataFormModelItem *modelItem = 
       
   605                         static_cast<HbDataFormModel *>(model())->itemFromIndex(topLeft);
       
   606                 HbDataFormViewItemPrivate::d_ptr(item)->setEnabled( modelItem->isEnabled() );          
       
   607             }
       
   608     }
       
   609 }
       
   610 /*!
       
   611     \reimp
       
   612 
       
   613     Initializes \a option with the values from HbDataForm.
       
   614 */
       
   615 void HbDataForm::initStyleOption(HbStyleOptionDataForm *option)
       
   616 {
       
   617     Q_D(HbDataForm);
       
   618     d->mHeadingWidget->initStyleOption(option);
       
   619 }
       
   620 
       
   621 /*!
       
   622     \reimp
       
   623 */
       
   624 void HbDataForm::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   625 {
       
   626     Q_D(HbDataForm);
       
   627     HbDataFormViewItem *hitItem = qobject_cast<HbDataFormViewItem*>(d->itemAt(event->scenePos()));
       
   628 
       
   629     if ( d->mHitItem
       
   630         && d->mHitItem == hitItem 
       
   631         && !d->mWasScrolling ) {
       
   632             hitItem->setExpanded(!hitItem->isExpanded());
       
   633             d->mInstantClickedModifiers |= Hb::ModifierExpandedItem;
       
   634     }
       
   635     HbAbstractItemView::mouseReleaseEvent( event );
       
   636 }
       
   637 
       
   638 /*!
       
   639     \reimp
       
   640 */
       
   641 void HbDataForm::rowsInserted(const QModelIndex &parent, int start, int end)
       
   642 {
       
   643     Q_D(HbDataForm);
       
   644     HbAbstractItemView::rowsInserted(parent, start, end);
       
   645     HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>(
       
   646         parent.data(HbDataFormModelItem::ItemTypeRole).toInt());
       
   647     if(itemType == HbDataFormModelItem::GroupItem ||
       
   648         itemType == HbDataFormModelItem::GroupPageItem ||
       
   649         itemType == HbDataFormModelItem::FormPageItem ) {
       
   650         HbDataGroup *item = static_cast<HbDataGroup*>(itemByIndex(parent));
       
   651         if((item && item->isExpanded()) || parent == d->mModelIterator->rootIndex()) {
       
   652             container()->setModelIndexes(parent);
       
   653         }
       
   654         
       
   655     }else {
       
   656         container()->setModelIndexes();
       
   657     }
       
   658 }
       
   659 
       
   660 /*!
       
   661     \reimp
       
   662 */
       
   663 void HbDataForm::rowsAboutToBeRemoved(const QModelIndex &index, int start, int end)
       
   664 {
       
   665    Q_D(HbDataForm);
       
   666 
       
   667      for(int i = start; i <= end; i++) {
       
   668 
       
   669         QModelIndex childIndex = model()->index(i,0,index);
       
   670         // HbDataFormViewItem* view_Item =  static_cast<HbDataFormViewItem*>(itemByIndex(childIndex));
       
   671         QModelIndex siblingIndex = model()->index(i+1,0,index);
       
   672         HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>(
       
   673         childIndex.data(HbDataFormModelItem::ItemTypeRole).toInt());
       
   674         QString label = childIndex.data(HbDataFormModelItem::LabelRole).toString();        
       
   675 
       
   676         if(itemType == HbDataFormModelItem::FormPageItem) {
       
   677             d->removeFormPage(label);            
       
   678         }
       
   679 
       
   680         if(itemType == HbDataFormModelItem::GroupPageItem) {
       
   681             QModelIndex group = childIndex.parent();
       
   682             HbDataGroup* groupItem = static_cast<HbDataGroup*>(itemByIndex(group));
       
   683             if(groupItem) {
       
   684                 HbDataGroupPrivate::d_ptr(groupItem)->removeGroupPage(label);                
       
   685             }           
       
   686         }        
       
   687      }
       
   688 }
       
   689 
       
   690 /*!
       
   691     @alpha 
       
   692 
       
   693     This API can be used to connect with the signal of HbDataFormViewItem's content widget.
       
   694     For example: If HbDataFormModelItem is of type DataItemType::SliderItem then user
       
   695     can connect to the signals of slider using this API.
       
   696     Example Usage:
       
   697     \code
       
   698     HbDataForm *form = new HbDataForm();
       
   699     HbDataFormModel *model = new HbDataFormModel();
       
   700     HbDataFormModelItem *sliderItem = model->appendDataFormItem(HbDataFormModelItem::SliderItem);
       
   701     form->addConnection(sliderItem, SIGNAL(sliderReleased()), 
       
   702         this, SLOT(volumeChanged()));
       
   703     \endcode
       
   704 
       
   705     \param item Instance of model item 
       
   706     \param signal Signal of content widget. 
       
   707     \param receiver Instance of object whose slot will be called 
       
   708     \param slot Slot of \a receiver which will get called when signal is emitted
       
   709  
       
   710     \sa removeConnection 
       
   711 */
       
   712 void HbDataForm::addConnection(HbDataFormModelItem * item, 
       
   713                                const char* signal, 
       
   714                                QObject *receiver, 
       
   715                                const char* slot)
       
   716 {   
       
   717     Q_D(HbDataForm);
       
   718     ItemSignal itemSignal;
       
   719     itemSignal.reciever = receiver;
       
   720     itemSignal.signal = signal;
       
   721     itemSignal.slot = slot;
       
   722     d->mConnectionList.insertMulti(item, itemSignal);
       
   723     d->connectNow(item, signal, receiver, slot);
       
   724 }
       
   725 
       
   726 /*!
       
   727     @alpha
       
   728 
       
   729     This API can be used to remove the signal connection which was established using the
       
   730     addConnection API.
       
   731 
       
   732     \sa addConnection 
       
   733 */
       
   734 void HbDataForm::removeConnection(HbDataFormModelItem * item, 
       
   735                                   const char* signal, 
       
   736                                   QObject *receiver, 
       
   737                                   const char* slot)
       
   738 {   
       
   739     Q_D(HbDataForm);
       
   740     d->removeConnection(item, signal, receiver, slot);
       
   741 }
       
   742 
       
   743 /*!
       
   744     @alpha
       
   745 
       
   746     Removes the connection of all the contentwidget of all the items which has been established .
       
   747     The connection information stored inside DataForm also cleared.
       
   748 
       
   749     \sa removeAllConnection 
       
   750 */
       
   751 void HbDataForm::removeAllConnection()
       
   752 {   
       
   753     Q_D(HbDataForm);
       
   754     d->removeAllConnection();
       
   755 }
       
   756 
       
   757 /*!
       
   758     @alpha
       
   759 
       
   760     Removes the all connections of the contentwidget of HbDataFormModelItem's corresponding 
       
   761     visual Item ( HbdataFormViewItem).The connection information of correspoding 
       
   762     HbDataFormModelItem stored inside DataForm also cleared.
       
   763 
       
   764     \sa removeAllConnection 
       
   765 */
       
   766 void HbDataForm::removeAllConnection(HbDataFormModelItem *item)
       
   767 {   
       
   768     Q_D(HbDataForm);
       
   769     d->removeAllConnection(item);
       
   770 }
       
   771 
       
   772 #include "moc_hbdataform.cpp"
       
   773 
       
   774