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