31
|
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>
|
42
|
19 |
#include "btdevicemodel_p.h"
|
|
20 |
#include "bluetoothuitrace.h"
|
31
|
21 |
|
|
22 |
/*!
|
|
23 |
This Constructor creates new instances of model data structure.
|
|
24 |
*/
|
|
25 |
BtDeviceModel::BtDeviceModel( QObject *parent )
|
|
26 |
: QAbstractItemModel( parent )
|
|
27 |
{
|
42
|
28 |
d = QSharedPointer<BtDeviceModelPrivate>( new BtDeviceModelPrivate( *this ) );
|
|
29 |
connectModelSignals();
|
31
|
30 |
}
|
|
31 |
|
|
32 |
/*!
|
42
|
33 |
This Constructor shares the private implementation of the device model.
|
31
|
34 |
*/
|
|
35 |
BtDeviceModel::BtDeviceModel( const BtDeviceModel &model, QObject *parent )
|
|
36 |
: QAbstractItemModel( parent )
|
|
37 |
{
|
42
|
38 |
d = model.d;
|
|
39 |
connectModelSignals();
|
31
|
40 |
}
|
|
41 |
|
|
42 |
/*!
|
|
43 |
Destructor.
|
|
44 |
*/
|
|
45 |
BtDeviceModel::~BtDeviceModel()
|
|
46 |
{
|
|
47 |
}
|
|
48 |
|
|
49 |
/*!
|
|
50 |
Requests the model to searching Bluetooth devices.
|
|
51 |
\return true if the request is accepted; false otherwise
|
|
52 |
*/
|
|
53 |
bool BtDeviceModel::searchDevice()
|
|
54 |
{
|
42
|
55 |
return d->searchDevice();
|
31
|
56 |
}
|
|
57 |
|
|
58 |
/*!
|
|
59 |
Cancels a possible outstanding device search request.
|
|
60 |
*/
|
|
61 |
void BtDeviceModel::cancelSearchDevice()
|
|
62 |
{
|
42
|
63 |
d->cancelSearchDevice();
|
31
|
64 |
}
|
|
65 |
|
|
66 |
/*!
|
|
67 |
Removes transient (not-in-registry) devices
|
|
68 |
which were added as the result of device search.
|
|
69 |
*/
|
|
70 |
void BtDeviceModel::removeTransientDevices()
|
|
71 |
{
|
42
|
72 |
d->removeTransientDevices();
|
31
|
73 |
}
|
|
74 |
|
|
75 |
/*!
|
|
76 |
\reimp
|
|
77 |
*/
|
|
78 |
QModelIndex BtDeviceModel::index( int row, int column, const QModelIndex &parent ) const
|
|
79 |
{
|
|
80 |
Q_UNUSED( parent );
|
42
|
81 |
if ( d->isValid( row, column ) ) {
|
|
82 |
return createIndex( row, column, d.data() );
|
31
|
83 |
}
|
|
84 |
// invalid row and column:
|
|
85 |
return QModelIndex();
|
|
86 |
}
|
|
87 |
|
|
88 |
/*!
|
|
89 |
\reimp
|
|
90 |
*/
|
|
91 |
QModelIndex BtDeviceModel::parent( const QModelIndex &child ) const
|
|
92 |
{
|
|
93 |
Q_UNUSED( child );
|
|
94 |
// root level, no parent.
|
|
95 |
return QModelIndex();
|
|
96 |
}
|
|
97 |
|
|
98 |
/*!
|
|
99 |
\reimp
|
|
100 |
*/
|
|
101 |
int BtDeviceModel::rowCount( const QModelIndex &parent ) const
|
|
102 |
{
|
|
103 |
Q_UNUSED( parent );
|
42
|
104 |
return d->rowCount();
|
31
|
105 |
}
|
|
106 |
|
|
107 |
/*!
|
|
108 |
\reimp
|
|
109 |
*/
|
|
110 |
int BtDeviceModel::columnCount( const QModelIndex &parent ) const
|
|
111 |
{
|
|
112 |
Q_UNUSED( parent );
|
42
|
113 |
return d->columnCount();
|
31
|
114 |
}
|
|
115 |
|
|
116 |
/*!
|
|
117 |
\reimp
|
|
118 |
*/
|
|
119 |
QVariant BtDeviceModel::data( const QModelIndex &index, int role ) const
|
|
120 |
{
|
|
121 |
QVariant val( QVariant::Invalid );
|
42
|
122 |
d.data()->data( val, index.row(), index.column(), role );
|
31
|
123 |
return val;
|
|
124 |
}
|
|
125 |
|
|
126 |
QMap<int, QVariant> BtDeviceModel::itemData( const QModelIndex & index ) const
|
|
127 |
{
|
42
|
128 |
return d.data()->itemData( index.row(), index.column() );
|
|
129 |
}
|
|
130 |
|
|
131 |
|
|
132 |
/*!
|
|
133 |
emits dataChanged signal.
|
|
134 |
*/
|
|
135 |
void BtDeviceModel::deviceDataChanged( int row, void *parent )
|
|
136 |
{
|
|
137 |
QModelIndex idx = createIndex( row, 0, parent );
|
|
138 |
emit dataChanged( idx, idx );
|
31
|
139 |
}
|
|
140 |
|
|
141 |
/*!
|
|
142 |
emits dataChanged signal.
|
|
143 |
*/
|
42
|
144 |
void BtDeviceModel::deviceDataChanged( int first, int last, void *parent )
|
31
|
145 |
{
|
42
|
146 |
QModelIndex top = createIndex( first, 0, parent );
|
|
147 |
QModelIndex bottom = createIndex( last, 0, parent );
|
|
148 |
emit dataChanged( top, bottom );
|
|
149 |
}
|
|
150 |
|
|
151 |
/*!
|
|
152 |
call beginInsertRows.
|
|
153 |
*/
|
|
154 |
void BtDeviceModel::beginInsertDevices(int first, int last, void *parent)
|
|
155 |
{
|
|
156 |
Q_UNUSED( parent);
|
|
157 |
beginInsertRows(QModelIndex(), first, last);
|
31
|
158 |
}
|
|
159 |
|
42
|
160 |
/*!
|
|
161 |
calls endInsertRows.
|
|
162 |
*/
|
|
163 |
void BtDeviceModel::BtDeviceModel::endInsertDevices()
|
|
164 |
{
|
|
165 |
endInsertRows();
|
|
166 |
}
|
|
167 |
|
|
168 |
/*!
|
|
169 |
calls beginRemoveRows.
|
|
170 |
*/
|
|
171 |
void BtDeviceModel::beginRemoveDevices(int first, int last, void *parent)
|
|
172 |
{
|
|
173 |
Q_UNUSED( parent);
|
|
174 |
beginRemoveRows(QModelIndex(), first, last);
|
|
175 |
}
|
|
176 |
|
|
177 |
/*!
|
|
178 |
calls endRemoveRows.
|
|
179 |
*/
|
|
180 |
void BtDeviceModel::endRemoveDevices()
|
|
181 |
{
|
|
182 |
endRemoveRows();
|
|
183 |
}
|
31
|
184 |
|
|
185 |
/*!
|
|
186 |
emits deviceSearchCompleted signal.
|
|
187 |
*/
|
42
|
188 |
void BtDeviceModel::emitDeviceSearchCompleted( int error )
|
31
|
189 |
{
|
|
190 |
emit deviceSearchCompleted( error );
|
|
191 |
}
|
42
|
192 |
|
|
193 |
/*!
|
|
194 |
connects all signals of private impl to slots of this
|
|
195 |
*/
|
|
196 |
void BtDeviceModel::connectModelSignals()
|
|
197 |
{
|
|
198 |
bool ok = connect(d.data(), SIGNAL(deviceDataChanged(int,void*)), SLOT(deviceDataChanged(int,void*)));
|
|
199 |
BTUI_ASSERT_X( ok, "BtDeviceModel", "deviceDataChanged can't connect" );
|
|
200 |
ok = connect(d.data(), SIGNAL(deviceDataChanged(int,int,void*)), SLOT(deviceDataChanged(int,int,void*)));
|
|
201 |
BTUI_ASSERT_X( ok, "BtDeviceModel", "deviceDataChanged can't connect 2" );
|
|
202 |
ok = connect(d.data(), SIGNAL(beginInsertDevices(int,int,void*)), SLOT(beginInsertDevices(int,int,void*)));
|
|
203 |
BTUI_ASSERT_X( ok, "BtDeviceModel", "beginInsertDevices can't connect" );
|
|
204 |
ok = connect(d.data(), SIGNAL(endInsertDevices()), SLOT(endInsertDevices()));
|
|
205 |
BTUI_ASSERT_X( ok, "BtDeviceModel", "endInsertDevices can't connect" );
|
|
206 |
ok = connect(d.data(), SIGNAL(beginRemoveDevices(int,int,void*)), SLOT(beginRemoveDevices(int,int,void*)));
|
|
207 |
BTUI_ASSERT_X( ok, "BtDeviceModel", "beginRemoveDevices can't connect" );
|
|
208 |
ok = connect(d.data(), SIGNAL(endRemoveDevices()), SLOT(endRemoveDevices()));
|
|
209 |
BTUI_ASSERT_X( ok, "BtDeviceModel", "endRemoveDevices can't connect" );
|
|
210 |
ok = connect(d.data(), SIGNAL(deviceSearchCompleted(int)), SLOT(emitDeviceSearchCompleted(int)));
|
|
211 |
BTUI_ASSERT_X( ok, "BtDeviceModel", "emitDeviceSearchCompleted can't connect" );
|
|
212 |
}
|