bluetoothengine/btui/btuimodel/btsettingmodel.cpp
author hgs
Fri, 03 Sep 2010 16:17:59 +0300
changeset 57 5ebadcda06cb
parent 42 b72428996822
permissions -rw-r--r--
201035_7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     1
/*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     3
* All rights reserved.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     8
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     9
* Initial Contributors:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    11
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    12
* Contributors:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    13
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    14
* Description: 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    15
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    16
*/
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    17
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    18
#include <btsettingmodel.h>
42
hgs
parents: 31
diff changeset
    19
#include "btsettingmodel_p.h"
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    20
#include "bluetoothuitrace.h"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    21
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    22
/*!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    23
    This Constructor creates new instances of model data structure.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    24
 */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    25
BtSettingModel::BtSettingModel( QObject *parent )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    26
    : QAbstractItemModel( parent )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    27
{
42
hgs
parents: 31
diff changeset
    28
   d = QSharedPointer<BtSettingModelPrivate>( new BtSettingModelPrivate( *this ) );
hgs
parents: 31
diff changeset
    29
   connectModelSignals();
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    30
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    32
/*!
42
hgs
parents: 31
diff changeset
    33
    This Constructor shares the private implementation of the setting model.
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    34
 */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    35
BtSettingModel::BtSettingModel( const BtSettingModel &model, QObject *parent )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    36
    : QAbstractItemModel( parent )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    37
{
42
hgs
parents: 31
diff changeset
    38
    d = model.d;
hgs
parents: 31
diff changeset
    39
    connectModelSignals();
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    40
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    41
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    42
/*!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    43
    Destructor.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    44
 */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    45
BtSettingModel::~BtSettingModel()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    46
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    47
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    48
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    49
/*!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    50
    \reimp
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    51
 */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    52
QModelIndex BtSettingModel::index( int row, int column, const QModelIndex &parent ) const
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    53
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    54
    Q_UNUSED( parent );
42
hgs
parents: 31
diff changeset
    55
    if ( d->isValid( row, column ) ) {
hgs
parents: 31
diff changeset
    56
        return createIndex( row, column, d.data() );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    57
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    58
    // invalid row and column:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    59
    return QModelIndex();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    60
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    61
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    62
/*!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    63
    \reimp
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    64
 */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    65
QModelIndex BtSettingModel::parent( const QModelIndex &child ) const
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    66
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    67
    Q_UNUSED( child );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    68
    // root level, no parent.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    69
    return QModelIndex();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    70
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    71
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    72
/*!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    73
    \reimp
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    74
 */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    75
int BtSettingModel::rowCount( const QModelIndex &parent ) const
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    76
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    77
    Q_UNUSED( parent );
42
hgs
parents: 31
diff changeset
    78
    return d->rowCount();
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    79
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    80
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    81
/*!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    82
    \reimp
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    83
 */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    84
int BtSettingModel::columnCount( const QModelIndex &parent ) const
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    85
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    86
    Q_UNUSED( parent );
42
hgs
parents: 31
diff changeset
    87
    return d->columnCount();
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    88
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    89
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    90
/*!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    91
    \reimp
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    92
 */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    93
QVariant BtSettingModel::data( const QModelIndex &index, int role ) const
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    94
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    95
    QVariant val( QVariant::Invalid );
42
hgs
parents: 31
diff changeset
    96
    d.data()->data( val, index.row(), index.column(), role );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    97
    return val;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    98
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    99
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   100
QMap<int, QVariant> BtSettingModel::itemData( const QModelIndex & index ) const
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   101
{
42
hgs
parents: 31
diff changeset
   102
    return d.data()->itemData( index.row(), index.column() );
hgs
parents: 31
diff changeset
   103
}
hgs
parents: 31
diff changeset
   104
hgs
parents: 31
diff changeset
   105
/*!
hgs
parents: 31
diff changeset
   106
    emits dataChanged signal.
hgs
parents: 31
diff changeset
   107
 */
hgs
parents: 31
diff changeset
   108
void BtSettingModel::settingDataChanged( int row, void *parent )
hgs
parents: 31
diff changeset
   109
{
hgs
parents: 31
diff changeset
   110
    QModelIndex idx = createIndex( row, 0, parent );
hgs
parents: 31
diff changeset
   111
    emit dataChanged( idx, idx );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   112
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   113
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   114
/*!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   115
    emits dataChanged signal.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   116
 */
42
hgs
parents: 31
diff changeset
   117
void BtSettingModel::settingDataChanged(int first, int last, void *parent )
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   118
    {
42
hgs
parents: 31
diff changeset
   119
    QModelIndex top = createIndex( first, 0, parent );
hgs
parents: 31
diff changeset
   120
    QModelIndex bottom = createIndex( last, 0, parent );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   121
    emit dataChanged( top, bottom );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   122
    }
42
hgs
parents: 31
diff changeset
   123
hgs
parents: 31
diff changeset
   124
/*!
hgs
parents: 31
diff changeset
   125
 connects all signals of private impl to slots of this
hgs
parents: 31
diff changeset
   126
 */
hgs
parents: 31
diff changeset
   127
void BtSettingModel::connectModelSignals()
hgs
parents: 31
diff changeset
   128
{
hgs
parents: 31
diff changeset
   129
    bool ok = connect(d.data(), SIGNAL(settingDataChanged(int,void*)), SLOT(settingDataChanged(int,void*)));
hgs
parents: 31
diff changeset
   130
    BTUI_ASSERT_X( ok, "BtSettingModel", "settingDataChanged can't connect" );
hgs
parents: 31
diff changeset
   131
    ok = connect(d.data(), SIGNAL(settingDataChanged(int,int,void*)), SLOT(settingDataChanged(int,int,void*)));
hgs
parents: 31
diff changeset
   132
    BTUI_ASSERT_X( ok, "BtSettingModel", "settingDataChanged can't connect 2" );
hgs
parents: 31
diff changeset
   133
}