bluetoothengine/btui/btuimodel/btsettingmodel.cpp
changeset 31 a0ea99b6fa53
child 41 0b2439c3e397
equal deleted inserted replaced
30:df7a93ede42e 31:a0ea99b6fa53
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <btsettingmodel.h>
       
    19 #include "btlocalsetting.h"
       
    20 #include "bluetoothuitrace.h"
       
    21 
       
    22 /*!
       
    23     This Constructor creates new instances of model data structure.
       
    24  */
       
    25 BtSettingModel::BtSettingModel( QObject *parent )
       
    26     : QAbstractItemModel( parent )
       
    27 {
       
    28    mLocalSetting = QSharedPointer<BtLocalSetting>( new BtLocalSetting( *this ) );
       
    29 }
       
    30 
       
    31 /*!
       
    32     This Constructor shares the instances of model data structure with the
       
    33     given model.
       
    34  */
       
    35 BtSettingModel::BtSettingModel( const BtSettingModel &model, QObject *parent )
       
    36     : QAbstractItemModel( parent )
       
    37 {
       
    38     mLocalSetting = model.mLocalSetting;
       
    39 }
       
    40 
       
    41 /*!
       
    42     Destructor.
       
    43  */
       
    44 BtSettingModel::~BtSettingModel()
       
    45 {
       
    46 }
       
    47 
       
    48 /*!
       
    49     \reimp
       
    50  */
       
    51 QModelIndex BtSettingModel::index( int row, int column, const QModelIndex &parent ) const
       
    52 {
       
    53     Q_UNUSED( parent );
       
    54     if ( mLocalSetting->isValid( row, column ) ) {
       
    55         return createIndex( row, column, mLocalSetting.data() );
       
    56     }
       
    57     // invalid row and column:
       
    58     return QModelIndex();
       
    59 }
       
    60 
       
    61 /*!
       
    62     \reimp
       
    63  */
       
    64 QModelIndex BtSettingModel::parent( const QModelIndex &child ) const
       
    65 {
       
    66     Q_UNUSED( child );
       
    67     // root level, no parent.
       
    68     return QModelIndex();
       
    69 }
       
    70 
       
    71 /*!
       
    72     \reimp
       
    73  */
       
    74 int BtSettingModel::rowCount( const QModelIndex &parent ) const
       
    75 {
       
    76     Q_UNUSED( parent );
       
    77     return mLocalSetting->rowCount();
       
    78 }
       
    79 
       
    80 /*!
       
    81     \reimp
       
    82  */
       
    83 int BtSettingModel::columnCount( const QModelIndex &parent ) const
       
    84 {
       
    85     Q_UNUSED( parent );
       
    86     return mLocalSetting->columnCount();
       
    87 }
       
    88 
       
    89 /*!
       
    90     \reimp
       
    91  */
       
    92 QVariant BtSettingModel::data( const QModelIndex &index, int role ) const
       
    93 {
       
    94     QVariant val( QVariant::Invalid );
       
    95     mLocalSetting.data()->data( val, index.row(), index.column(), role );
       
    96     return val;
       
    97 }
       
    98 
       
    99 QMap<int, QVariant> BtSettingModel::itemData( const QModelIndex & index ) const
       
   100 {
       
   101     return mLocalSetting.data()->itemData( index.row(), index.column() );
       
   102 }
       
   103 
       
   104 /*!
       
   105     emits dataChanged signal.
       
   106  */
       
   107 void BtSettingModel::emitDataChanged( int row, int column, void *parent )
       
   108 {
       
   109     QModelIndex idx = createIndex( row, column, parent );
       
   110     emit dataChanged( idx, idx );
       
   111 }
       
   112 
       
   113 void BtSettingModel::emitDataChanged(const QModelIndex &top, const QModelIndex &bottom )
       
   114     {
       
   115     emit dataChanged( top, bottom );
       
   116     }