locationpickerservice/src/hgwidgetdatamodel.cpp
branchRCL_3
changeset 17 1fc85118c3ae
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
       
     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: HgWidgetDataModel implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QBrush>
       
    19 #include <HbIcon>
       
    20 #include <hgwidgets/hgwidgets.h>
       
    21 #include <QPainter>
       
    22 
       
    23 #include "locationpickertypes.h"
       
    24 #include "hgwidgetdatamodel.h"
       
    25 #include "locationpickerproxymodel.h"
       
    26 
       
    27 const int MAPSTROKE(3);
       
    28 // ----------------------------------------------------------------------------
       
    29 // HgWidgetDataModel::HgWidgetDataModel()
       
    30 // ----------------------------------------------------------------------------
       
    31 HgWidgetDataModel::HgWidgetDataModel( LocationPickerProxyModel *aProxyModel, QObject *aParent )
       
    32     : QAbstractListModel(aParent),
       
    33       mImageType(ETypeHbIcon),
       
    34       mDefaultImage(KDummyImage),
       
    35       mUseLowResImages(false),
       
    36       mProxyModel(NULL)
       
    37 {
       
    38     mProxyModel  = aProxyModel;   
       
    39     
       
    40 }
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // HgWidgetDataModel::resetModel()
       
    44 // ----------------------------------------------------------------------------
       
    45 void HgWidgetDataModel::resetModel( LocationPickerProxyModel *aProxyModel )
       
    46 {   
       
    47     //reset and update
       
    48     mProxyModel = aProxyModel;
       
    49     reset();
       
    50     emit beginResetModel();
       
    51     emit endResetModel();
       
    52 }
       
    53 
       
    54 
       
    55 // ----------------------------------------------------------------------------
       
    56 // HgWidgetDataModel::~HgWidgetDataModel()
       
    57 // ----------------------------------------------------------------------------
       
    58 HgWidgetDataModel::~HgWidgetDataModel()
       
    59 {
       
    60 
       
    61 }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // HgWidgetDataModel::rowCount()
       
    65 // ----------------------------------------------------------------------------
       
    66 int HgWidgetDataModel::rowCount( const QModelIndex &aParent ) const
       
    67 {
       
    68     Q_UNUSED(aParent);
       
    69 
       
    70     return mProxyModel->rowCount(QModelIndex());
       
    71    
       
    72 }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // HgWidgetDataModel::data()
       
    76 // ----------------------------------------------------------------------------
       
    77 QVariant HgWidgetDataModel::data(const QModelIndex &aIndex, int aRole) const
       
    78 {   
       
    79     int row= aIndex.row();
       
    80     int col = aIndex.column();
       
    81     //get proxy model index
       
    82     QModelIndex proxyModelIndex = mProxyModel->index(row,col);
       
    83     QVariant returnValue = QVariant();
       
    84     if ( !aIndex.isValid() )
       
    85     {
       
    86         return returnValue;
       
    87     }
       
    88 
       
    89     if( row >= mProxyModel->rowCount(QModelIndex()) )
       
    90     {
       
    91         return returnValue;
       
    92     }
       
    93 
       
    94     switch ( aRole )
       
    95     {
       
    96         case HgWidget::HgVisibilityRole:
       
    97         {
       
    98             returnValue = true;
       
    99         }
       
   100         break;
       
   101         case Qt::DisplayRole:
       
   102         {
       
   103             QStringList displayText;
       
   104             QStringList adressDetail = mProxyModel->data(proxyModelIndex,Qt::DisplayRole).toStringList();
       
   105             QString displayString;
       
   106             if(!adressDetail[0].isEmpty())
       
   107             {
       
   108                 displayString = adressDetail[0]+KSeparator+KSpace+adressDetail[1];
       
   109             }
       
   110             else
       
   111             {
       
   112                 displayString = adressDetail[1];
       
   113             }
       
   114             QString text("");
       
   115             displayText <<displayString<<text;
       
   116             returnValue = displayText;
       
   117             break;
       
   118         }
       
   119         case Qt::DecorationRole:
       
   120         {
       
   121             //get icon name from data model
       
   122             QString iconName =  mProxyModel->data(proxyModelIndex,Qt::UserRole+1).toString();
       
   123             if (iconName.isEmpty()) 
       
   124             {
       
   125                 returnValue = mDefaultImage;
       
   126             }
       
   127             else 
       
   128             {   
       
   129                 QString adressType =  mProxyModel->data(proxyModelIndex,Qt::UserRole+2).toString();
       
   130                 QPixmap mapPixmap(iconName);
       
   131                 int mapWidth = mapPixmap.width();
       
   132                 int mapHeight = mapPixmap.height();
       
   133                 QBrush brush(Qt::black,Qt::SolidPattern);
       
   134                 QPainter painter;
       
   135                 painter.begin(&mapPixmap);
       
   136                 HbIcon adressTypeIcon(adressType);
       
   137                 //draw the adressType Icon over mapTile Icon
       
   138                 adressTypeIcon.paint(&painter,QRectF((mapPixmap.width()-adressTypeIcon.width()),0,adressTypeIcon.width(),adressTypeIcon.height()));
       
   139                 painter.fillRect(QRect(0,0,mapWidth,MAPSTROKE),brush);
       
   140                 painter.fillRect(QRect(0,mapHeight-MAPSTROKE,mapWidth,(mapHeight-MAPSTROKE)),brush);
       
   141                 painter.fillRect(QRect(0,0,MAPSTROKE,mapPixmap.height()),brush);
       
   142                 painter.fillRect(QRect((mapWidth-MAPSTROKE),0,mapWidth,mapHeight),brush);
       
   143                 painter.end();
       
   144                 QIcon landscape( mapPixmap );
       
   145                 HbIcon landscapeIcon(landscape);
       
   146                 returnValue = landscapeIcon;
       
   147             }
       
   148             break;
       
   149         }
       
   150         default:
       
   151             break;
       
   152         }
       
   153 
       
   154     return returnValue;
       
   155 }
       
   156 
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // HgWidgetDataModel::setImageDataType()
       
   160 // ----------------------------------------------------------------------------
       
   161 void HgWidgetDataModel::setImageDataType(TImageType type)
       
   162 {
       
   163     mImageType = type;
       
   164 }
       
   165 
       
   166 
       
   167