src/hbwidgets/itemviews/hbtreeviewitem.cpp
changeset 34 ed14f46c0e55
parent 6 c3690ec91ef8
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    29 #include "hbtreeview.h"
    29 #include "hbtreeview.h"
    30 #include "hbabstractitemview.h"
    30 #include "hbabstractitemview.h"
    31 #include "hbabstractitemcontainer_p.h"
    31 #include "hbabstractitemcontainer_p.h"
    32 
    32 
    33 #include <hbnamespace.h>
    33 #include <hbnamespace.h>
       
    34 #include <hbnamespace_p.h>
    34 #include <hbstyle.h>
    35 #include <hbstyle.h>
    35 #include <hbstyleoptiontreeviewitem_p.h>
       
    36 #include <hbwidgetfeedback.h>
    36 #include <hbwidgetfeedback.h>
    37 #include <hbtapgesture.h>
    37 #include <hbtapgesture.h>
    38 #include <hbeffect.h>
    38 #include <hbeffect.h>
       
    39 
       
    40 #include <hbstyleiconprimitivedata.h>
    39 
    41 
    40 #include <QPersistentModelIndex>
    42 #include <QPersistentModelIndex>
    41 #include <QVariant>
    43 #include <QVariant>
    42 #include <QDebug>
    44 #include <QDebug>
    43 
    45 
    47     \class HbTreeViewItem
    49     \class HbTreeViewItem
    48     \brief The HbTreeViewItem class represents a single item in a hierarchical list.    
    50     \brief The HbTreeViewItem class represents a single item in a hierarchical list.    
    49 
    51 
    50     The HbTreeViewItem class provides an item that is used by the HbTreeView class to
    52     The HbTreeViewItem class provides an item that is used by the HbTreeView class to
    51     visualize content within single model index. The item can only be used with HbTreeView
    53     visualize content within single model index. The item can only be used with HbTreeView
    52     or with objects derived from HbTreeView. By default the HbTreeViewItem supports
    54     or with objects derived from HbTreeView. 
    53     all the same content that HbListViewItem supports. In addition to this it is able to 
    55     
    54     visualize parent items.
    56     HbTreeViewItem supports following model item types in Hb::ItemTypeRole role of data model
       
    57     \li Hb::StandardItem
       
    58     \li Hb::ParentItem. Parent item visualizes collapsed/expanded state of parent item with "subitem-indicator" item.
       
    59     \li Hb::SeparatorItem
       
    60     HbAbstractViewItem documentation provides details how these item types distinguish from each other. 
       
    61 
       
    62     HbTreeViewItem supports all the same data content in child items as HbListViewItem does. 
       
    63     Parent item visualizes by default expanded/collapsed icon and content of "text-1" primitive item. This is defined in HbTreeViewItem WidgetML file.
       
    64     Handling Qt::BackgroundRole item data role takes place in base class HbAbstractViewItem.
    55 
    65 
    56     \b Subclassing
    66     \b Subclassing
    57 
    67 
    58     See HbListViewItem for commmon view item subclassing reference. 
    68     See HbListViewItem for commmon view item subclassing reference. 
    59 
    69 
    60     \primitives
    70     \primitives
    61     \primitive{subitem-indicator} HbIconItem representing the expand/collapse icon in an HbTreeViewItem that has child items.
    71     \primitive{subitem-indicator} HbIconItem with item name "subitem-indicator" representing the expand/collapse icon in an HbTreeViewItem that has child items.
       
    72 
       
    73     \sa HbListViewItem
       
    74     \sa HbAbstractViewItem
    62 */
    75 */
    63 
    76 
    64 
    77 
    65 HbTreeViewItemPrivate::HbTreeViewItemPrivate(HbTreeViewItem *prototype) :
    78 HbTreeViewItemPrivate::HbTreeViewItemPrivate(HbTreeViewItem *prototype) :
    66     HbListViewItemPrivate(prototype, new HbTreeViewItemShared),
    79     HbListViewItemPrivate(prototype, new HbTreeViewItemShared),
   110 
   123 
   111 void HbTreeViewItemPrivate::updateExpandItem()
   124 void HbTreeViewItemPrivate::updateExpandItem()
   112 {
   125 {
   113     Q_Q(HbTreeViewItem);
   126     Q_Q(HbTreeViewItem);
   114 
   127 
   115     HbStyleOptionTreeViewItem styleOption;
   128     HbStyleIconPrimitiveData iconPrimitiveData;
   116     q->initStyleOption(&styleOption);
   129     q->initPrimitiveData(&iconPrimitiveData, mExpandItem);
   117 
   130 
   118     q->style()->updatePrimitive(mExpandItem, HbStyle::P_TreeViewItem_expandicon, &styleOption);
   131     q->style()->updatePrimitive(mExpandItem, &iconPrimitiveData, q);
   119 }
   132 }
   120 
   133 
   121 void HbTreeViewItemPrivate::tapTriggered(QGestureEvent *event)
   134 void HbTreeViewItemPrivate::tapTriggered(QGestureEvent *event)
   122 {
   135 {
   123     Q_Q(HbTreeViewItem);
   136     Q_Q(HbTreeViewItem);
   124 
   137 
   125     HbTapGesture *gesture = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
   138     HbTapGesture *gesture = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
   126 
   139 
   127     if (gesture->state() == Qt::GestureFinished 
   140     if (gesture->state() == Qt::GestureFinished 
   128         && gesture->tapStyleHint() == HbTapGesture::Tap) {
   141         && gesture->tapStyleHint() == HbTapGesture::Tap) {
       
   142         q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
   129 
   143 
   130         QPointF position = event->mapToGraphicsScene(gesture->hotSpot());
   144         QPointF position = event->mapToGraphicsScene(gesture->hotSpot());
   131         position = q->mapFromScene(position);
   145         position = q->mapFromScene(position);
   132 
   146 
   133         bool inSelectionArea = false;
   147         bool inSelectionArea = false;
   236 
   250 
   237     const QAbstractItemModel *model = d->mIndex.model();
   251     const QAbstractItemModel *model = d->mIndex.model();
   238 
   252 
   239     if (model && model->hasChildren(d->mIndex) && sd->mUserExpandable) {
   253     if (model && model->hasChildren(d->mIndex) && sd->mUserExpandable) {
   240         if (!d->mExpandItem) {
   254         if (!d->mExpandItem) {
   241             d->mExpandItem = style()->createPrimitive(HbStyle::P_TreeViewItem_expandicon, this);
   255             d->mExpandItem = style()->createPrimitive(HbStyle::PT_IconItem, QLatin1String("subitem-indicator"), 0);
       
   256             d->mExpandItem->setParentItem(this); // To enable asynchronous icon loading.
   242             d->mItemsChanged = true;
   257             d->mItemsChanged = true;
   243         }
   258         }
   244     } else {
   259     } else {
   245         if (d->mExpandItem) {
   260         if (d->mExpandItem) {
   246             d->mItemsChanged = true;
   261             d->mItemsChanged = true;
   284     HB_SD(HbAbstractViewItem);
   299     HB_SD(HbAbstractViewItem);
   285 
   300 
   286     if (d->mExpanded != expanded) {
   301     if (d->mExpanded != expanded) {
   287         d->mExpanded = expanded;
   302         d->mExpanded = expanded;
   288 
   303 
   289 		if (sd->mItemView != 0) {
   304         if (sd->mItemView != 0) {
   290             HbTreeView *treeView = qobject_cast<HbTreeView *>(sd->mItemView);
   305             HbTreeView *treeView = qobject_cast<HbTreeView *>(sd->mItemView);
   291             if (treeView) {
   306             if (treeView) {
   292                 treeView->setExpanded(this->modelIndex(), expanded);
   307                 treeView->setExpanded(this->modelIndex(), expanded);
   293             }
   308             }
   294         }
   309         }
   334     HbListViewItem::setTransientState(state);
   349     HbListViewItem::setTransientState(state);
   335     d->mExpanded = state.value("expanded").toBool();
   350     d->mExpanded = state.value("expanded").toBool();
   336 }
   351 }
   337 
   352 
   338 /*!
   353 /*!
   339     Initialize option with the values from this HbTreeViewItem. 
   354   Initializes the HbTreeViewItem primitive data. 
   340 
   355   
   341     This method is useful for subclasses when they need a HbStyleOptionTreeViewItem, 
   356   This function calls HbWidgetBase::initPrimitiveData().
   342     but don't want to fill in all the information themselves.
   357   \a primitiveData is data object, which is populated with data. \a primitive is the primitive.
   343 */
   358 */
   344 void HbTreeViewItem::initStyleOption(HbStyleOptionTreeViewItem *option) const
   359 void HbTreeViewItem::initPrimitiveData(HbStylePrimitiveData     *primitiveData, 
   345 {
   360                                        const QGraphicsObject    *primitive)
   346     Q_D(const HbTreeViewItem);
   361 {
   347 
   362     Q_ASSERT_X(primitive && primitiveData, "HbTreeViewItem::initPrimitiveData" , "NULL data not permitted");
   348     HbListViewItem::initStyleOption(option);
   363     Q_D(HbTreeViewItem);
   349 
   364 
   350     option->expanded = d->mExpanded;
   365     HbWidgetBase::initPrimitiveData(primitiveData, primitive);
       
   366     if (    primitiveData->type == HbStylePrimitiveData::SPD_Icon
       
   367         &&  primitive == d->mExpandItem) {
       
   368         QString iconName;
       
   369         if (d->mExpanded) {
       
   370             if (testAttribute(Hb::InsidePopup)) {
       
   371                 iconName = QLatin1String("qtg_mono_collapse");
       
   372             } else {
       
   373                 iconName = QLatin1String("qtg_small_collapse");
       
   374             }
       
   375         } else {
       
   376             if (testAttribute(Hb::InsidePopup)) {
       
   377                 iconName = QLatin1String("qtg_mono_expand");
       
   378             } else {
       
   379                 iconName = QLatin1String("qtg_small_expand");
       
   380             }
       
   381         }
       
   382         hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData)->iconName = iconName;
       
   383     }
   351 }
   384 }
   352 
   385 
   353 /*!
   386 /*!
   354     Sets items either expandable or non-expandable by the user, depending on the value of \a expandable.
   387     Sets items either expandable or non-expandable by the user, depending on the value of \a expandable.
   355 
   388 
   379 
   412 
   380 /*!
   413 /*!
   381     \reimp
   414     \reimp
   382     
   415     
   383     In the base class the multiselection mode selection area is the whole item. In HbTreeView this is not
   416     In the base class the multiselection mode selection area is the whole item. In HbTreeView this is not
   384     possible because of the expansion icon. For the HbTreeView the selection area in multiselection mode is 
   417     possible because of the expansion icon. For the HbTreeView the selection is area of
   385     defined by the primitive HbStyle::P_ItemViewItem_touchmultiselection
   418     primitive with item name "multiselection-toucharea".
   386 */
   419 */
   387 bool HbTreeViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const
   420 bool HbTreeViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const
   388 {
   421 {
   389     Q_D(const HbTreeViewItem);
   422     Q_D(const HbTreeViewItem);
   390     if (   selectionAreaType == HbAbstractViewItem::MultiSelection 
   423     if (   selectionAreaType == HbAbstractViewItem::MultiSelection