40 QVariant MemSpyKernelObjectTypeModel::data(const QModelIndex &index, int role) const |
40 QVariant MemSpyKernelObjectTypeModel::data(const QModelIndex &index, int role) const |
41 { |
41 { |
42 if (role == Qt::DisplayRole) { |
42 if (role == Qt::DisplayRole) { |
43 QStringList lines; |
43 QStringList lines; |
44 lines << mObjectTypes.at(index.row())->name(); |
44 lines << mObjectTypes.at(index.row())->name(); |
|
45 lines << QString("%1, %2"). |
|
46 arg(tr("%n item(s)", "", mObjectTypes.at(index.row())->count())). |
|
47 arg(formatSize(mObjectTypes.at(index.row())->size())); |
45 |
48 |
46 return lines; |
49 return lines; |
47 } |
50 } |
48 |
51 |
49 if (role == Qt::UserRole) |
52 if (role == Qt::UserRole) |
50 return mObjectTypes.at(index.row())->id(); |
53 return mObjectTypes.at(index.row())->id(); |
51 |
54 |
52 return QVariant(); |
55 return QVariant(); |
53 } |
56 } |
54 |
57 |
|
58 QString MemSpyKernelObjectTypeModel::formatSize(qint64 size) const |
|
59 { |
|
60 // If < 1000K |
|
61 if (size < 1024000) |
|
62 return QString("%1K").arg(size ? qBound<int>(1, (size + 512) >> 10, 999) : 0); |
|
63 |
|
64 // larger than 1M |
|
65 double sizeInM = size / 1048576.; |
|
66 return sizeInM >= 1000 ? |
|
67 QString("%1G").arg(qMax<double>(1, sizeInM / 1024), 0, 'f', 1) : |
|
68 QString("%1M").arg(qBound<double>(1, sizeInM, 999.9), 0, 'f', 1); |
|
69 } |
|
70 |
55 void MemSpyKernelObjectTypeView::initialize(const QVariantMap& params) |
71 void MemSpyKernelObjectTypeView::initialize(const QVariantMap& params) |
56 { |
72 { |
57 MemSpyView::initialize(params); |
73 MemSpyView::initialize(params); |
58 |
74 |
59 setTitle(tr("Kernel Objects")); |
75 setTitle(tr("Kernel Objects")); |
60 |
|
61 QStringList list = QStringList() << "Thread" << "Process" << "Chunk" << "Library" << |
|
62 "Semaphore" << "Mutex" << "Timer" << "Server" << "Session" << "Logical Device" << |
|
63 "Physical Device" << "Logical Channel" << "Change Notifier" << "Undertaker" << |
|
64 "Message Queue" << "Property Ref." << "Conditional Var."; |
|
65 |
76 |
66 //mListView.setModel(new MemSpyKernelObjectTypeModel(mEngine, this)); |
77 mListView.setModel(new MemSpyKernelObjectTypeModel(mEngine, this)); |
67 mListView.setModel(new QStringListModel(list, this)); |
|
68 |
78 |
69 connect(&mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemClicked(QModelIndex))); |
79 connect(&mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemClicked(QModelIndex))); |
70 } |
80 } |
71 |
81 |
72 void MemSpyKernelObjectTypeView::itemClicked(const QModelIndex& index) |
82 void MemSpyKernelObjectTypeView::itemClicked(const QModelIndex& index) |