git-svn-id: svn://db.shs.com.ru/libs@563 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "containers_view.h"
|
||||
#include <QTreeView>
|
||||
#include <QPainter>
|
||||
#include <QStyle>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include <cxxabi.h>
|
||||
@@ -29,7 +31,7 @@ ContainersModel::ContainersModel() {
|
||||
prev_all.resize(all.size(), 0L);
|
||||
}
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
|
||||
void ContainersModel::update(const PIMap<uint, PIIntrospectionContainers::Type> & td, const PIMap<uint, PIString> & tn) {
|
||||
prev_typedata = typedata;
|
||||
typedata = td;
|
||||
@@ -49,14 +51,12 @@ void ContainersModel::update(const PIMap<uint, PIIntrospectionContainers::Type>
|
||||
all[ccBytesAllocated] += i.value().bytes_allocated;
|
||||
all[ccBytesUsed] += i.value().bytes_used;
|
||||
}
|
||||
dataChanged(index(1, 0), index(columnCount(), typeids.size_s() - 1));
|
||||
emit headerDataChanged(Qt::Horizontal, 1, columnCount());
|
||||
dataChanged(index(0, ccCount), index(typeids.size_s() - 1, columnCount()));
|
||||
emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void ContainersModel::clear() {
|
||||
#ifdef PIP_INTROSPECTION
|
||||
beginRemoveRows(QModelIndex(), 0, typeids.size_s() - 1);
|
||||
typedata.clear();
|
||||
prev_typedata.clear();
|
||||
@@ -64,9 +64,9 @@ void ContainersModel::clear() {
|
||||
typeids.clear();
|
||||
all.fill(0L);
|
||||
endRemoveRows();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int ContainersModel::rowCount(const QModelIndex & parent) const {
|
||||
return typeids.size_s();
|
||||
}
|
||||
@@ -78,9 +78,7 @@ int ContainersModel::columnCount(const QModelIndex & parent) const {
|
||||
|
||||
|
||||
QModelIndex ContainersModel::index(int row, int column, const QModelIndex & parent) const {
|
||||
#ifdef PIP_INTROSPECTION
|
||||
if (row >= typenames.size_s() || row >= typedata.size_s()) return QModelIndex();
|
||||
#endif
|
||||
return createIndex(row, column, typeids[row]);
|
||||
}
|
||||
|
||||
@@ -110,40 +108,43 @@ QVariant ContainersModel::headerData(int section, Qt::Orientation orientation, i
|
||||
|
||||
|
||||
QVariant ContainersModel::data(const QModelIndex & index, int role) const {
|
||||
if (role != Qt::DisplayRole && role != Qt::UserRole) return QVariant();
|
||||
#ifdef PIP_INTROSPECTION
|
||||
if (role != Qt::DisplayRole && role != Qt::UserRole && role != (Qt::UserRole+1)) return QVariant();
|
||||
uint id = uint(index.internalId());
|
||||
llong v = 0L;
|
||||
if (mode_changes) {
|
||||
switch (index.column()) {
|
||||
case ccType: return demangle(typenames.value(id).dataAscii());
|
||||
case ccCount: return int(typedata.value(id).count) - int(prev_typedata.value(id).count);
|
||||
case ccBytesAllocated:
|
||||
v = typedata.value(id).bytes_allocated;
|
||||
v -= prev_typedata.value(id).bytes_allocated;
|
||||
if (role == Qt::UserRole) return piAbs(v);
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
case ccBytesUsed:
|
||||
v = typedata.value(id).bytes_used;
|
||||
v -= prev_typedata.value(id).bytes_used;
|
||||
if (role == Qt::UserRole) return piAbs(v);
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
}
|
||||
} else {
|
||||
switch (index.column()) {
|
||||
case ccType: return demangle(typenames.value(id).dataAscii());
|
||||
case ccCount: return typedata.value(id).count;
|
||||
case ccBytesAllocated:
|
||||
v = typedata.value(id).bytes_allocated;
|
||||
if (role == Qt::UserRole) return v;
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
case ccBytesUsed:
|
||||
v = typedata.value(id).bytes_used;
|
||||
if (role == Qt::UserRole) return v;
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
if (role == Qt::DisplayRole || role == Qt::UserRole) {
|
||||
if (mode_changes) {
|
||||
switch (index.column()) {
|
||||
case ccType: return demangle(typenames.value(id).dataAscii());
|
||||
case ccCount: return int(typedata.value(id).count) - int(prev_typedata.value(id).count);
|
||||
case ccBytesAllocated:
|
||||
v = typedata.value(id).bytes_allocated;
|
||||
v -= prev_typedata.value(id).bytes_allocated;
|
||||
if (role == Qt::UserRole) return piAbs(v);
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
case ccBytesUsed:
|
||||
v = typedata.value(id).bytes_used;
|
||||
v -= prev_typedata.value(id).bytes_used;
|
||||
if (role == Qt::UserRole) return piAbs(v);
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
}
|
||||
} else {
|
||||
switch (index.column()) {
|
||||
case ccType: return demangle(typenames.value(id).dataAscii());
|
||||
case ccCount: return typedata.value(id).count;
|
||||
case ccBytesAllocated:
|
||||
v = typedata.value(id).bytes_allocated;
|
||||
if (role == Qt::UserRole) return v;
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
case ccBytesUsed:
|
||||
v = typedata.value(id).bytes_used;
|
||||
if (role == Qt::UserRole) return v;
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (role == (Qt::UserRole+1) && (index.column() == ccCount)) {
|
||||
return typedata.value(id).count;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@@ -155,8 +156,27 @@ Qt::ItemFlags ContainersModel::flags(const QModelIndex & index) const {
|
||||
|
||||
void ContainersModel::setChangesMode(bool yes) {
|
||||
mode_changes = yes;
|
||||
dataChanged(index(1, 0), index(columnCount(), typeids.size_s() - 1));
|
||||
emit headerDataChanged(Qt::Horizontal, 1, columnCount());
|
||||
dataChanged(index(0, ccCount), index(typeids.size_s() - 1, columnCount()));
|
||||
emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ContainersDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const {
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
if (model->index(index.row(), ccCount).data(Qt::UserRole+1).toInt() == 0) {
|
||||
QColor col;
|
||||
if (option.state == QStyle::State_Enabled ||
|
||||
option.state == QStyle::State_HasFocus)
|
||||
col = option.palette.color(QPalette::Active, QPalette::WindowText);
|
||||
else
|
||||
col = option.palette.color(QPalette::Disabled, QPalette::WindowText);
|
||||
col.setAlphaF(0.5);
|
||||
int y = option.rect.center().y() + (option.fontMetrics.height() / 2.5) - option.fontMetrics.strikeOutPos();
|
||||
painter->setPen(QPen(col, lineThickness()));
|
||||
painter->drawLine(QPoint(option.rect.left(), y), QPoint(option.rect.right(), y));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +190,8 @@ ContainersView::ContainersView(QWidget * parent): QWidget(parent) {
|
||||
proxy->setSourceModel(model);
|
||||
proxy->setSortRole(Qt::UserRole);
|
||||
proxy->setDynamicSortFilter(false);
|
||||
treeContainers->setModel(proxy);
|
||||
treeContainers->setModel(model);
|
||||
treeContainers->setItemDelegate(new ContainersDelegate(model));
|
||||
}
|
||||
|
||||
|
||||
@@ -189,11 +210,10 @@ void ContainersView::changeEvent(QEvent * e) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
|
||||
void ContainersView::showContainers(const PIMap<uint, PIIntrospectionContainers::Type> & data, const PIMap<uint, PIString> & typenames) {
|
||||
model->update(data, typenames);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void ContainersView::clear() {
|
||||
|
||||
Reference in New Issue
Block a user