src/hbwidgets/itemviews/hbtreeview_p.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 "hbtreeview_p.h"
       
    27 #include "hbtreeview.h"
       
    28 
       
    29 #include "hbtreeviewitem.h"
       
    30 #include "hbtreeitemselectionmodel_p.h"
       
    31 #include "hbtreemodeliterator_p.h"
       
    32 
       
    33 const QString KDefaultLayoutOption = "default";
       
    34 
       
    35 HbTreeViewPrivate::HbTreeViewPrivate() :
       
    36     HbAbstractItemViewPrivate(),
       
    37     mSelectionStarted(false)
       
    38 {
       
    39 }
       
    40 
       
    41 HbTreeViewPrivate::~HbTreeViewPrivate()
       
    42 {
       
    43 }
       
    44 
       
    45 void HbTreeViewPrivate::init()
       
    46 {
       
    47     Q_Q(HbTreeView);
       
    48 
       
    49     q->setClampingStyle(HbScrollArea::StrictClamping);
       
    50     q->setFrictionEnabled(0);
       
    51     q->setItemRecycling(true);
       
    52     q->setScrollDirections(Qt::Horizontal | Qt::Vertical);
       
    53     mLayoutOptionName = KDefaultLayoutOption;
       
    54     treeModelIterator()->setItemContainer(mContainer, HbTreeViewItem::ExpansionKey);
       
    55 }
       
    56 
       
    57 bool HbTreeViewPrivate::isParentValid(const QModelIndex &parent) const
       
    58 {
       
    59     bool valid = false;
       
    60     QModelIndex currentParent = parent;
       
    61     while (!valid) {
       
    62         if (currentParent == mModelIterator->rootIndex()) {
       
    63             valid = true;
       
    64         } else if (currentParent.isValid()) {
       
    65             currentParent = currentParent.parent();
       
    66         } else {
       
    67             break;
       
    68         }
       
    69     }
       
    70     return valid;
       
    71 }
       
    72 
       
    73 bool HbTreeViewPrivate::isChild(const QModelIndex &index, const QModelIndex &parent) const
       
    74 {
       
    75     bool isChild = false;
       
    76     QModelIndex currentIndex = index;
       
    77     while (!isChild) {
       
    78         if (currentIndex.parent() == parent) {
       
    79             isChild = true;
       
    80         } else if (currentIndex.isValid()) {
       
    81             currentIndex = currentIndex.parent();
       
    82         } else {
       
    83             break;
       
    84         }
       
    85     }
       
    86     return isChild;
       
    87 }
       
    88 
       
    89 QModelIndex HbTreeViewPrivate::searchIndexUp( 
       
    90                             const   QModelIndex &index,
       
    91                             int     maxStepCount) const
       
    92 {
       
    93     Q_Q(const HbTreeView);
       
    94 
       
    95     QModelIndex root = q->rootIndex();
       
    96     int counter = 1;
       
    97 
       
    98     // previousIndex() returns invalid, if root found
       
    99     QModelIndex previousIndex = index;
       
   100     QModelIndex previousIndexTemp = mModelIterator->previousIndex(previousIndex);
       
   101     while (previousIndex.isValid() && counter < maxStepCount) {
       
   102         counter++;
       
   103         previousIndexTemp = mModelIterator->previousIndex(previousIndex);
       
   104         if (previousIndexTemp.isValid()) {
       
   105             previousIndex = previousIndexTemp;
       
   106         }
       
   107     }
       
   108     return previousIndex;
       
   109 }