perfapps/memspyui/ui/hb/src/memspyecomcategoryview.cpp
changeset 51 b048e15729d6
equal deleted inserted replaced
44:5db69f4c3d06 51:b048e15729d6
       
     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 "memspyecomcategoryview.h"
       
    19 #include "viewmanager.h"
       
    20 
       
    21 MemSpyEComCategoryModel::MemSpyEComCategoryModel(EngineWrapper &engine, QObject *parent) :
       
    22     QAbstractListModel(parent),
       
    23     mEngine(engine),
       
    24     mData(engine.getEComCategories())
       
    25 {
       
    26 }
       
    27 
       
    28 MemSpyEComCategoryModel::~MemSpyEComCategoryModel()
       
    29 {
       
    30     qDeleteAll(mData);
       
    31 }
       
    32     
       
    33 int MemSpyEComCategoryModel::rowCount(const QModelIndex &parent) const
       
    34 {
       
    35     Q_UNUSED(parent);
       
    36     return mData.count();
       
    37 }
       
    38     
       
    39 QVariant MemSpyEComCategoryModel::data(const QModelIndex &index, int role) const
       
    40 {
       
    41     if (role == Qt::DisplayRole) {
       
    42         const MemSpyEComCategory* cat = mData.at(index.row());
       
    43         
       
    44         QStringList lines;
       
    45         lines << cat->name();
       
    46         lines << QString("%1 interface(s)").arg(cat->interfaceCount());
       
    47         
       
    48         return lines;
       
    49     }
       
    50     
       
    51     if (role == Qt::UserRole)
       
    52         return mData.at(index.row())->id();
       
    53     
       
    54     return QVariant();
       
    55 }
       
    56 
       
    57 void MemSpyEComCategoryModel::refresh()
       
    58 {
       
    59     beginResetModel();
       
    60     QList<MemSpyEComCategory*> data = mEngine.getEComCategories();
       
    61     qDeleteAll(mData);
       
    62     mData = data;
       
    63     endResetModel();
       
    64 }
       
    65     
       
    66 
       
    67 void MemSpyEComCategoryView::initialize(const QVariantMap& params)
       
    68 {
       
    69     setTitle(tr("ECom Categories"));
       
    70     MemSpyView::initialize(params);
       
    71     
       
    72     mModel = new MemSpyEComCategoryModel(mEngine, this);
       
    73     mListView.setModel(mModel);
       
    74     
       
    75     connect(&mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemClicked(QModelIndex)));
       
    76 }
       
    77 
       
    78 void MemSpyEComCategoryView::itemClicked(const QModelIndex& index)
       
    79 {
       
    80     QVariantMap map;
       
    81     map.insert("pid", index.data(Qt::UserRole));
       
    82     map.insert("pname", index.data(Qt::DisplayRole).toStringList().at(0));
       
    83     mViewManager.showView(EComInterfaceView, map);
       
    84 }
       
    85 
       
    86 void MemSpyEComCategoryView::refresh()
       
    87 { 
       
    88     mModel->refresh(); 
       
    89 }