예제 #1
0
int HbDataGroupPrivate::activePage( )
{
    Q_Q( HbDataGroup );
    // Here we need to find which page has the itemTransientState  true, 
    // which in turn will be the active page. If no page is set as true , then
    // make the 0th page as expanded ie itemTransientState as true

    // This function can be called from Group or GroupPage items 
    QModelIndex groupIndex ;    
    HbDataFormModelItem *modelItem = 
        static_cast<HbDataFormModel*>((q->itemView())->model())->itemFromIndex(
            q->modelIndex( ));
    HbDataFormModelItem *groupModelItem = 0;
    // get the group modelItem pointer depending upon the type
    if( modelItem->type() == HbDataFormModelItem::GroupItem ) {
        groupModelItem = modelItem;
    } else if( modelItem->type() == HbDataFormModelItem::GroupPageItem ) {
        groupModelItem = modelItem->parent();
    }
    int childCount = groupModelItem->childCount();
    //int activePage = 0;
    // get container for setting item state
    HbAbstractItemContainer *container = qobject_cast<HbAbstractItemContainer *>(
        static_cast<QGraphicsWidget *>( mSharedData->mItemView->contentWidget( ) ) );
    int currentPage = -1; 
    bool somePageExpanded = false;
    for( int i = 0; i < childCount; i++) {
        // Make sure that the child is groupPage type.
        HbDataFormModelItem *child = groupModelItem->childAt(i);
        if( child->type() == HbDataFormModelItem::GroupPageItem ) {
            // Here we are not using i as the page index since there can other types of children in the same level
            // so need a seperate variable for this 
            currentPage ++;
            
            // get the index of groupPage
            QModelIndex pageIndex = static_cast<HbDataFormModel*>(q->itemView()->model())->indexFromItem(child);
            if(container->itemTransientState(pageIndex).value("expanded").toBool()) {
                somePageExpanded = true;
                break;
            }
            
        }        
    }
    if(!somePageExpanded && currentPage != -1) {// This means pages are present and no page is expanded so expand first page
        currentPage = 0;
    }
    return currentPage;
}
예제 #2
0
QModelIndex HbDataGroupPrivate::pageModelIndex(int index) const 
{
    const Q_Q(HbDataGroup);
    int pageIndex = -1;
    QModelIndex modelIndex;
    
    // Make sure that the child is groupPage type and current item is group.
    if( index >= 0) {

        HbDataFormModelItem *modelItem = 
            static_cast<HbDataFormModel*>((q->itemView())->model())->itemFromIndex(
                q->modelIndex( ));
        HbDataFormModelItem *groupModelItem = 0;
        // get the group modelItem pointer depending upon the type
        if( modelItem->type() == HbDataFormModelItem::GroupItem ) {
            groupModelItem = modelItem;
        } else if( modelItem->type() == HbDataFormModelItem::GroupPageItem ) {
            groupModelItem = modelItem->parent();
        }

        int childCount = groupModelItem->childCount();

        for( int i = 0; i < childCount; i++) {

            HbDataFormModelItem *child = groupModelItem->childAt(i);
            if( child->type() == HbDataFormModelItem::GroupPageItem ) {
                pageIndex ++;
                // get the index of groupPage
                if(pageIndex == index) {
                modelIndex = static_cast<HbDataFormModel*>(q->itemView()->model())->indexFromItem(child);
                break; 
                    
                }
            }        
        }
    }
    return modelIndex;
}
예제 #3
0
// This function gets called  for group item or for grouppage item . It returs the corresponding page index .
// The relevance of this function is when some items are inserted before group page inside a group.
// returns -1 if not valid index.
int HbDataGroupPrivate::pageIndex(const QModelIndex &index) const 
{
    const Q_Q(HbDataGroup);
    int pageIndex = -1;
    HbDataFormModelItem::DataItemType indexType = static_cast<HbDataFormModelItem::DataItemType>(
        index.data( HbDataFormModelItem::ItemTypeRole).toInt( ) );

    // Make sure that the child is groupPage type and current item is group.
    if( (indexType == HbDataFormModelItem::GroupPageItem) || (indexType == HbDataFormModelItem::FormPageItem) ) {
        HbDataFormModelItem *modelItem = 
            static_cast<HbDataFormModel*>((q->itemView())->model())->itemFromIndex(
                q->modelIndex( ));
        HbDataFormModelItem *groupModelItem = 0;
        // get the group modelItem pointer depending upon the type
        if( modelItem->type() == HbDataFormModelItem::GroupItem ) {
            groupModelItem = modelItem;
        } else if( modelItem->type() == HbDataFormModelItem::GroupPageItem ) {
            groupModelItem = modelItem->parent();
        } else if (modelItem->type() == HbDataFormModelItem::FormPageItem ) {
            groupModelItem = static_cast<HbDataFormModel*>(q->itemView()->model())->invisibleRootItem();
        }
 
        int childCount = groupModelItem->childCount();
        for( int i = 0; i < childCount; i++) {
            HbDataFormModelItem *child = groupModelItem->childAt(i);
            if( (child->type() == HbDataFormModelItem::GroupPageItem ) || (child->type() == HbDataFormModelItem::FormPageItem)) {
                pageIndex ++;
                // get the index of groupPage
                QModelIndex childIndex = static_cast<HbDataFormModel*>(q->itemView()->model())->indexFromItem(child);
                if(childIndex == index) {
                    break;// we got the page index
                }
            }        
        }
    }
    return pageIndex;
}