51
|
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 "memspyserverview.h"
|
|
19 |
#include "viewmanager.h"
|
|
20 |
|
|
21 |
MemSpyServerModel::MemSpyServerModel(EngineWrapper &engine, QObject *parent) :
|
|
22 |
QAbstractListModel(parent),
|
|
23 |
mEngine(engine),
|
|
24 |
mServers(engine.getServers())
|
|
25 |
{
|
|
26 |
}
|
|
27 |
|
|
28 |
MemSpyServerModel::~MemSpyServerModel()
|
|
29 |
{
|
|
30 |
qDeleteAll(mServers);
|
|
31 |
}
|
|
32 |
|
|
33 |
int MemSpyServerModel::rowCount(const QModelIndex &parent) const
|
|
34 |
{
|
|
35 |
Q_UNUSED(parent);
|
|
36 |
return mServers.count();
|
|
37 |
}
|
|
38 |
|
|
39 |
QVariant MemSpyServerModel::data(const QModelIndex &index, int role) const
|
|
40 |
{
|
|
41 |
if (role == Qt::DisplayRole) {
|
|
42 |
const MemSpyServer* server = mServers.at(index.row());
|
|
43 |
|
|
44 |
QStringList lines;
|
|
45 |
lines << server->name();
|
|
46 |
lines << QString("%1 session(s)").arg(server->sessionCount());
|
|
47 |
|
|
48 |
return lines;
|
|
49 |
}
|
|
50 |
|
|
51 |
if (role == Qt::UserRole)
|
|
52 |
return mServers.at(index.row())->id();
|
|
53 |
|
|
54 |
return QVariant();
|
|
55 |
}
|
|
56 |
|
|
57 |
void MemSpyServerModel::refresh()
|
|
58 |
{
|
|
59 |
beginResetModel();
|
|
60 |
QList<MemSpyServer*> data = mEngine.getServers();
|
|
61 |
qDeleteAll(mServers);
|
|
62 |
mServers = data;
|
|
63 |
endResetModel();
|
|
64 |
}
|
|
65 |
|
|
66 |
|
|
67 |
void MemSpyServerView::initialize(const QVariantMap& params)
|
|
68 |
{
|
|
69 |
setTitle(tr("Servers"));
|
|
70 |
MemSpyView::initialize(params);
|
|
71 |
|
|
72 |
mModel = new MemSpyServerModel(mEngine, this);
|
|
73 |
mListView.setModel(mModel);
|
|
74 |
|
|
75 |
connect(&mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemClicked(QModelIndex)));
|
|
76 |
}
|
|
77 |
|
|
78 |
void MemSpyServerView::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(ThreadView, map);
|
|
84 |
}
|
|
85 |
|
|
86 |
void MemSpyServerView::refresh()
|
|
87 |
{
|
|
88 |
mModel->refresh();
|
|
89 |
}
|