memspyui/ui/hb/src/memspyecomimplementationview.cpp
branchRCL_3
changeset 50 9b2cffad4b5e
equal deleted inserted replaced
49:f8280f3bfeb7 50:9b2cffad4b5e
       
     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:
       
    15  *  
       
    16  */
       
    17 
       
    18 #include "memspyecomimplementationview.h"
       
    19 #include "viewmanager.h"
       
    20 
       
    21 MemSpyEComImplementationModel::MemSpyEComImplementationModel(EngineWrapper &engine, int interfaceId, QObject *parent) :
       
    22     QAbstractListModel(parent),
       
    23     mInterfaceId(interfaceId),
       
    24     mEngine(engine),
       
    25     mData(engine.getEComImplementations(interfaceId))
       
    26 {
       
    27 }
       
    28 
       
    29 MemSpyEComImplementationModel::~MemSpyEComImplementationModel()
       
    30 {
       
    31     qDeleteAll(mData);
       
    32 }
       
    33     
       
    34 int MemSpyEComImplementationModel::rowCount(const QModelIndex &parent) const
       
    35 {
       
    36     Q_UNUSED(parent);
       
    37     return mData.count();
       
    38 }
       
    39     
       
    40 QVariant MemSpyEComImplementationModel::data(const QModelIndex &index, int role) const
       
    41 {
       
    42     if (role == Qt::DisplayRole) {
       
    43         const MemSpyEComImplementation* impl = mData.at(index.row());
       
    44         
       
    45         QStringList lines;
       
    46         lines << QString("0x%1").arg(impl->id(), 0, 16);
       
    47         lines << impl->name();
       
    48         
       
    49         return lines;
       
    50     }
       
    51     
       
    52     if (role == Qt::UserRole)
       
    53         return qVariantFromValue<void*>(mData.at(index.row()));
       
    54     
       
    55     return QVariant();
       
    56 }
       
    57 
       
    58 void MemSpyEComImplementationModel::refresh()
       
    59 {
       
    60     beginResetModel();
       
    61     QList<MemSpyEComImplementation*> data = mEngine.getEComImplementations(mInterfaceId);
       
    62     qDeleteAll(mData);
       
    63     mData = data;
       
    64     endResetModel();
       
    65 }
       
    66     
       
    67 
       
    68 void MemSpyEComImplementationView::initialize(const QVariantMap& params)
       
    69 {
       
    70     setTitle(tr("ECom Implementations"));
       
    71     
       
    72     mParentId = params["pid"].toInt();    
       
    73     mParentName = params["pname"].toString();
       
    74         
       
    75     MemSpyView::initialize(params);
       
    76     
       
    77     mModel = new MemSpyEComImplementationModel(mEngine, mParentId, this);
       
    78     mListView.setModel(mModel);
       
    79     
       
    80     connect(&mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemClicked(QModelIndex)));
       
    81 }
       
    82 
       
    83 void MemSpyEComImplementationView::itemClicked(const QModelIndex& index)
       
    84 {
       
    85     QVariantMap map;
       
    86     map.insert("implementation", index.data(Qt::UserRole));
       
    87     mViewManager.showView(EComImplementationDetailView, map);
       
    88 }
       
    89 
       
    90 void MemSpyEComImplementationView::refresh()
       
    91 { 
       
    92     mModel->refresh(); 
       
    93 }