|
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 <btdevicemodel.h> |
|
19 #include "btdevicedata.h" |
|
20 |
|
21 /*! |
|
22 This Constructor creates new instances of model data structure. |
|
23 */ |
|
24 BtDeviceModel::BtDeviceModel( QObject *parent ) |
|
25 : QAbstractItemModel( parent ) |
|
26 { |
|
27 mDeviceData = QSharedPointer<BtDeviceData>( new BtDeviceData( *this ) ); |
|
28 } |
|
29 |
|
30 /*! |
|
31 This Constructor shares the instances of model data structure with the |
|
32 given model. |
|
33 */ |
|
34 BtDeviceModel::BtDeviceModel( const BtDeviceModel &model, QObject *parent ) |
|
35 : QAbstractItemModel( parent ) |
|
36 { |
|
37 mDeviceData = model.mDeviceData; |
|
38 } |
|
39 |
|
40 /*! |
|
41 Destructor. |
|
42 */ |
|
43 BtDeviceModel::~BtDeviceModel() |
|
44 { |
|
45 } |
|
46 |
|
47 /*! |
|
48 Requests the model to searching Bluetooth devices. |
|
49 \return true if the request is accepted; false otherwise |
|
50 */ |
|
51 bool BtDeviceModel::searchDevice() |
|
52 { |
|
53 return mDeviceData->searchDevice(); |
|
54 } |
|
55 |
|
56 /*! |
|
57 Cancels a possible outstanding device search request. |
|
58 */ |
|
59 void BtDeviceModel::cancelSearchDevice() |
|
60 { |
|
61 mDeviceData->cancelSearchDevice(); |
|
62 } |
|
63 |
|
64 /*! |
|
65 Removes transient (not-in-registry) devices |
|
66 which were added as the result of device search. |
|
67 */ |
|
68 void BtDeviceModel::removeTransientDevices() |
|
69 { |
|
70 mDeviceData->removeTransientDevices(); |
|
71 } |
|
72 |
|
73 /*! |
|
74 \reimp |
|
75 */ |
|
76 QModelIndex BtDeviceModel::index( int row, int column, const QModelIndex &parent ) const |
|
77 { |
|
78 Q_UNUSED( parent ); |
|
79 if ( mDeviceData->isValid( row, column ) ) { |
|
80 return createIndex( row, column, mDeviceData.data() ); |
|
81 } |
|
82 // invalid row and column: |
|
83 return QModelIndex(); |
|
84 } |
|
85 |
|
86 /*! |
|
87 \reimp |
|
88 */ |
|
89 QModelIndex BtDeviceModel::parent( const QModelIndex &child ) const |
|
90 { |
|
91 Q_UNUSED( child ); |
|
92 // root level, no parent. |
|
93 return QModelIndex(); |
|
94 } |
|
95 |
|
96 /*! |
|
97 \reimp |
|
98 */ |
|
99 int BtDeviceModel::rowCount( const QModelIndex &parent ) const |
|
100 { |
|
101 Q_UNUSED( parent ); |
|
102 return mDeviceData->rowCount(); |
|
103 } |
|
104 |
|
105 /*! |
|
106 \reimp |
|
107 */ |
|
108 int BtDeviceModel::columnCount( const QModelIndex &parent ) const |
|
109 { |
|
110 Q_UNUSED( parent ); |
|
111 return mDeviceData->columnCount(); |
|
112 } |
|
113 |
|
114 /*! |
|
115 \reimp |
|
116 */ |
|
117 QVariant BtDeviceModel::data( const QModelIndex &index, int role ) const |
|
118 { |
|
119 QVariant val( QVariant::Invalid ); |
|
120 mDeviceData.data()->data( val, index.row(), index.column(), role ); |
|
121 return val; |
|
122 } |
|
123 |
|
124 QMap<int, QVariant> BtDeviceModel::itemData( const QModelIndex & index ) const |
|
125 { |
|
126 return mDeviceData.data()->itemData( index.row(), index.column() ); |
|
127 } |
|
128 |
|
129 /*! |
|
130 emits dataChanged signal. |
|
131 */ |
|
132 void BtDeviceModel::emitDataChanged( int row, int column, void *parent ) |
|
133 { |
|
134 QModelIndex idx = createIndex( row, column, parent ); |
|
135 emit dataChanged( idx, idx ); |
|
136 } |
|
137 |
|
138 void BtDeviceModel::emitDataChanged(const QModelIndex &top, const QModelIndex &bottom ) |
|
139 { |
|
140 emit dataChanged( top, bottom ); |
|
141 } |
|
142 |
|
143 /*! |
|
144 emits deviceSearchCompleted signal. |
|
145 */ |
|
146 void BtDeviceModel::emitdeviceSearchCompleted( int error ) |
|
147 { |
|
148 emit deviceSearchCompleted( error ); |
|
149 } |