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 |
|
26 class BtDeviceModelPrivate; |
|
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 |
|
70 MinorPropertyRole, // QVariant::Int, bits of DevMinorProperty |
|
71 CoDRole, // QVariant::Int, the value of Class of Device |
|
72 SeqNumRole // sequence number indicating order in which device was found |
|
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 |
|
89 // from QAbstractItemModel |
|
90 virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; |
|
91 |
|
92 virtual QModelIndex parent( const QModelIndex &child ) const; |
|
93 |
|
94 virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; |
|
95 |
|
96 virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; |
|
97 |
|
98 virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; |
|
99 |
|
100 virtual QMap<int, QVariant> itemData( const QModelIndex & index ) const; |
|
101 |
|
102 signals: |
|
103 |
|
104 void deviceSearchCompleted(int error); |
|
105 |
|
106 private slots: |
|
107 |
|
108 void deviceDataChanged( int row, void *parent ); |
|
109 |
|
110 void deviceDataChanged( int first, int last, void *parent ); |
|
111 |
|
112 void beginInsertDevices(int first, int last, void *parent); |
|
113 void endInsertDevices(); |
|
114 |
|
115 void beginRemoveDevices(int first, int last, void *parent); |
|
116 void endRemoveDevices(); |
|
117 |
|
118 void emitDeviceSearchCompleted( int error ); |
|
119 |
|
120 private: |
|
121 |
|
122 void connectModelSignals(); |
|
123 |
|
124 private: |
|
125 QSharedPointer<BtDeviceModelPrivate> d; |
|
126 }; |
|
127 |
|
128 #endif // BTUIMODEL_H |
|