src/hbwidgets/dataform/hbdataform.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
    31 #include "hbdataitemcontainer_p.h"
    31 #include "hbdataitemcontainer_p.h"
    32 #include "hbdatagroup_p.h"
    32 #include "hbdatagroup_p.h"
    33 #include "hbdatagroup_p_p.h"
    33 #include "hbdatagroup_p_p.h"
    34 #include <hbcombobox.h>
    34 #include <hbcombobox.h>
    35 #include "hbdataformheadingwidget_p.h"
    35 #include "hbdataformheadingwidget_p.h"
       
    36 #include "hbdataformmodelitem_p.h"
    36 #include "hbtreemodeliterator_p.h"
    37 #include "hbtreemodeliterator_p.h"
       
    38 
       
    39 // For QMAP_INT__ITEM_STATE_DEPRECATED's sake. Removed when QMap<int,QVariant> based state item system is removed
       
    40 #include <hbabstractviewitem_p.h>
    37 
    41 
    38 #include <QGraphicsSceneMouseEvent>
    42 #include <QGraphicsSceneMouseEvent>
    39 #include <QCoreApplication>
    43 #include <QCoreApplication>
    40 
    44 
    41 /*!
    45 /*!
   343 void HbDataForm::setExpanded(const QModelIndex &index, bool expanded)
   347 void HbDataForm::setExpanded(const QModelIndex &index, bool expanded)
   344 {
   348 {
   345     Q_D(HbDataForm);
   349     Q_D(HbDataForm);
   346 
   350 
   347     if (isExpanded(index) != expanded) {
   351     if (isExpanded(index) != expanded) {
   348         d->treeModelIterator()->itemStateChanged(index, HbDataFormViewItem::ExpansionKey);
   352         d->treeModelIterator()->itemExpansionChanged(index);
   349 
   353 
   350         HbDataFormViewItem *item =
   354         HbDataFormViewItem *item =
   351             static_cast<HbDataFormViewItem *>(d->mContainer->itemByIndex(index));
   355             static_cast<HbDataFormViewItem *>(d->mContainer->itemByIndex(index));
   352         if (item) {
   356         if (item) {
   353             item->setExpanded(expanded);
   357             item->setExpanded(expanded);
   354         }
   358         }
   355 
   359 
   356         d->mContainer->setItemStateValue(index, HbDataFormViewItem::ExpansionKey, expanded);
   360 #ifndef QMAP_INT__ITEM_STATE_DEPRECATED
       
   361        d->mContainer->setItemStateValue(index, HbDataFormViewItem::ExpansionKey, expanded);
       
   362 #endif
       
   363         d->mContainer->setItemTransientStateValue(index, "expanded", expanded);
   357         d->mContainer->setModelIndexes();
   364         d->mContainer->setModelIndexes();
   358     }
   365     }
   359 }
   366 }
   360 
   367 
   361 /*!
   368 /*!
   366     \sa setExpanded
   373     \sa setExpanded
   367 */
   374 */
   368 bool HbDataForm::isExpanded(const QModelIndex &index) const
   375 bool HbDataForm::isExpanded(const QModelIndex &index) const
   369 {
   376 {
   370     Q_D(const HbDataForm);
   377     Q_D(const HbDataForm);
   371     QVariant flags = d->mContainer->itemState(index).value(HbDataFormViewItem::ExpansionKey);
   378     QVariant flags = d->mContainer->itemTransientState(index).value("expanded");
   372     if (flags.isValid() && flags.toBool() == true) {
   379     if (flags.isValid() && flags.toBool() == true) {
   373         return true;
   380         return true;
   374     } else {
   381     } else {
   375         return false;
   382         return false;
   376     }
   383     }
   482     }
   489     }
   483     return QString();
   490     return QString();
   484 }
   491 }
   485 
   492 
   486 /*!
   493 /*!
       
   494 
       
   495     \deprecated HbDataForm::primitive(HbStyle::Primitive)
       
   496          is deprecated.
       
   497 
   487     \reimp
   498     \reimp
   488 
   499 
   489     Returns the style primitive of HbDataForm depending upon the type \a primitive.
   500     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
   501     \sa primitive
   494 */
   502 */
   495 QGraphicsItem* HbDataForm::primitive(HbStyle::Primitive primitive) const
   503 QGraphicsItem* HbDataForm::primitive(HbStyle::Primitive primitive) const
   496 {
   504 {
   497     Q_D(const HbDataForm);
   505     Q_D(const HbDataForm);
   498 
   506 
   499     switch (primitive) {
   507     switch (primitive) {
       
   508         case HbStyle::P_DataForm_heading_background:
       
   509             return d->mHeadingWidget->mBackgroundItem;
   500         case HbStyle::P_DataForm_heading:
   510         case HbStyle::P_DataForm_heading:
   501             return d->mHeadingWidget->mHeadingItem;
   511             return d->mHeadingWidget->mHeadingItem;
   502         case HbStyle::P_DataForm_description:
   512         case HbStyle::P_DataForm_description:
   503             return d->mHeadingWidget->mDescriptionItem;
   513             return d->mHeadingWidget->mDescriptionItem;
   504         default:
   514         default:
   506     }
   516     }
   507 }
   517 }
   508 
   518 
   509 /*!
   519 /*!
   510     
   520     
   511     \deprecated HbDataForm::dataFormViewItem(const QModelIndex &index) const
   521     \deprecated HbDataForm::dataFormViewItem(const QModelIndex&) const
   512         is deprecated. Please use HbAbstractItemView::itemByIndex instead.
   522         is deprecated. Please use HbAbstractItemView::itemByIndex instead.
   513 
   523 
   514     Returns HbDataFormViewItem for the correspoding \a index passed. Returns
   524     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.
   525     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.    
   526     Ideally user should call this API when activate is called for \a index.    
   595 */
   605 */
   596 
   606 
   597 void HbDataForm::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
   607 void HbDataForm::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
   598 {
   608 {
   599     Q_UNUSED(bottomRight);
   609     Q_UNUSED(bottomRight);
   600     if(topLeft.isValid()) {       
   610     if(topLeft.isValid()) {
       
   611 
   601             HbDataFormViewItem* item = static_cast<HbDataFormViewItem*>(dataFormViewItem(topLeft));
   612             HbDataFormViewItem* item = static_cast<HbDataFormViewItem*>(dataFormViewItem(topLeft));
       
   613             HbDataFormModelItem *modelItem = 
       
   614                         static_cast<HbDataFormModel *>(model())->itemFromIndex(topLeft);           
       
   615             HbDataFormModelItemPrivate *modelItem_priv = HbDataFormModelItemPrivate::d_ptr(modelItem);
       
   616 
   602             if(item){
   617             if(item){
   603                 item->load();
   618                 if( modelItem_priv->dirtyProperty() == "LabelRole"      ||
   604                 HbDataFormModelItem *modelItem = 
   619                     modelItem_priv->dirtyProperty() == "DecorationRole" || 
   605                         static_cast<HbDataFormModel *>(model())->itemFromIndex(topLeft);
   620                     modelItem_priv->dirtyProperty() == "DescriptionRole" ) {
       
   621 
       
   622                          HbDataFormViewItemPrivate::d_ptr(item)->updateData();
       
   623                          return;
       
   624                 }
       
   625 
       
   626                 item->load();                
   606                 HbDataFormViewItemPrivate::d_ptr(item)->setEnabled( modelItem->isEnabled() );          
   627                 HbDataFormViewItemPrivate::d_ptr(item)->setEnabled( modelItem->isEnabled() );          
   607             }
   628             }
   608     }
   629     }
   609 }
   630 }
   610 /*!
   631 /*!
   616 {
   637 {
   617     Q_D(HbDataForm);
   638     Q_D(HbDataForm);
   618     d->mHeadingWidget->initStyleOption(option);
   639     d->mHeadingWidget->initStyleOption(option);
   619 }
   640 }
   620 
   641 
   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 
   642 
   638 /*!
   643 /*!
   639     \reimp
   644     \reimp
   640 */
   645 */
   641 void HbDataForm::rowsInserted(const QModelIndex &parent, int start, int end)
   646 void HbDataForm::rowsInserted(const QModelIndex &parent, int start, int end)