phoneuis/bubblemanager2/bubblecore/src/bubbleparticipantlistmodel.cpp
changeset 21 92ab7f8d0eab
child 22 6bb1b21d2484
equal deleted inserted replaced
4:c84cf270c54f 21:92ab7f8d0eab
       
     1 /*
       
     2 * Copyright (c) 2009 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: Model for conference participant list.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtCore>
       
    19 #include "bubbleparticipantlistmodel.h"
       
    20 
       
    21 class Participant
       
    22 {
       
    23 public:
       
    24     int mBubbleId;
       
    25     QString mName;
       
    26     int mState;
       
    27 
       
    28 public:
       
    29     Participant(int bubbleId, const QString &name, int state);
       
    30 
       
    31 };
       
    32 
       
    33 Participant::Participant(int bubbleId, const QString &name, int state) :
       
    34     mBubbleId(bubbleId), mName(name), mState(state)
       
    35 {
       
    36 }
       
    37 
       
    38 
       
    39 BubbleParticipantListModel::BubbleParticipantListModel()
       
    40 {
       
    41 }
       
    42 
       
    43 BubbleParticipantListModel::~BubbleParticipantListModel()
       
    44 {
       
    45     qDeleteAll(mParticipants);
       
    46 }
       
    47 
       
    48 int BubbleParticipantListModel::rowCount(const QModelIndex &parent) const
       
    49 {
       
    50     Q_UNUSED(parent);
       
    51     return mParticipants.count();
       
    52 }
       
    53 
       
    54 QVariant BubbleParticipantListModel::data(
       
    55     const QModelIndex &index,
       
    56     int role ) const
       
    57 {
       
    58     Participant *player = mParticipants.at(index.row());
       
    59 
       
    60     if (role == Qt::DisplayRole) {
       
    61         return player->mName;
       
    62     } else if (role == Qt::DecorationRole) {
       
    63         return player->mState;
       
    64     } else {
       
    65         return QVariant();
       
    66     }
       
    67 }
       
    68 
       
    69 void BubbleParticipantListModel::addParticipant(
       
    70     int bubbleId,
       
    71     const QString &name,
       
    72     int state )
       
    73 {
       
    74     Participant* p = new Participant(bubbleId,name,state);
       
    75     mParticipants.append(p);
       
    76 }
       
    77 
       
    78 int BubbleParticipantListModel::bubbleId(int row)
       
    79 {
       
    80     if (mParticipants.count()>=row) {
       
    81         return mParticipants.at(row)->mBubbleId;
       
    82     } else {
       
    83         return -1;
       
    84     }
       
    85 }
       
    86 
       
    87 void BubbleParticipantListModel::reset()
       
    88 {
       
    89     qDeleteAll(mParticipants);
       
    90     mParticipants.clear();
       
    91 }
       
    92