bluetoothengine/btui/btuimodel/btuimodel.h
changeset 29 48ae3789ce00
equal deleted inserted replaced
28:7e2761e776bd 29:48ae3789ce00
       
     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 BTUIMODEL_H
       
    19 #define BTUIMODEL_H
       
    20 
       
    21 
       
    22 #include <qglobal.h>
       
    23 #include <QAbstractItemModel>
       
    24 #include <QSharedPointer>
       
    25 
       
    26 class BtLocalSetting;
       
    27 class BtDeviceStore;
       
    28 
       
    29 // A data item in this model. For example, power state item consists 
       
    30 // of the information regarding the current Bluetooth power state.
       
    31 typedef QMap< int, QVariant > BtuiModelDataItem;
       
    32 
       
    33 // A category of the model data for specific group
       
    34 typedef QList< BtuiModelDataItem > BtuiModelDataSource;
       
    35 
       
    36 #ifdef BUILD_BTUIMODEL
       
    37 #define BTUIMODEL_IMEXPORT Q_DECL_EXPORT
       
    38 #else
       
    39 #define BTUIMODEL_IMEXPORT Q_DECL_IMPORT
       
    40 #endif
       
    41 
       
    42 /*!
       
    43     \class BtuiModel
       
    44     \brief The data model provided to Bluetooth UIs in QT
       
    45 
       
    46     BtuiModel provides APIs for accessing certain BT data, such as local Bluetooth
       
    47     settings and the properties of remote BT devices. In addition, signals from this
       
    48     model are provided for being informed of data update. 
       
    49     
       
    50     This model is in two dimension (2 rows * n columns), i.e.,
       
    51     
       
    52     row 0 (BT local setting)
       
    53           col 0 (local device name)
       
    54           col 1 (power state)
       
    55           ...
       
    56     row 1 (remote devices)
       
    57           col 0 ( a remote device)
       
    58           col 1 ( another device)
       
    59           ...
       
    60     
       
    61     The data in this model is non-modifiable from the user interface (except device
       
    62     search may add a number of in-range devices temporarily) , 
       
    63     determined by the characteristics of Bluetooth, the underline BT software 
       
    64     services and the BT application requirements. 
       
    65     
       
    66     Whenever feasible, the detailed description should contain a simple
       
    67     example code example:
       
    68     \code
       
    69     // ...
       
    70     \endcode
       
    71 
       
    72     \sa \link model-view-programming.html Model/View Programming\endlink
       
    73  */
       
    74 
       
    75 class BTUIMODEL_IMEXPORT BtuiModel : public QAbstractItemModel
       
    76 {
       
    77     Q_OBJECT
       
    78     Q_ENUMS( RowId LocalSettingCol LocalSettingDataRole )
       
    79 
       
    80 public:
       
    81     
       
    82     /**
       
    83      * The parent row identifier of data model. Data in this model is grouped into
       
    84      * two categories: the local Bluetooth settings and the remote device 
       
    85      * database. The data of each category is stored in multiple 
       
    86      * rows of a specified row.
       
    87      */
       
    88     enum RowId {
       
    89         LocalSettingRow = 0,
       
    90         RemoteDeviceRow = 1,
       
    91         ModelRowCount = 2
       
    92     };
       
    93     //Q_DECLARE_FLAGS(Rows, BtuiModelRow)
       
    94 
       
    95     /**
       
    96      * child row identifiers of the local setting row
       
    97      */
       
    98     enum LocalSettingCol {
       
    99         BluetoothNameCol = 0,
       
   100         PowerStateCol ,
       
   101         VisibilityCol,
       
   102         SapModeCol,
       
   103         AllowedInOfflineCol,
       
   104         LocalSettingColCount,
       
   105     };
       
   106     //Q_DECLARE_FLAGS(BtuiModelLocalSettings, BtuiModelLocalSettingColumn)
       
   107     
       
   108     /**
       
   109      * Data roles that the items in the local setting row
       
   110      */
       
   111     enum LocalSettingDataRole {
       
   112         SettingIdentity = Qt::WhatsThisRole,
       
   113         settingDisplay = Qt::DisplayRole,
       
   114         SettingValue = Qt::EditRole,
       
   115         SettingValueParam = Qt::UserRole + 1,  // e.g., temp visibility time     
       
   116     };
       
   117 
       
   118 public:
       
   119     
       
   120     explicit BtuiModel( QObject *parent = 0 );
       
   121     
       
   122     explicit BtuiModel( const BtuiModel &model, QObject *parent = 0 );
       
   123     
       
   124     virtual ~BtuiModel();
       
   125     
       
   126     // from QAbstractItemModel
       
   127     virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
       
   128     
       
   129     virtual QModelIndex parent( const QModelIndex &child ) const;
       
   130     
       
   131     virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
       
   132     
       
   133     virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
       
   134     
       
   135     virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
       
   136 
       
   137     virtual QMap<int, QVariant> itemData( const QModelIndex & index ) const;
       
   138     
       
   139 public slots:
       
   140     
       
   141     void btDataChanged(int row, int column, void *parent );
       
   142     
       
   143 private:
       
   144     QSharedPointer<BtLocalSetting> mLocalSetting;
       
   145 };
       
   146 
       
   147 //Q_DECLARE_OPERATORS_FOR_FLAGS(BtuiModel::Rows)
       
   148 
       
   149 Q_DECLARE_METATYPE(BtuiModelDataItem)
       
   150 Q_DECLARE_METATYPE(BtuiModelDataSource)
       
   151 
       
   152 #endif // BTUIMODEL_H