src/hbwidgets/dataform/hbdataform.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    37 #include <hbdataformmodel.h>
    37 #include <hbdataformmodel.h>
    38 #include <hbcombobox.h>
    38 #include <hbcombobox.h>
    39 
    39 
    40 #include <QGraphicsSceneMouseEvent>
    40 #include <QGraphicsSceneMouseEvent>
    41 #include <QCoreApplication>
    41 #include <QCoreApplication>
    42 
    42 #include <QGraphicsScene>
       
    43 #include <QGestureRecognizer>
       
    44 
       
    45 #include <hbgesturerecognizers_p.h>
       
    46 #include <hbgestures_p.h>
       
    47 
       
    48 class HbTapDelayGesture:public HbTapGesture
       
    49 {
       
    50 public:
       
    51     using HbTapGesture::d_ptr;
       
    52     
       
    53     Q_DECLARE_PRIVATE_D(d_ptr, HbTapGesture)
       
    54 };
       
    55 class HbTapDelayGestureRecognizer : public HbTapGestureRecognizer
       
    56 {
       
    57 public:
       
    58     explicit HbTapDelayGestureRecognizer(){}
       
    59     virtual ~HbTapDelayGestureRecognizer()
       
    60     {
       
    61         int i = 0;
       
    62         i++;
       
    63     };
       
    64 
       
    65     QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event)
       
    66     {
       
    67         HbTapDelayGesture* gesture = static_cast<HbTapDelayGesture *>(state);
       
    68         QMouseEvent* me = toMouseEvent(event);
       
    69         Qt::GestureState gestureState = state->state();
       
    70         switch(event->type())
       
    71         {
       
    72         case QEvent::MouseButtonDblClick:
       
    73         case QEvent::MouseButtonPress:
       
    74             if ( state->state() == Qt::NoGesture && me->button() == Qt::LeftButton){
       
    75                 
       
    76                 gesture->setPosition(me->globalPos());
       
    77                 gesture->setHotSpot(me->globalPos());
       
    78                 gesture->setStartPos(me->globalPos());
       
    79                 gesture->setScenePosition(HbGestureUtils::mapToScene(watched, me->globalPos()));
       
    80                 gesture->setSceneStartPos(HbGestureUtils::mapToScene(watched, me->globalPos()));
       
    81                 mTapRadius = (int)(HbDefaultTapRadius * HbDeviceProfile::current().ppmValue());        
       
    82 
       
    83                 HbTapGesturePrivate* d_ptr = gesture->d_func();
       
    84                 d_ptr->mTapStyleHint = HbTapGesture::Tap;
       
    85                 if ( d_ptr->mTimerId ) {
       
    86                     gesture->killTimer(d_ptr->mTimerId);
       
    87                 }
       
    88                 d_ptr->mTimerId = gesture->startTimer(50);
       
    89                 return QGestureRecognizer::MayBeGesture;
       
    90                 
       
    91             }
       
    92             else {
       
    93                 return QGestureRecognizer::Ignore;
       
    94             }
       
    95     
       
    96 
       
    97         case QEvent::MouseMove:
       
    98             if(gestureState != Qt::NoGesture && gestureState != Qt::GestureCanceled) { 
       
    99                 return handleMouseMove(gestureState, gesture, watched, toMouseEvent(event));
       
   100             }
       
   101             else{
       
   102                 if (gesture->d_func()->mTimerId) {
       
   103                     gesture->setPosition(me->globalPos());
       
   104                     gesture->setScenePosition(HbGestureUtils::mapToScene(watched, me->globalPos()));
       
   105                     gesture->setHotSpot(me->globalPos());
       
   106 
       
   107                     int tapRadiusSquare(mTapRadius * mTapRadius);
       
   108                     if(gesture->property(HbPrivate::TapRadius.latin1()).isValid()) {
       
   109                         qWarning("WARNING using widget specific properties in HbTapGestureRecognizer");
       
   110                         int tapRadius = gesture->property(HbPrivate::TapRadius.latin1()).toInt();
       
   111                         tapRadiusSquare = tapRadius * tapRadius;
       
   112                     }
       
   113                     QPointF delta = me->globalPos() - gesture->startPos();
       
   114 
       
   115                      // cancel long press with radius
       
   116                     if((delta.x() * delta.x() + delta.y() * delta.y()) > tapRadiusSquare) {                
       
   117                         gesture->killTimer(gesture->d_func()->mTimerId);
       
   118                         gesture->d_func()->mTimerId = 0;
       
   119                     }
       
   120 
       
   121                 }
       
   122                 return QGestureRecognizer::Ignore;
       
   123             }
       
   124 
       
   125         case QEvent::MouseButtonRelease:
       
   126             if(gestureState != Qt::NoGesture) {
       
   127                 return handleMouseRelease(gestureState, gesture, watched, toMouseEvent(event));
       
   128             }
       
   129             else{
       
   130                 
       
   131                 if (gesture->d_func()->mTimerId) {
       
   132                     gesture->killTimer(gesture->d_func()->mTimerId);
       
   133                     gesture->d_func()->mTimerId = 0;
       
   134                     return QGestureRecognizer::FinishGesture;
       
   135                 } else {
       
   136                     return QGestureRecognizer::Ignore;
       
   137                 }
       
   138             }
       
   139 
       
   140         case QEvent::Timer:
       
   141             {
       
   142             QGestureRecognizer::Result result;
       
   143             gesture->killTimer(gesture->d_func()->mTimerId);
       
   144             gesture->d_func()->mTimerId = 0;
       
   145             if(gestureState == Qt::NoGesture) {
       
   146                 result = QGestureRecognizer::TriggerGesture;        
       
   147                 gesture->d_func()->mTimerId = gesture->startTimer(HbTapAndHoldTimeout);
       
   148               
       
   149             } 
       
   150             else {
       
   151                 result = handleTimerEvent(gesture->state(),gesture,watched);
       
   152             }
       
   153 
       
   154             return result;
       
   155             }
       
   156         case QEvent::TouchBegin:
       
   157         case QEvent::TouchUpdate:        
       
   158             return HbTapGestureRecognizer::recognize(state, watched, event);
       
   159 
       
   160         default: break;
       
   161         }
       
   162 
       
   163         return QGestureRecognizer::Ignore;
       
   164 
       
   165     }
       
   166 };
       
   167 
       
   168 class DelayGestureInstaller
       
   169 {
       
   170 public:
       
   171     DelayGestureInstaller():count(0){}
       
   172     void install()
       
   173     {
       
   174         if(count <=0){
       
   175             QGestureRecognizer::unregisterRecognizer(Qt::TapGesture);
       
   176             QGestureRecognizer::registerRecognizer(new HbTapDelayGestureRecognizer);
       
   177             
       
   178         }
       
   179         count++;
       
   180     }
       
   181     void unInstall()
       
   182     {
       
   183         count--;
       
   184         if(count <1){
       
   185             QGestureRecognizer::unregisterRecognizer(Qt::TapGesture);
       
   186             QGestureRecognizer::registerRecognizer(new HbTapGestureRecognizer);
       
   187         }
       
   188     }
       
   189     int count;
       
   190 };
       
   191 static DelayGestureInstaller delayGestureInstaller;
    43 /*!
   192 /*!
    44     @beta
   193     @beta
    45     @hbwidgets
   194     @hbwidgets
    46     \class HbDataForm
   195     \class HbDataForm
    47     \brief HbDataForm represents hierarchical dataitems in form of form pages, groups, group pages
   196 
    48     and data items.
   197     \brief The HbDataForm class is for showing and entering data in 
    49     HbDataForm implements a hierarchical representation of view items for each model items from 
   198     hierarchically organized pages and groups of a form.
    50     HbDataFormModel.
   199 
    51 
   200     A data form contains data items for showing and entering data in an 
    52     HbDataForm implements the interfaces defined by the HbAbstractItemView class to allow 
   201     application. Each data item shown in a data form can contain an input widget 
    53     it to display data provided by models which are derived from QAbstractItemModel class.
   202     and an optional text label. Text fields, sliders and check boxes are typical 
    54 
   203     widgets used to show and collect data in an application. If a complex data 
    55     It is simple to construct a dataform displaying data from a model. The user has to create
   204     form contains many data items a user may be required to scroll the data form 
    56     HbDataFormModel and create the hierarchy of HbDataFormModelItems.The hierarchy is 
   205     content. To reduce the need to scroll, the data items can be organised into 
    57     similar to the following.
   206     elements whose hierarchy is the following:
    58     
   207     -  %Data form
    59     - HbDataForm
   208       - Form pages
    60        - HbDataFormPage1
   209         - Groups
    61          - HbDataGroup1
   210           - Group pages
    62            - HbDataGroupPage1
   211 
    63              - HbDataItem
   212     The data form uses a model-view architecture. HbDataFormModel represents the 
    64              - HbDataItem
   213     data model for the form. You add HbDataFormModelItem objects (i.e. form 
    65              - HbDataItem
   214     pages, groups, group pages and data items) to a data form model by creating 
    66              - HbDataItem
   215     a HbDataFormModel object and adding HbDataFormModelItem objects to it. You 
    67        - HbDataFormPage2
   216     can then create a data form widget to show the data by creating an 
    68          - HbDataGroup2
   217     HbDataForm object and setting its data form model. The model-view 
    69            - HbDataGroupPage2
   218     architecture ensures that the content of the data form view is updated as 
    70              - HbDataItem
   219     the data form model changes.
    71              - HbDataItem
   220 
    72              - HbDataItem
   221     The important thing to note is that you do not create data form widgets 
    73              - HbDataItem
   222     directly in your data form. The HbDataForm object creates the appropriate UI 
    74        - HbDataGroup3
   223     widget type for each data item in your data form model. You must specify the 
    75           - HbDataItem
   224     type of widget that is shown in the data form when you create your data form 
    76           - HbDataItem
   225     model.
    77           - HbDataItem
   226 
    78        - HbDataItem
   227     HbDataForm implements the interface defined by the HbAbstractItemView class 
    79        - HbDataItem
   228     to display the data provided by the data form model. This model is derived 
    80  
   229     from the QAbstractItemModel class. To construct a data form for displaying 
    81     HbDataItem can be the child of HbDataForm, HbDataFormPage, HbDataGroup and 
   230     the data from a data form model, create HbDataFormModel and the hierarchy of 
    82     HbDataGroupPage. An instance of HbDataForm has to be created and model should be set 
   231     HbDataFormModelItem objects. The following rules apply in the hierarchy:
    83     to the form using setModel( ) API.
   232     - A form page can be a child of the data form only.
    84     The properties of each data item node can be set using HbDataFormModelItem convenient
   233     - A group can be a child of the data form or a form page.
    85     API's like setContentWidgetData( ). These model data are parsed and set while the visualization 
   234     - A group page can be a child of a group only.
    86     instance of each item is created.
   235     - A data item can be the child of data form, form page, group, and group page.
    87 
   236 
    88     The model/view architecture ensures that the view contents are updated as and when the data in
   237     The hierarchy can be for example the following:
    89     model changes.
   238     
    90 
   239     - %Data form
    91     Only model items that can have children can be in expanded (childrens are visible) or 
   240        - Form page 1
    92     collapsed (childrens are hidden) state. Model items of type HbDataFormModelItem::FormPageItem,
   241          - Group 1
    93     HbDataFormModelItem::GroupItem and HbDataFormModelItem::GroupPageItem can be expanded 
   242            - Group page 1
    94     or collapsed. Which in turn means that these types of model item can only have children. 
   243              - %Data item 1
    95     Each item in model is represented by either an instance of HbDataFormViewItem or classes which 
   244              - %Data item 2
    96     are derived from HbDataFormViewItem. HbDataFormViewItem can be subclassed for
   245              - %Data item 3
       
   246        - %Data item 4
       
   247        - Form page 2
       
   248          - %Data item 5
       
   249          - Group 2
       
   250            - %Data item 6
       
   251            - Group page 2
       
   252              - %Data item 7
       
   253              - %Data item 8
       
   254        - Group 3
       
   255          - %Data item 9
       
   256 
       
   257     To build the structure create first the HbDataForm object and set the model 
       
   258     to the form with the setModel() method. Set properties of each data item 
       
   259     with methods of HbDataFormModelItem class. The data is parsed when the 
       
   260     visualization instance of each item is created and set on each item.
       
   261 
       
   262     Items which have children (i.e. form pages, groups, and group pages) can be 
       
   263     in expanded (i.e. children are visible) or collapsed (i.e. children are 
       
   264     hidden) state. Each item in data form model is represented by an 
       
   265     HbDataFormViewItem object. HbDataForm uses HbDataFormViewItem prototype to 
       
   266     instantiate the data form items. HbDataFormViewItem can be subclassed for 
    97     customization purposes.
   267     customization purposes.
    98     
   268 
    99     The Model hierarchy can be created using the convenient API's provided in model class like
   269     The signals emitted by HbDataForm are the following:
   100     appendDataFormPage(), appendDataFormGroup(), appendDataFormGroupPage() and 
   270     \li itemShown(const QModelIndex &index) signal is emitted when the 
   101     appendDataFormItem(). All these API's return HbDataFormModelItem instance corresponding 
   271     HbDataFormViewItem corresponding to \a index is shown. You can connect to 
   102     to each HbDataFormModelItem::DataItemType type on which user can set item 
   272     this signal and fetch the instance of HbDataFormViewItem from HbDataForm 
   103     specific(content widget) data. Otherwise each HbDataFormModelItem can be created individually
   273     with HbAbstractItemView::itemByIndex().
   104     by passing the corresponding type of item (GroupItem, GroupPageItem, FormPageItem) and create
   274     \li dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) 
   105     the tree of HbDataFormModelItem using setParent API or by passing the parent 
   275     signal is emitted when the HbDataFormModel is updated \a topLeft and \a 
   106     HbDataFormModelItem in constructor. Later the top level HbDataFormModelItem can be added in 
   276     bottomRight will be same since every node has only one column. You can 
   107     model.
   277     connect to this signal and fetch the instance of
   108 
   278     - HbDataFormViewItem from HbDataForm with HbAbstractItemView::itemByIndex() or
   109     After setting model in HbDataForm using setModel(), the visualization gets created.
   279     - HbDataFormModelItem with HbDataFormModel::itemFromIndex(). HbDataForm 
   110     Only the items inside the expanded form page, group or group page are created. When an item's
   280     takes care of updating the corresponding the visualization of item when you 
   111     visualization is created, HbDataForm emits itemShown(constQModelIndex&) signal. The application 
   281     update the model with HbDataFormModelItem::setContentWidgetData().
   112     can connect to this signal and when corresponding slot is called then application can get
   282 
   113     HbDataFormViewItem instance and even content widget instance. Use HbAbstractItemView::itemByIndex()
   283     You can also provide the connection information to the corresponding content 
   114     to get HbDataFormViewItem instance. Use HbDataFormViewItem::dataItemContentWidget() to get
   284     widget of each HbDataFormModelItem with the \link HbDataForm::addConnection(HbDataFormModelItem * item, const char* signal, QObject *receiver, const char* slot) HbDataForm::addConnection()\endlink 
   115     content widget instance.
   285     method. The connection is established when the item visualization is 
   116     
   286     created. You can use \link HbDataForm::removeConnection(HbDataFormModelItem *item, const char* signal, QObject *receiver, const char* slot) HbDataForm::removeConnection()\endlink and HbDataForm::removeAllConnection() 
   117     The signals emitted by HbDataForm
   287     methods in the same way. You can establish and remove the connection also at 
   118     \li itemShown(const QModelIndex &index) Emitted when the HbDataFormViewItem corresponding to
   288     runtime.
   119     \a index is shown. User can connect to this signal and can fetch the instance of 
   289 
   120     HbDataFormViewItem from HbDataForm using the API dataFormViewItem(const QModelIndex &index).
   290     \sa HbDataFormViewItem, HbDataFormModel, and HbDataFormModelItem
   121     This signal is only emitted for model items of type greater than HbDataFormModelItem::GroupPageItem
   291     
   122 
   292     \section _usecases_hbdataform Using the HbDataForm class
   123     The user can also provide connection information to correspoding content widget of each 
   293     
   124     HbDataFormModelItem using API 
   294     \subsection _uc_hbdataform_001 Creating a data form.
   125     addConnection(HbDataFormModelItem* item, const char* signal, QObject* receiver, const char* slot)
   295     
   126     provided in HbDataForm. The connection will be established when the item visualization is created.
   296     The following example shows how to create a data form. The code
   127     Using addConnection() API user can also connect to hbdialog's signals(for ex: aboutToClose) in case 
   297     - creates the data form and data form model
   128     of popup items like radio button list item and multi selection list item. Below code snippet demonstrates
   298     - adds the data form model items (i.e. groups, group pages, and data items)
   129     the same:
   299     - sets the model to the view
   130 
   300     
   131     \code
   301     
   132     HbDataFormModelItem *days = model->appendDataFormItem(HbDataFormModelItem::MultiselectionItem,
   302     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,31}
   133                                     QString("Days"), themeGeneral);
   303     
   134     QStringList multiItems;
   304     The code creates the following structure:
   135     multiItems<<"Sunday"<<"Monday"<<"Tuesday"<<"Wednesday"<<"Thursday"<<"Friday";
   305     - Group 1                              - group
   136     days->setContentWidgetData(QString("items"), multiItems);
   306       - %Data Item 1  (check box)              - data item
   137     QList<QVariant> selected;
   307         - Check box added to group            - text property of the data item
   138     selected<<2<<3;
   308       - %Data Item 2 (text item)              - data item
   139     days->setContentWidgetData(QString("selectedItems"), selected);
   309         - Text Item added to group            - text property of the data item
   140     days->setContentWidgetData(QString("items"), multiItems);
   310     - %Data Item 3  (combo box)              - data item
   141     form->addConnection(days, SIGNAL(aboutToShow()), this, SLOT(aboutToShow()));
   311     - Profile                              - group
   142     form->addConnection(days, SIGNAL(aboutToHide()()), this, SLOT(aboutToHide()()));
   312       - Silent                              - group page
   143     form->addConnection(days, SIGNAL(aboutToClose()), this, SLOT(aboutToClose()));
   313         - Slider                              - data item
   144     form->addConnection(days, SIGNAL(finished(HbAction*)), this, SLOT(finished(HbAction*)));
   314       - General                              - group page
   145 
   315       - Meeting                              - group page
   146     \endcode
   316         
   147 
   317     The generated data form is the following:
   148     Similar way 
   318 
   149     removeConnection(HbDataFormModelItem *item, const char* signal, QObject *receiver, const char* slot)
   319     \image html hbsettingform.png
   150     and removeAllConnection() API can be used. Connection can be established or removed even at runtime.
   320 
   151     An example of how to make connection and setting the content widget property:
   321     The picture below shows the generated data form in the landscape mode.
   152 
   322 
       
   323     \image html hbsettingform_landscape.png
       
   324 
       
   325      \subsection _uc_hbdataform_002 Connecting the "sliderReleased" signal to the "volumeChanged" slot.
       
   326 
       
   327     In the following example the content widget is a slider whose 
       
   328     "sliderReleased"  \a signal is connected to the "volumeChanged" slot which 
       
   329     handles the changed volume.
       
   330     
   153     \code
   331     \code
   154     HbDataForm *form = new HbDataForm();
   332     HbDataForm *form = new HbDataForm();
   155     model = new HbDataFormModel();
   333     model = new HbDataFormModel();
   156 
   334 
   157     HbDataFormModelItem *sliderItem = 
   335     HbDataFormModelItem *sliderItem = 
   164     form->addConnection(sliderItem, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
   342     form->addConnection(sliderItem, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
   165 
   343 
   166     form->setModel(model);
   344     form->setModel(model);
   167     setWidget(form);
   345     setWidget(form);
   168     \endcode
   346     \endcode
   169     
   347 
   170     An example of how to create HbDataForm:
   348      \subsection _uc_hbdataform_003 Creating the model hierarchy.
   171     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,31}
   349 
   172 
   350     You can create the model hierarchy with the \link 
   173     The output generated by the above code looks like:
   351     HbDataFormModel::appendDataFormPage() appendDataFormPage()\endlink, \link 
   174 
   352     HbDataFormModel::appendDataFormGroup() appendDataFormGroup()\endlink, \link 
   175     \image html hbsettingform.png
   353     HbDataFormModel::appendDataFormGroupPage() 
   176 
   354     appendDataFormGroupPage()\endlink, and \link 
   177     This is how HbDataForm will look like in landscape mode:
   355     HbDataFormModel::appendDataFormItem() appendDataFormItem()\endlink methods 
   178 
   356     of the HbDataFormModel class. All of these methods will return 
   179     \image html hbsettingform_landscape.png
   357     HbDataFormModelItem object corresponding to each type in which the user can 
   180 
   358     set item specific data. 
   181     \sa HbDataFormViewItem, HbDataFormModel, HbDataFormModelItem
   359     
   182 
   360     After running the setModel method the visualization is created . The items 
   183     Creating Custom Item:
   361     of expanded groups and group pages are created. The data form emits the 
   184 
   362     itemShown(const QModelIndex &index) signal when an the  visualization of 
   185     Application developer can create custom DataItem by deriving from HbDataFormViewItem and setting this as 
   363     item is created. The application can get HbDataFormViewItem and content 
   186     prototype using setItemProtoType() API. Application has to override virtual API's createCustomWidget(),
   364     widget from HbDataForm using QModelIndex.
   187     restore()and save(). createCustomWidget() API should return the corresponding custom HbWidget which
   365 */
   188     can also be a compound widget. Signal connection for child widgets inside the compound widget should
   366 
   189     be taken care by the application. restore() API will be called by the framework when the model data 
   367 /*!
   190     is changed. So restore() should take care of updating the visual items with correspoding data from model. 
   368     \fn void HbDataForm::itemShown(const QModelIndex &index)
   191     save() API should update the model. App developer should connect respective widgets SIGNALs to SLOT save() 
   369 
   192     and update the data to model .
   370     This signal is emitted when HbDataFormViewItem corresponding to \a index is 
   193 
   371     shown.
   194 */
   372 
   195 
   373 */
   196 /*!
   374 
   197     \fn void HbAbstractItemView::itemShown(const QModelIndex &index)
   375 /*!
   198 
   376     Constructs a data form with the given \a parent.
   199     This signal is emitted when HbDataFormViewItem corresponding to \a index is shown.
       
   200 
       
   201 */
       
   202 
       
   203 /*!
       
   204     Constructs DataForm with given \a parent.
       
   205     \param parent parent .
       
   206  */
   377  */
   207 HbDataForm::HbDataForm(QGraphicsItem *parent)
   378 HbDataForm::HbDataForm(QGraphicsItem *parent)
   208     : HbAbstractItemView(*new HbDataFormPrivate(), new HbDataItemContainer(),
   379     : HbAbstractItemView(*new HbDataFormPrivate(), new HbDataItemContainer(),
   209                          new HbTreeModelIterator(0, QModelIndex(), false), parent)
   380                          new HbTreeModelIterator(0, QModelIndex(), false), parent)
   210 {
   381 {
   211     Q_D( HbDataForm );
   382     Q_D( HbDataForm );
   212     d->q_ptr = this;
   383     d->q_ptr = this;
   213     d->init();
   384     d->init();
   214     setVerticalScrollBarPolicy(ScrollBarAlwaysOff);
   385     //setVerticalScrollBarPolicy(ScrollBarAlwaysOff);
   215 }
   386 }
   216 
   387 
   217 /*!
   388 /*!
   218     Constructs a data form with a private class object \a dd, 
   389     Constructs a data form with the given private class object \a dd, 
   219     \a container and \a parent.
   390     \a container and \a parent.
   220 */
   391 */
   221 HbDataForm::HbDataForm(HbDataFormPrivate &dd, HbAbstractItemContainer *container,
   392 HbDataForm::HbDataForm(HbDataFormPrivate &dd, HbAbstractItemContainer *container,
   222                        QGraphicsItem * parent)
   393                        QGraphicsItem * parent)
   223         : HbAbstractItemView(dd, container, new HbTreeModelIterator(0, QModelIndex(), false), parent)
   394         : HbAbstractItemView(dd, container, new HbTreeModelIterator(0, QModelIndex(), false), parent)
   226     d->q_ptr = this;
   397     d->q_ptr = this;
   227     d->init();
   398     d->init();
   228 }
   399 }
   229 
   400 
   230 /*!
   401 /*!
   231     Destructs the data form.
   402     Destructor.
   232 */
   403 */
   233 HbDataForm::~HbDataForm()
   404 HbDataForm::~HbDataForm()
   234 {
   405 {
   235 }
   406 }
   236 
   407 
   237 /*!
   408 /*! Scrolls the view so that the data form item of given \a index is shown at 
   238     \reimp
   409 the given \a hint position of the screen. By default the data form does not 
   239 
   410 scroll, so to make it scroll connect to the activated signal first and then call 
   240     Scrolls the view so that the item represented by \a index position is changed as per \a hint
   411 this method.
   241     parameter. By default HbDataForm does not scrolls. Application developer is supposed to 
   412     
   242     call this API if he wants this behaviour. User can connect to itemShown signal and then
   413     \param index - item of the data form to be scrolled to the \a hint position. 
   243     can call this API.
   414     \param hint - position the item is scrolled to on the view, for example to 
       
   415     the top or center. The values of \a hint are the following:
       
   416 
       
   417     - EnsureVisible (default)
       
   418     - PositionAtTop
       
   419     - PositionAtBottom
       
   420     - PositionAtCenter
       
   421 
   244 */
   422 */
   245 void HbDataForm::scrollTo(const QModelIndex &index, ScrollHint hint)
   423 void HbDataForm::scrollTo(const QModelIndex &index, ScrollHint hint)
   246 {
   424 {
   247     HbAbstractItemView::scrollTo(index, hint);
   425     HbAbstractItemView::scrollTo(index, hint);
   248 }
   426 }
   249 
   427 
   250 
   428 
   251 /*!
   429 /*!
   252     @beta
   430     @beta
   253 
   431 
   254     Sets the item referred to by \a index to either collapse or expanded state, 
   432     Expands and collapses the given item specified by \a index, depending on the 
   255     depending on the value of \a expanded. If \a expanded is true then child item are 
   433     given \a expanded value. If it is \c true, the item is expanded. If it is \c 
   256     supposed to be visible and in that case itemShown will be emitted for all the
   434     false, the item is collapsed. When the item is
   257     new data items which were created.
   435     
       
   436     - expanded, its child items are shown.
       
   437     - collapsed, its child items are not shown.
   258 
   438 
   259     \sa isExpanded
   439     \sa isExpanded
   260 */
   440 */
   261 void HbDataForm::setExpanded(const QModelIndex &index, bool expanded)
   441 void HbDataForm::setExpanded(const QModelIndex &index, bool expanded)
   262 {
   442 {
   274         // when ever it gets created expansion state will be considered . This is valid for formPage group 
   454         // when ever it gets created expansion state will be considered . This is valid for formPage group 
   275         // and group page . Itemstate for the leaf items also will be set but does not have any
   455         // and group page . Itemstate for the leaf items also will be set but does not have any
   276         // significance since these items cannot expand( do not have children )
   456         // significance since these items cannot expand( do not have children )
   277         
   457         
   278         else {
   458         else {
       
   459             HbDataFormModelItem *modelItem = static_cast<HbDataFormModel *>(model())->itemFromIndex(index);
       
   460             if(modelItem->type() == HbDataFormModelItem::GroupPageItem ) {
       
   461                 d->collapseAllGroupPages(index.parent());
       
   462             }
   279             d->mContainer->setItemTransientStateValue(index, "expanded", expanded);
   463             d->mContainer->setItemTransientStateValue(index, "expanded", expanded);
   280         } 
   464         } 
   281     }
   465     }
   282 }
   466 }
   283 
   467 
   284 /*!
   468 /*!
   285     @beta
   469     @beta
   286 
   470 
   287     Returns true if the model item at \a index is expanded otherwise returns false.
   471     Returns \c true if the given model item is expanded (i.e. children are 
       
   472     visible), otherwise returns \c false.
       
   473     
       
   474     \param index - the model item
   288 
   475 
   289     \sa setExpanded
   476     \sa setExpanded
   290 */
   477 */
   291 bool HbDataForm::isExpanded(const QModelIndex &index) const
   478 bool HbDataForm::isExpanded(const QModelIndex &index) const
   292 {
   479 {
   300 }
   487 }
   301 
   488 
   302 /*!
   489 /*!
   303     @beta
   490     @beta
   304 
   491 
   305     Sets the heading of HbDataForm with the \a heading provided. Heading is displayed on 
   492     Sets the data form's heading to be the given \a heading. The heading is 
   306     top of the HbDataForm. Heading is non-focusable.
   493     displayed on the top of form and it is non-focusable.
   307 
   494 
   308     \sa heading 
   495     \sa heading, setDescription and description
   309     \sa setDescription
       
   310     \sa description
       
   311 */
   496 */
   312 void HbDataForm::setHeading(const QString &heading)
   497 void HbDataForm::setHeading(const QString &heading)
   313 {
   498 {
   314     Q_D(HbDataForm);
   499     Q_D(HbDataForm);
   315 
       
   316     if(heading.isEmpty() && d->mHeadingWidget) {
   500     if(heading.isEmpty() && d->mHeadingWidget) {
   317         if(!d->mHeadingWidget->mPageCombo && d->mHeadingWidget->mDescription.isEmpty()) {
   501         if(!d->mHeadingWidget->mPageCombo && d->mHeadingWidget->mDescription.isEmpty()) {
   318             // delete the FormheadingWidget
   502             // delete the FormheadingWidget
   319             delete d->mHeadingWidget;
   503             delete d->mHeadingWidget;
   320             d->mHeadingWidget = 0;
   504             d->mHeadingWidget = 0;
   339 }
   523 }
   340 
   524 
   341 /*!
   525 /*!
   342     @beta
   526     @beta
   343 
   527 
   344     Returns heading of HbDataForm.
   528     Returns the heading of the data form.
   345 
   529 
   346     \sa setHeading
   530     \sa setHeading, setDescription and description
   347     \sa setDescription
       
   348     \sa description
       
   349 */
   531 */
   350 QString HbDataForm::heading() const
   532 QString HbDataForm::heading() const
   351 {
   533 {
   352     Q_D(const HbDataForm);
   534     Q_D(const HbDataForm);
   353     if(d->mHeadingWidget) {
   535     if(d->mHeadingWidget) {
   358 }
   540 }
   359 
   541 
   360 /*!
   542 /*!
   361     @beta
   543     @beta
   362 
   544 
   363     Sets the description of HbDataForm with the \a description. Description is displayed 
   545     Sets the data form's description to be the given \a description. The 
   364     below heading. Description is non-focusable.
   546     description is displayed below the heading and it is non-focusable.
   365 
   547 
   366     \sa description
   548     \sa description, setHeading and heading
   367     \sa setHeading
       
   368     \sa heading
       
   369 */
   549 */
   370 void HbDataForm::setDescription(const QString &description)
   550 void HbDataForm::setDescription(const QString &description)
   371 {
   551 {
   372     Q_D(HbDataForm);
   552     Q_D(HbDataForm);
   373 
       
   374     if(description.isEmpty() && d->mHeadingWidget) {
   553     if(description.isEmpty() && d->mHeadingWidget) {
   375         if(!d->mHeadingWidget->mPageCombo && d->mHeadingWidget->mHeading.isEmpty()) {
   554         if(!d->mHeadingWidget->mPageCombo && d->mHeadingWidget->mHeading.isEmpty()) {
   376             // delete the FormheadingWidget
   555             // delete the FormheadingWidget
   377             delete d->mHeadingWidget;
   556             delete d->mHeadingWidget;
   378             d->mHeadingWidget = 0;
   557             d->mHeadingWidget = 0;
   397 }
   576 }
   398 
   577 
   399 /*!
   578 /*!
   400     @beta
   579     @beta
   401 
   580 
   402     Returns description of HbDataForm.
   581     Returns the description of the data form.
   403 
   582 
   404     \sa setDescription
   583     \sa setDescription, setHeading and heading
   405     \sa setHeading
       
   406     \sa heading
       
   407 */
   584 */
   408 QString HbDataForm::description() const
   585 QString HbDataForm::description() const
   409 {
   586 {
   410     Q_D(const HbDataForm);
   587     Q_D(const HbDataForm);
   411     if(d->mHeadingWidget) {
   588     if(d->mHeadingWidget) {
   419     \deprecated HbDataForm::primitive(HbStyle::Primitive)
   596     \deprecated HbDataForm::primitive(HbStyle::Primitive)
   420          is deprecated.
   597          is deprecated.
   421 
   598 
   422     \reimp
   599     \reimp
   423 
   600 
   424     Returns the style primitive of HbDataForm depending upon the type \a primitive.
   601     Returns the style primitive of HbDataForm depending on the type \a primitive.
   425     \sa primitive
   602     \sa primitive
   426 */
   603 */
   427 QGraphicsItem* HbDataForm::primitive(HbStyle::Primitive primitive) const
   604 QGraphicsItem* HbDataForm::primitive(HbStyle::Primitive primitive) const
   428 {
   605 {
   429     Q_D(const HbDataForm);
   606     Q_D(const HbDataForm);
   430 
   607 
   431     switch (primitive) {
   608     switch (primitive) {
   432         case HbStyle::P_DataForm_heading_background:
   609         case HbStylePrivate::P_DataForm_heading_background:
   433             return d->mHeadingWidget->mBackgroundItem;
   610             return d->mHeadingWidget->mBackgroundItem;
   434         case HbStyle::P_DataForm_heading:
   611         case HbStylePrivate::P_DataForm_heading:
   435             return d->mHeadingWidget->mHeadingItem;
   612             return d->mHeadingWidget->mHeadingItem;
   436         case HbStyle::P_DataForm_description:
   613         case HbStylePrivate::P_DataForm_description:
   437             return d->mHeadingWidget->mDescriptionItem;
   614             return d->mHeadingWidget->mDescriptionItem;
   438         default:
   615         default:
   439             return 0;
   616             return 0;
   440     }
   617     }
   441 }
   618 }
   442 
   619 
   443 /*!
   620 
   444     \reimp
   621 
   445 
   622 /*!
   446     If \a model passed is NULL then all values of data form are reset. Calls the
   623     Sets the data form model to the given \a model. If the given \a model is 
   447     setModel of base class. This API does not clears the heading and description set
   624     NULL then all values of the data form are reset. This method does not clear 
   448     for HbDataForm. If with new \a model user does not wants heading and description
   625     the heading and description of the data form. If you want the heading and 
   449     then he should call setHeading and setDescription with empty string.
   626     description of the data model to be empty, call HbDataForm::setHeading() and 
   450 
   627     HbDataForm::setDescription() with an empty string as a parameter.
       
   628     
   451     \sa setHeading, setDescription
   629     \sa setHeading, setDescription
   452 */
   630 */
   453 void HbDataForm::setModel(QAbstractItemModel *model, HbAbstractViewItem *prototype)
   631 void HbDataForm::setModel(QAbstractItemModel *model, HbAbstractViewItem *prototype)
   454 {
   632 {
   455     Q_D(HbDataForm);
   633     Q_D(HbDataForm);
   464     }
   642     }
   465     HbAbstractItemView::setModel(model, prototype);
   643     HbAbstractItemView::setModel(model, prototype);
   466 }
   644 }
   467 
   645 
   468 
   646 
   469 /*!
   647 
   470     \reimp
   648 /*!
   471 */
   649 
       
   650 */
       
   651 
   472 void HbDataForm::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
   652 void HbDataForm::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
   473 {
   653 {
   474     Q_UNUSED(bottomRight);
   654     Q_UNUSED(bottomRight);
   475     if(topLeft.isValid()) {
   655     if(topLeft.isValid()) {
   476 
   656 
   478             HbDataFormModelItem *modelItem = 
   658             HbDataFormModelItem *modelItem = 
   479                         static_cast<HbDataFormModel *>(model())->itemFromIndex(topLeft);           
   659                         static_cast<HbDataFormModel *>(model())->itemFromIndex(topLeft);           
   480             HbDataFormModelItemPrivate *modelItem_priv = HbDataFormModelItemPrivate::d_ptr(modelItem);
   660             HbDataFormModelItemPrivate *modelItem_priv = HbDataFormModelItemPrivate::d_ptr(modelItem);
   481 
   661 
   482             if(item){
   662             if(item){
   483                 HbDataFormViewItemPrivate::d_ptr(item)->setEnabled( modelItem->isEnabled() );
       
   484                 if( modelItem_priv->dirtyProperty() == "LabelRole"      ||
   663                 if( modelItem_priv->dirtyProperty() == "LabelRole"      ||
   485                     modelItem_priv->dirtyProperty() == "DecorationRole" || 
   664                     modelItem_priv->dirtyProperty() == "DecorationRole" || 
   486                     modelItem_priv->dirtyProperty() == "DescriptionRole" ) {
   665                     modelItem_priv->dirtyProperty() == "DescriptionRole" ) {
   487 
   666 
   488                      HbDataFormViewItemPrivate::d_ptr(item)->updateData();
   667                      HbDataFormViewItemPrivate::d_ptr(item)->updateData();
   489                      return;
   668                      return;
       
   669                 } else if(modelItem_priv->dirtyProperty() == "enabled") {
       
   670                     HbDataFormViewItemPrivate::d_ptr(item)->setEnabled( modelItem->isEnabled() );
   490                 }
   671                 }
   491                 item->restore();
   672                 item->restore();
   492             }
   673             }
   493     }
   674     }
   494 }
   675 }
   495 /*!
   676 /*!
   496     \reimp
   677     Initializes the style option data form defined by \a option with the data 
   497 
   678     form values.
   498     Initializes \a option with the values from HbDataForm.
   679     
       
   680     \param option - Style option data form to be initialized.
   499 */
   681 */
   500 void HbDataForm::initStyleOption(HbStyleOptionDataForm *option)
   682 void HbDataForm::initStyleOption(HbStyleOptionDataForm *option)
   501 {
   683 {
   502     Q_D(HbDataForm);
   684     Q_D(HbDataForm);
   503     d->mHeadingWidget->initStyleOption(option);
   685     d->mHeadingWidget->initStyleOption(option);
   504 }
   686 }
   505 
   687 
   506 
   688 
   507 /*!
   689 /*!
   508     \reimp
   690 
   509 */
   691 */
   510 void HbDataForm::rowsInserted(const QModelIndex &parent, int start, int end)
   692 void HbDataForm::rowsInserted(const QModelIndex &parent, int start, int end)
   511 {
   693 {
   512     HbAbstractItemView::rowsInserted(parent, start, end);
   694     HbAbstractItemView::rowsInserted(parent, start, end);
   513 }
   695 }
   514 
   696 
   515 /*!
   697 /*!
   516     \reimp
   698 
   517 */
   699 */
   518 void HbDataForm::rowsAboutToBeRemoved(const QModelIndex &index, int start, int end)
   700 void HbDataForm::rowsAboutToBeRemoved(const QModelIndex &index, int start, int end)
   519 {
   701 {
   520    Q_D(HbDataForm);
   702    Q_D(HbDataForm);
   521 
   703 
   543 }
   725 }
   544 
   726 
   545 /*!
   727 /*!
   546     @beta 
   728     @beta 
   547 
   729 
   548     This API can be used to connect with the signal of HbDataFormViewItem's content widget.
   730     Connects the \a signal of content widget \a item to the \a slot of \a 
   549     For example: If HbDataFormModelItem is of type DataItemType::SliderItem then user
   731     receiver object.
   550     can connect to the signals of slider using this API.
   732     
   551     Example Usage:
   733     \param item - %Data form model item.
   552     \code
   734     \param signal - Signal of the content widget. 
   553     HbDataForm *form = new HbDataForm();
   735     \param receiver - Object whose slot is called. 
   554     HbDataFormModel *model = new HbDataFormModel();
   736     \param slot - Slot of \a receiver object which is called when \a signal is emitted.
   555     HbDataFormModelItem *sliderItem = model->appendDataFormItem(HbDataFormModelItem::SliderItem);
       
   556     form->addConnection(sliderItem, SIGNAL(sliderReleased()), 
       
   557         this, SLOT(volumeChanged()));
       
   558     \endcode
       
   559 
       
   560     \param item Instance of model item 
       
   561     \param signal Signal of content widget. 
       
   562     \param receiver Instance of object whose slot will be called 
       
   563     \param slot Slot of \a receiver which will get called when signal is emitted
       
   564  
   737  
   565     \sa removeConnection
   738     \sa removeConnection 
   566     \sa removeAllConnection
       
   567 */
   739 */
   568 void HbDataForm::addConnection(HbDataFormModelItem * item, 
   740 void HbDataForm::addConnection(HbDataFormModelItem * item, 
   569                                const char* signal, 
   741                                const char* signal, 
   570                                QObject *receiver, 
   742                                QObject *receiver, 
   571                                const char* slot)
   743                                const char* slot)
   580 }
   752 }
   581 
   753 
   582 /*!
   754 /*!
   583     @beta
   755     @beta
   584 
   756 
   585     This API can be used to remove the signal connection which was established using the
   757     Removes the connection between the signal of content widget object and the 
   586     addConnection API.
   758     slot of receiver object.
   587 
   759 
   588     \sa addConnection
   760     \param item - %Data form model item.
   589     \sa removeAllConnection
   761     \param signal - The signal of content widget object.
       
   762     \param receiver - The object whose slot is called.
       
   763     \param slot - The slot of \a receiver object which is called when \a signal is emitted.
       
   764 
       
   765     \sa addConnection and removeAllConnection
   590 */
   766 */
   591 void HbDataForm::removeConnection(HbDataFormModelItem * item, 
   767 void HbDataForm::removeConnection(HbDataFormModelItem * item, 
   592                                   const char* signal, 
   768                                   const char* signal, 
   593                                   QObject *receiver, 
   769                                   QObject *receiver, 
   594                                   const char* slot)
   770                                   const char* slot)
   598 }
   774 }
   599 
   775 
   600 /*!
   776 /*!
   601     @beta
   777     @beta
   602 
   778 
   603     Removes the connection of all the contentwidget of all the items which has been established.
   779     Removes all the connections between signals and slots of all content widgets 
   604     The connection information stored inside data form is also cleared.
   780     of all items. The connection information stored in the underlying data form 
   605 
   781     is also cleared.
   606     \sa removeConnection
   782 
   607     \sa addConnection
   783     \sa removeConnection and addConnection
   608 */
   784 */
   609 void HbDataForm::removeAllConnection()
   785 void HbDataForm::removeAllConnection()
   610 {   
   786 {   
   611     Q_D(HbDataForm);
   787     Q_D(HbDataForm);
   612     d->removeAllConnection();
   788     d->removeAllConnection();
   613 }
   789 }
   614 
   790 
   615 /*!
   791 /*!
   616     @beta
   792     @beta
   617 
   793 
   618     Removes all connections to the contentwidget of HbDataFormModelItem's corresponding 
   794     Removes all the connections of the content widget \a item. The connection 
   619     visual Item ( HbdataFormViewItem ).The connection information of correspoding 
   795     information stored in the underlying data form is also cleared.
   620     HbDataFormModelItem stored inside data form also cleared.
       
   621 
   796 
   622     \sa removeAllConnection 
   797     \sa removeAllConnection 
   623 */
   798 */
   624 void HbDataForm::removeAllConnection(HbDataFormModelItem *item)
   799 void HbDataForm::removeAllConnection(HbDataFormModelItem *item)
   625 {   
   800 {   
   626     Q_D(HbDataForm);
   801     Q_D(HbDataForm);
   627     d->removeAllConnection(item);
   802     d->removeAllConnection(item);
   628 }
   803 }
   629 
   804 
       
   805 
       
   806 /*!
       
   807     \reimp
       
   808 
       
   809     This slot is called when orientation is changed.
       
   810     \a newOrientation has the currentOrientation mode.
       
   811     Note: Currently platform dependent orientation support is not available
       
   812 */
       
   813 void HbDataForm::orientationChanged(Qt::Orientation newOrientation)
       
   814 {
       
   815     Q_UNUSED(newOrientation);
       
   816     Q_D(HbDataForm);
       
   817 
       
   818     //Setting the uniform ites sizes to container again resets size caches.
       
   819     d->mContainer->setUniformItemSizes(d->mContainer->uniformItemSizes());
       
   820     d->mContainer->setPos(0,0);
       
   821     d->mContainer->resizeContainer();
       
   822 
       
   823     d->updateScrollMetrics();
       
   824 
       
   825     d->stopAnimating();
       
   826     scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter);
       
   827     d->mVisibleIndex = QModelIndex();
       
   828 }
       
   829 
       
   830 void HbDataForm::orientationAboutToBeChanged()
       
   831 {
       
   832     Q_D(HbDataForm);
       
   833     QRectF rect = mapToScene(boundingRect()).boundingRect();
       
   834     HbAbstractViewItem * item = d->itemAt((rect.center()));
       
   835     if(item){
       
   836         d->mVisibleIndex = item->modelIndex();
       
   837     } else{
       
   838         HbAbstractItemView::orientationAboutToBeChanged();
       
   839     }
       
   840 }
       
   841 
       
   842 /*!
       
   843     \reimp
       
   844 */
       
   845 
       
   846 void HbDataForm::showEvent(QShowEvent * event)
       
   847 {
       
   848     //if(!isVisible() ){
       
   849     //    delayGestureInstaller.install();       
       
   850     //}    
       
   851     HbAbstractItemView::showEvent( event );
       
   852 }
       
   853 
       
   854 /*!
       
   855     \reimp
       
   856 */
       
   857 void HbDataForm::hideEvent ( QHideEvent * event )  
       
   858 {
       
   859     //delayGestureInstaller.unInstall();
       
   860     HbAbstractItemView::hideEvent( event );
       
   861     
       
   862 }
       
   863 
       
   864 
   630 #include "moc_hbdataform.cpp"
   865 #include "moc_hbdataform.cpp"
   631 
   866 
   632 
   867