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 |
#ifndef BTDEVICEMODEL_H
|
|
19 |
#define BTDEVICEMODEL_H
|
|
20 |
|
|
21 |
#include <qglobal.h>
|
|
22 |
#include <QAbstractItemModel>
|
|
23 |
#include <QSharedPointer>
|
|
24 |
#include <btuimodeltypes.h>
|
|
25 |
|
42
|
26 |
class BtDeviceModelPrivate;
|
31
|
27 |
|
|
28 |
/*!
|
|
29 |
\class BtDeviceModel
|
|
30 |
\brief The data model provided to Bluetooth UIs in QT
|
|
31 |
|
|
32 |
BtDeviceModel provides APIs for accessing the data of remote devices.
|
|
33 |
In addition, signals from this
|
|
34 |
model are provided for being informed of data update.
|
|
35 |
|
|
36 |
This model is in one dimension (n rows * 1 columns), i.e.,
|
|
37 |
|
|
38 |
row 0 ( a remote device)
|
|
39 |
row 1 ( another device)
|
|
40 |
...
|
|
41 |
|
|
42 |
The data in this model is non-modifiable from the user interface (except device
|
|
43 |
search may add a number of in-range devices temporarily) ,
|
|
44 |
determined by the characteristics of Bluetooth, the underline BT software
|
|
45 |
services and the BT application requirements.
|
|
46 |
|
|
47 |
Whenever feasible, the detailed description should contain a simple
|
|
48 |
example code example:
|
|
49 |
\code
|
|
50 |
// ...
|
|
51 |
\endcode
|
|
52 |
|
|
53 |
\sa \link model-view-programming.html Model/View Programming\endlink
|
|
54 |
*/
|
|
55 |
|
|
56 |
class BTUIMODEL_IMEXPORT BtDeviceModel : public QAbstractItemModel
|
|
57 |
{
|
|
58 |
Q_OBJECT
|
|
59 |
Q_ENUMS( DevDataRole DevMajorProperty AVDevMinorProperty PeripheralMinorProperty )
|
|
60 |
|
|
61 |
public:
|
|
62 |
|
|
63 |
// the roles for catogerizing Bluetooth device properties
|
|
64 |
enum DevDataRole {
|
|
65 |
NameAliasRole = Qt::DisplayRole, // QVariant::String, the name showing in UI
|
|
66 |
ReadableBdaddrRole = Qt::UserRole, // QString, the readable format of a BD_ADDR (BT Device address)
|
|
67 |
LastUsedTimeRole, // QDateTime
|
|
68 |
RssiRole, // QVariant::Int
|
|
69 |
MajorPropertyRole, // QVariant::Int, bits of DevMajorProperty
|
42
|
70 |
MinorPropertyRole, // QVariant::Int, bits of DevMinorProperty
|
31
|
71 |
CoDRole, // QVariant::Int, the value of Class of Device
|
42
|
72 |
SeqNumRole // sequence number indicating order in which device was found
|
31
|
73 |
};
|
|
74 |
|
|
75 |
public:
|
|
76 |
|
|
77 |
explicit BtDeviceModel( QObject *parent = 0 );
|
|
78 |
|
|
79 |
explicit BtDeviceModel( const BtDeviceModel &model, QObject *parent = 0 );
|
|
80 |
|
|
81 |
virtual ~BtDeviceModel();
|
|
82 |
|
|
83 |
bool searchDevice();
|
|
84 |
|
|
85 |
void cancelSearchDevice();
|
|
86 |
|
|
87 |
void removeTransientDevices();
|
|
88 |
|
57
|
89 |
int deviceCount(int majorProperty);
|
|
90 |
|
31
|
91 |
// from QAbstractItemModel
|
|
92 |
virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
|
|
93 |
|
|
94 |
virtual QModelIndex parent( const QModelIndex &child ) const;
|
|
95 |
|
|
96 |
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
|
|
97 |
|
|
98 |
virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
|
|
99 |
|
|
100 |
virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
|
|
101 |
|
|
102 |
virtual QMap<int, QVariant> itemData( const QModelIndex & index ) const;
|
|
103 |
|
57
|
104 |
virtual QModelIndexList match(const QModelIndex & start, int role,
|
|
105 |
const QVariant & value, int hits = 1, Qt::MatchFlags flags =
|
|
106 |
Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const;
|
|
107 |
|
31
|
108 |
signals:
|
|
109 |
|
|
110 |
void deviceSearchCompleted(int error);
|
42
|
111 |
|
|
112 |
private slots:
|
|
113 |
|
|
114 |
void deviceDataChanged( int row, void *parent );
|
31
|
115 |
|
42
|
116 |
void deviceDataChanged( int first, int last, void *parent );
|
|
117 |
|
|
118 |
void beginInsertDevices(int first, int last, void *parent);
|
|
119 |
void endInsertDevices();
|
|
120 |
|
|
121 |
void beginRemoveDevices(int first, int last, void *parent);
|
|
122 |
void endRemoveDevices();
|
|
123 |
|
|
124 |
void emitDeviceSearchCompleted( int error );
|
|
125 |
|
31
|
126 |
private:
|
|
127 |
|
42
|
128 |
void connectModelSignals();
|
57
|
129 |
|
31
|
130 |
private:
|
42
|
131 |
QSharedPointer<BtDeviceModelPrivate> d;
|
31
|
132 |
};
|
|
133 |
|
|
134 |
#endif // BTUIMODEL_H
|