bluetoothengine/btui/btuimodel/btuimodel.cpp
changeset 33 837dcc42fd6a
parent 19 43824b19ee35
child 37 91746b151f97
equal deleted inserted replaced
19:43824b19ee35 33:837dcc42fd6a
     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 "btuimodel.h"
       
    19 #include "btlocalsetting.h"
       
    20 
       
    21 /*!
       
    22     This Constructor creates new instances of model data structure.
       
    23  */
       
    24 BtuiModel::BtuiModel( QObject *parent )
       
    25     : QAbstractItemModel( parent )
       
    26 {
       
    27    mLocalSetting = QSharedPointer<BtLocalSetting>( new BtLocalSetting( *this ) );
       
    28    bool b = connect( mLocalSetting.data(), SIGNAL(settingDataChanged(int,int,void*)), this, SLOT(btDataChanged(int,int,void*)));
       
    29    Q_ASSERT( b );
       
    30 }
       
    31 
       
    32 /*!
       
    33     This Constructor shares the instances of model data structure with the
       
    34     given model.
       
    35  */
       
    36 BtuiModel::BtuiModel( const BtuiModel &model, QObject *parent )
       
    37     : QAbstractItemModel( parent )
       
    38 {
       
    39     mLocalSetting = model.mLocalSetting;
       
    40     bool b = connect( mLocalSetting.data(), SIGNAL(settingDataChanged(int,int,void*)), this, SLOT(btDataChanged(int,int,void*)));
       
    41     Q_ASSERT( b );
       
    42 }
       
    43 
       
    44 /*!
       
    45     Destructor.
       
    46  */
       
    47 BtuiModel::~BtuiModel()
       
    48 {
       
    49 }
       
    50 
       
    51 /*!
       
    52     \reimp
       
    53  */
       
    54 QModelIndex BtuiModel::index( int row, int column, const QModelIndex &parent ) const
       
    55 {
       
    56     Q_UNUSED( parent );
       
    57     if ( row == LocalSettingRow
       
    58          && mLocalSetting->isValid( column ) ) {
       
    59         // local setting data:
       
    60         return createIndex( row, column, mLocalSetting.data() );
       
    61         }
       
    62     else if ( row == RemoteDeviceRow ) {
       
    63     
       
    64     }
       
    65     // invalid row and column:
       
    66     return QModelIndex();
       
    67 }
       
    68 
       
    69 /*!
       
    70     \reimp
       
    71  */
       
    72 QModelIndex BtuiModel::parent( const QModelIndex &child ) const
       
    73 {
       
    74     Q_UNUSED( child );
       
    75     // root level, no parent.
       
    76     return QModelIndex();
       
    77 }
       
    78 
       
    79 /*!
       
    80     \reimp
       
    81  */
       
    82 int BtuiModel::rowCount( const QModelIndex &parent ) const
       
    83 {
       
    84     Q_UNUSED( parent );
       
    85     return ModelRowCount;
       
    86 }
       
    87 
       
    88 /*!
       
    89     \reimp
       
    90  */
       
    91 int BtuiModel::columnCount( const QModelIndex &parent ) const
       
    92 {
       
    93     if ( parent.row() == LocalSettingRow 
       
    94          && mLocalSetting->isValid( parent.column() ) ) {
       
    95         // local setting data:
       
    96         return mLocalSetting->itemCount();
       
    97         }
       
    98     else if ( parent.row() == RemoteDeviceRow ) {
       
    99     }
       
   100     return 0;
       
   101 }
       
   102 
       
   103 /*!
       
   104     \reimp
       
   105  */
       
   106 QVariant BtuiModel::data( const QModelIndex &index, int role ) const
       
   107 {
       
   108     QVariant val( QVariant::Invalid );
       
   109     if ( index.row() == LocalSettingRow ) {
       
   110         mLocalSetting.data()->data( val, index.column(), role );
       
   111         }
       
   112     else if ( index.row() == RemoteDeviceRow ) {
       
   113     }
       
   114     return val;
       
   115 }
       
   116 
       
   117 QMap<int, QVariant> BtuiModel::itemData( const QModelIndex & index ) const
       
   118 {
       
   119     if ( index.row() == LocalSettingRow ) {
       
   120         mLocalSetting.data()->itemData( index.column() );
       
   121         }
       
   122     else if ( index.row() == RemoteDeviceRow ) {
       
   123     }
       
   124     return QMap<int, QVariant>();
       
   125 }
       
   126 
       
   127 /*!
       
   128     Slot for receiving notification of changes from the data source.
       
   129     Forward the notification using dataChanged signal.
       
   130  */
       
   131 void BtuiModel::btDataChanged( int row, int column, void *parent )
       
   132 {
       
   133     (void) parent;
       
   134     QModelIndex idx = createIndex( row, column, parent );
       
   135     emit dataChanged( idx, idx );
       
   136 }
       
   137 
       
   138