emailuis/nmhswidget/src/nmhswidgetlistmodel.cpp
changeset 75 47d84de1c893
child 76 38bf5461e270
equal deleted inserted replaced
72:64e38f08e49c 75:47d84de1c893
       
     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 #include <hbnamespace.h>
       
    19 #include <nmmessageenvelope.h>
       
    20 #include "nmhswidgetlistmodel.h"
       
    21 #include "nmhswidgetlistmodelitem.h"
       
    22 
       
    23 /*!
       
    24     \class NmHsWidgetListModel
       
    25     \brief The NmHsWidgetListModel class represents data model for message list.
       
    26     @alpha
       
    27 
       
    28     The NmHsWidgetListModel class uses NmHsWidgetListModelItem class to represent data returned in its'
       
    29     data method to get all information needed for one list row for a widget by calling the method
       
    30     once.
       
    31 */
       
    32 
       
    33 /*!
       
    34     Constructor
       
    35  */
       
    36 NmHsWidgetListModel::NmHsWidgetListModel(QObject *parent)
       
    37 :QStandardItemModel(parent)
       
    38 {
       
    39     NM_FUNCTION;
       
    40 }
       
    41 
       
    42 /*!
       
    43 	Destructor
       
    44  */
       
    45 NmHsWidgetListModel::~NmHsWidgetListModel()
       
    46 {
       
    47     NM_FUNCTION;
       
    48     
       
    49     clear();
       
    50 }
       
    51 
       
    52 /*!
       
    53     Returns data specified by \a index. Only Qt::DisplayRole is supported in \a role.
       
    54     The refresh method must have been called before this method can return any real data.
       
    55  */
       
    56 QVariant NmHsWidgetListModel::data(const QModelIndex &index, int role) const
       
    57 {
       
    58     NM_FUNCTION;
       
    59     
       
    60     QVariant qVariant;
       
    61     if (index.isValid() && Qt::DisplayRole == role) {
       
    62         NmHsWidgetListModelItem *item = static_cast<NmHsWidgetListModelItem*>(itemFromIndex(index));
       
    63         NmMessageEnvelope *mailbox = item->itemMetaData();
       
    64         qVariant = QVariant::fromValue(mailbox);
       
    65     }
       
    66     return qVariant;
       
    67 }
       
    68 
       
    69 /*!
       
    70     This refreshes the data of the model.
       
    71     NOTE: safe guard any call to this function with try-catch.
       
    72  */
       
    73 void NmHsWidgetListModel::refresh(
       
    74         QList<NmMessageEnvelope*> &envelopeList)
       
    75 {
       
    76     NM_FUNCTION;
       
    77     
       
    78     clear();
       
    79     foreach(NmMessageEnvelope *env, envelopeList){
       
    80        NmHsWidgetListModelItem *item = createMessageListModelItem(env);
       
    81        appendRow(item);
       
    82     }
       
    83 }
       
    84 
       
    85 
       
    86 /*!
       
    87     Create mailbox item
       
    88     \param mailbox
       
    89  */
       
    90 NmHsWidgetListModelItem* NmHsWidgetListModel::createMessageListModelItem(const NmMessageEnvelope* envelope)
       
    91 {
       
    92     NM_FUNCTION;
       
    93     
       
    94     NmMessageEnvelope *newMeta = new NmMessageEnvelope(*envelope);
       
    95     NmHsWidgetListModelItem *item = new NmHsWidgetListModelItem();
       
    96     item->setItemMetaData(newMeta);
       
    97     item->setData(Hb::StandardItem, Hb::ItemTypeRole);
       
    98     return item;
       
    99 }