git-svn-id: svn://db.shs.com.ru/libs@568 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -4,18 +4,10 @@
|
||||
#include <QStyle>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include <cxxabi.h>
|
||||
const QString demangle(const char * name) {
|
||||
int status = -4;
|
||||
char * res = abi::__cxa_demangle(name, NULL, NULL, &status);
|
||||
QString ret((status == 0) ? res : name);
|
||||
free(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
enum ColumnContainers {
|
||||
ccType,
|
||||
ccItemSize,
|
||||
ccCount,
|
||||
ccBytesAllocated,
|
||||
ccBytesUsed,
|
||||
@@ -32,43 +24,41 @@ ContainersModel::ContainersModel() {
|
||||
}
|
||||
|
||||
|
||||
void ContainersModel::update(const PIMap<uint, PIIntrospectionContainers::Type> & td, const PIMap<uint, PIString> & tn) {
|
||||
prev_typedata = typedata;
|
||||
typedata = td;
|
||||
typenames = tn;
|
||||
PIVector<uint> ntypeids = tn.keys();
|
||||
for (int i = 0; i < ntypeids.size_s(); ++i) {
|
||||
if (typeids.size_s() > i)
|
||||
if (typeids[i] == ntypeids[i]) continue;
|
||||
beginInsertRows(QModelIndex(), i, i);
|
||||
typeids.insert(i, ntypeids[i]);
|
||||
void ContainersModel::update(const PIVector<PIIntrospectionContainers::TypeInfo> & t) {
|
||||
prev_data.clear();
|
||||
all.fill(0U);
|
||||
piForeachC (PIIntrospectionContainers::TypeInfo & i, t) {
|
||||
prev_data[i.id] = i;
|
||||
all[ccCount] += i.count;
|
||||
all[ccBytesAllocated] += i.allocated * i.item_size;
|
||||
all[ccBytesUsed] += i.used * i.item_size;
|
||||
}
|
||||
int pts = cur_data.size_s();
|
||||
cur_data = t;
|
||||
if (t.size_s() > pts) {
|
||||
beginInsertRows(QModelIndex(), pts, t.size_s() - 1);
|
||||
endInsertRows();
|
||||
}
|
||||
prev_all = all;
|
||||
all.fill(0U);
|
||||
for (auto i = td.constBegin(); i != td.constEnd(); ++i) {
|
||||
all[ccCount] += i.value().count;
|
||||
all[ccBytesAllocated] += i.value().bytes_allocated;
|
||||
all[ccBytesUsed] += i.value().bytes_used;
|
||||
if (t.size_s() < pts) {
|
||||
beginRemoveRows(QModelIndex(), t.size_s(), pts - 1);
|
||||
endRemoveRows();
|
||||
}
|
||||
dataChanged(index(0, ccCount), index(typeids.size_s() - 1, columnCount()));
|
||||
dataChanged(index(0, 0), index(cur_data.size_s() - 1, columnCount()));
|
||||
emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
|
||||
}
|
||||
|
||||
|
||||
void ContainersModel::clear() {
|
||||
beginRemoveRows(QModelIndex(), 0, typeids.size_s() - 1);
|
||||
typedata.clear();
|
||||
prev_typedata.clear();
|
||||
typenames.clear();
|
||||
typeids.clear();
|
||||
beginRemoveRows(QModelIndex(), 0, cur_data.size_s() - 1);
|
||||
cur_data.clear();
|
||||
prev_data.clear();
|
||||
all.fill(0L);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
|
||||
int ContainersModel::rowCount(const QModelIndex & parent) const {
|
||||
return typeids.size_s();
|
||||
return cur_data.size_s();
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +68,8 @@ int ContainersModel::columnCount(const QModelIndex & parent) const {
|
||||
|
||||
|
||||
QModelIndex ContainersModel::index(int row, int column, const QModelIndex & parent) const {
|
||||
if (row >= typenames.size_s() || row >= typedata.size_s()) return QModelIndex();
|
||||
return createIndex(row, column, typeids[row]);
|
||||
if (row >= cur_data.size_s() || row >= cur_data.size_s()) return QModelIndex();
|
||||
return createIndex(row, column, cur_data[row].id);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +88,7 @@ QVariant ContainersModel::headerData(int section, Qt::Orientation orientation, i
|
||||
}
|
||||
switch (section) {
|
||||
case ccType : return tr("Type");
|
||||
case ccItemSize : return tr("Item size");
|
||||
case ccCount : return tr("Count (%1)").arg(ret[ccCount]);
|
||||
case ccBytesAllocated: return tr("Allocated (%1)").arg(PI2QString(PIString::readableSize(ret[ccBytesAllocated])));
|
||||
case ccBytesUsed : return tr("Used (%1)").arg(PI2QString(PIString::readableSize(ret[ccBytesUsed])));
|
||||
@@ -110,40 +101,46 @@ 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 && role != (Qt::UserRole+1)) return QVariant();
|
||||
uint id = uint(index.internalId());
|
||||
const PIIntrospectionContainers::TypeInfo & t(cur_data[index.row()]);
|
||||
llong v = 0L;
|
||||
if (role == Qt::DisplayRole || role == Qt::UserRole) {
|
||||
switch (index.column()) {
|
||||
case ccType: return PI2QString(t.name);
|
||||
case ccItemSize: return PI2QString(PIString::readableSize(t.item_size));
|
||||
default: break;
|
||||
}
|
||||
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 ccCount: return int(t.count) - int(prev_data.value(id).count);
|
||||
case ccBytesAllocated:
|
||||
v = typedata.value(id).bytes_allocated;
|
||||
v -= prev_typedata.value(id).bytes_allocated;
|
||||
v = t.allocated;
|
||||
v -= prev_data.value(id).allocated;
|
||||
v *= t.item_size;
|
||||
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;
|
||||
v = t.used;
|
||||
v -= prev_data.value(id).used;
|
||||
v *= t.item_size;
|
||||
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 ccCount: return t.count;
|
||||
case ccBytesAllocated:
|
||||
v = typedata.value(id).bytes_allocated;
|
||||
v = t.allocated * t.item_size;
|
||||
if (role == Qt::UserRole) return v;
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
case ccBytesUsed:
|
||||
v = typedata.value(id).bytes_used;
|
||||
v = t.used * t.item_size;
|
||||
if (role == Qt::UserRole) return v;
|
||||
return PI2QString(PIString::readableSize(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (role == (Qt::UserRole+1) && (index.column() == ccCount)) {
|
||||
return typedata.value(id).count;
|
||||
return t.count;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
@@ -156,8 +153,8 @@ Qt::ItemFlags ContainersModel::flags(const QModelIndex & index) const {
|
||||
|
||||
void ContainersModel::setChangesMode(bool yes) {
|
||||
mode_changes = yes;
|
||||
if (typeids.isEmpty()) return;
|
||||
dataChanged(index(0, ccCount), index(typeids.size_s() - 1, columnCount()));
|
||||
if (cur_data.isEmpty()) return;
|
||||
dataChanged(index(0, ccCount), index(cur_data.size_s() - 1, columnCount()));
|
||||
emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
|
||||
}
|
||||
|
||||
@@ -212,8 +209,8 @@ void ContainersView::changeEvent(QEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void ContainersView::showContainers(const PIMap<uint, PIIntrospectionContainers::Type> & data, const PIMap<uint, PIString> & typenames) {
|
||||
model->update(data, typenames);
|
||||
void ContainersView::showContainers(const PIVector<PIIntrospectionContainers::TypeInfo> & t) {
|
||||
model->update(t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user