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 "btsettingmodel_p.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 d = QSharedPointer<BtSettingModelPrivate>( new BtSettingModelPrivate( *this ) ); |
|
29 connectModelSignals(); |
|
30 } |
|
31 |
|
32 /*! |
|
33 This Constructor shares the private implementation of the setting model. |
|
34 */ |
|
35 BtSettingModel::BtSettingModel( const BtSettingModel &model, QObject *parent ) |
|
36 : QAbstractItemModel( parent ) |
|
37 { |
|
38 d = model.d; |
|
39 connectModelSignals(); |
|
40 } |
|
41 |
|
42 /*! |
|
43 Destructor. |
|
44 */ |
|
45 BtSettingModel::~BtSettingModel() |
|
46 { |
|
47 } |
|
48 |
|
49 /*! |
|
50 \reimp |
|
51 */ |
|
52 QModelIndex BtSettingModel::index( int row, int column, const QModelIndex &parent ) const |
|
53 { |
|
54 Q_UNUSED( parent ); |
|
55 if ( d->isValid( row, column ) ) { |
|
56 return createIndex( row, column, d.data() ); |
|
57 } |
|
58 // invalid row and column: |
|
59 return QModelIndex(); |
|
60 } |
|
61 |
|
62 /*! |
|
63 \reimp |
|
64 */ |
|
65 QModelIndex BtSettingModel::parent( const QModelIndex &child ) const |
|
66 { |
|
67 Q_UNUSED( child ); |
|
68 // root level, no parent. |
|
69 return QModelIndex(); |
|
70 } |
|
71 |
|
72 /*! |
|
73 \reimp |
|
74 */ |
|
75 int BtSettingModel::rowCount( const QModelIndex &parent ) const |
|
76 { |
|
77 Q_UNUSED( parent ); |
|
78 return d->rowCount(); |
|
79 } |
|
80 |
|
81 /*! |
|
82 \reimp |
|
83 */ |
|
84 int BtSettingModel::columnCount( const QModelIndex &parent ) const |
|
85 { |
|
86 Q_UNUSED( parent ); |
|
87 return d->columnCount(); |
|
88 } |
|
89 |
|
90 /*! |
|
91 \reimp |
|
92 */ |
|
93 QVariant BtSettingModel::data( const QModelIndex &index, int role ) const |
|
94 { |
|
95 QVariant val( QVariant::Invalid ); |
|
96 d.data()->data( val, index.row(), index.column(), role ); |
|
97 return val; |
|
98 } |
|
99 |
|
100 QMap<int, QVariant> BtSettingModel::itemData( const QModelIndex & index ) const |
|
101 { |
|
102 return d.data()->itemData( index.row(), index.column() ); |
|
103 } |
|
104 |
|
105 /*! |
|
106 emits dataChanged signal. |
|
107 */ |
|
108 void BtSettingModel::settingDataChanged( int row, void *parent ) |
|
109 { |
|
110 QModelIndex idx = createIndex( row, 0, parent ); |
|
111 emit dataChanged( idx, idx ); |
|
112 } |
|
113 |
|
114 /*! |
|
115 emits dataChanged signal. |
|
116 */ |
|
117 void BtSettingModel::settingDataChanged(int first, int last, void *parent ) |
|
118 { |
|
119 QModelIndex top = createIndex( first, 0, parent ); |
|
120 QModelIndex bottom = createIndex( last, 0, parent ); |
|
121 emit dataChanged( top, bottom ); |
|
122 } |
|
123 |
|
124 /*! |
|
125 connects all signals of private impl to slots of this |
|
126 */ |
|
127 void BtSettingModel::connectModelSignals() |
|
128 { |
|
129 bool ok = connect(d.data(), SIGNAL(settingDataChanged(int,void*)), SLOT(settingDataChanged(int,void*))); |
|
130 BTUI_ASSERT_X( ok, "BtSettingModel", "settingDataChanged can't connect" ); |
|
131 ok = connect(d.data(), SIGNAL(settingDataChanged(int,int,void*)), SLOT(settingDataChanged(int,int,void*))); |
|
132 BTUI_ASSERT_X( ok, "BtSettingModel", "settingDataChanged can't connect 2" ); |
|
133 } |
|