memspyui/ui/hb/src/memspykernelobjecttypeview.cpp
changeset 51 b048e15729d6
parent 44 5db69f4c3d06
child 52 36d60d12b4af
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 <QStringListModel>
       
    19 
       
    20 #include "memspykernelobjecttypeview.h"
       
    21 #include "viewmanager.h"
       
    22 
       
    23 MemSpyKernelObjectTypeModel::MemSpyKernelObjectTypeModel(EngineWrapper &engine, QObject *parent) :
       
    24 	QAbstractListModel(parent),
       
    25 	mObjectTypes(engine.getKernelObjectTypes())
       
    26 {
       
    27     mKernelObjectNames << "Threads" << "Processes" << "Chunks" << "Libraries" <<
       
    28         "Semaphores" << "Mutexes" << "Timers" << "Servers" << "Sessions" << "Logical Devices" <<
       
    29         "Physical Devices" << "Logical Channels" << "Change Notifiers" << "Undertakers" <<
       
    30         "Message Queues" << "Property Refs." << "Conditional Vars.";
       
    31 }
       
    32 
       
    33 MemSpyKernelObjectTypeModel::~MemSpyKernelObjectTypeModel()
       
    34 {
       
    35 	qDeleteAll(mObjectTypes);
       
    36 }
       
    37 	
       
    38 int MemSpyKernelObjectTypeModel::rowCount(const QModelIndex &parent) const
       
    39 {
       
    40 	Q_UNUSED(parent);
       
    41 	return mObjectTypes.count();
       
    42 }
       
    43 	
       
    44 QVariant MemSpyKernelObjectTypeModel::data(const QModelIndex &index, int role) const
       
    45 {
       
    46 	if (role == Qt::DisplayRole) {
       
    47 		QStringList lines;
       
    48 		lines << mKernelObjectNames.at(index.row());
       
    49 		lines << QString("%1, %2").
       
    50 			arg(tr("%n item(s)", "", mObjectTypes.at(index.row())->count())).
       
    51 			arg(formatSize(mObjectTypes.at(index.row())->size()));
       
    52 		
       
    53 		return lines;
       
    54 	}
       
    55 	
       
    56 	if (role == Qt::UserRole)
       
    57 		return mObjectTypes.at(index.row())->id();
       
    58 	
       
    59 	return QVariant();
       
    60 }
       
    61 
       
    62 QString MemSpyKernelObjectTypeModel::formatSize(qint64 size) const
       
    63 {
       
    64 	// If < 1000K
       
    65 	if  (size < 1024000)
       
    66 		return QString("%1K").arg(size ? qBound<int>(1, (size + 512) >> 10, 999) : 0);
       
    67 	
       
    68 	// larger than 1M
       
    69 	double sizeInM = size / 1048576.;
       
    70 	return sizeInM >= 1000 ?
       
    71 		QString("%1G").arg(qMax<double>(1, sizeInM / 1024), 0, 'f', 1) :
       
    72 		QString("%1M").arg(qBound<double>(1, sizeInM, 999.9), 0, 'f', 1);
       
    73 }
       
    74 
       
    75 void MemSpyKernelObjectTypeView::initialize(const QVariantMap& params)
       
    76 {
       
    77 	setTitle(tr("Kernel Objects"));
       
    78 		
       
    79 	MemSpyView::initialize(params);
       
    80 			
       
    81 	mListView.setModel(new MemSpyKernelObjectTypeModel(mEngine, this));
       
    82 	
       
    83 	connect(&mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemClicked(QModelIndex)));
       
    84 }
       
    85 
       
    86 void MemSpyKernelObjectTypeView::itemClicked(const QModelIndex& index)
       
    87 {
       
    88 	QVariantMap map;
       
    89 	map.insert("type", index.row());
       
    90     mViewManager.showView(KernelObjectView, map);
       
    91 }
       
    92