bluetoothengine/btui/btuimodel/btdevicemodel.cpp
changeset 57 5ebadcda06cb
parent 42 b72428996822
--- a/bluetoothengine/btui/btuimodel/btdevicemodel.cpp	Fri Aug 06 16:43:21 2010 +0300
+++ b/bluetoothengine/btui/btuimodel/btdevicemodel.cpp	Fri Sep 03 16:17:59 2010 +0300
@@ -18,6 +18,7 @@
 #include <btdevicemodel.h>
 #include "btdevicemodel_p.h"
 #include "bluetoothuitrace.h"
+#include "btuidevtypemap.h"
 
 /*!
     This Constructor creates new instances of model data structure.
@@ -128,6 +129,53 @@
     return  d.data()->itemData( index.row(), index.column() );
 }
 
+/*!
+    \Reimplemented just to match the model based on major property
+ */
+QModelIndexList BtDeviceModel::match(const QModelIndex & start, int role,
+        const QVariant & value, int hits, Qt::MatchFlags flags ) const
+{
+    DevDataRole propRole = (DevDataRole)role;
+    if(BtDeviceModel::MajorPropertyRole == propRole) {
+        BtuiDevProperty::DevMajorProperty propValue = (BtuiDevProperty::DevMajorProperty)value.toInt();
+        QModelIndexList indexList;
+        int count = rowCount();
+        if (count && (start.row() < count)) {
+            for(int row = start.row(); row < count; row++) {
+                QModelIndex modelIndex = index(row,0);
+                int majorPropRole = data(modelIndex,BtDeviceModel::MajorPropertyRole).toInt();
+                if (majorPropRole & propValue) {
+                    indexList.append(modelIndex);
+                }
+            }
+        }
+        return indexList;
+    }
+    
+    return QAbstractItemModel::match(start, role, value, hits, flags);
+}
+
+
+/*!
+    Returns device count of devices having majorProperty.
+ */
+int BtDeviceModel::deviceCount(int majorProperty)
+{
+    int deviceCount = 0;
+    int count = rowCount();
+    BtuiDevProperty::DevMajorProperty propValue = (BtuiDevProperty::DevMajorProperty)majorProperty;
+    
+    for(int row = 0; row < count; row++) {
+        QModelIndex modelIndex = index(row,0);
+        int majorPropRole = data(modelIndex,BtDeviceModel::MajorPropertyRole).toInt();
+        if (majorPropRole & propValue) {
+            deviceCount++;
+        }
+    }
+
+    return deviceCount;
+}
+
 
 /*!
     emits dataChanged signal.