git-svn-id: svn://db.shs.com.ru/libs@560 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
195
piqt_utils/piintrospector/containers_view.cpp
Normal file
195
piqt_utils/piintrospector/containers_view.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
#include "containers_view.h"
|
||||
#include <QTreeView>
|
||||
#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,
|
||||
ccCount,
|
||||
ccBytesAllocated,
|
||||
ccBytesUsed,
|
||||
ccColumnCount,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
ContainersModel::ContainersModel() {
|
||||
mode_changes = false;
|
||||
all.resize(columnCount(), 0L);
|
||||
prev_all.resize(all.size(), 0L);
|
||||
}
|
||||
|
||||
|
||||
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]);
|
||||
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;
|
||||
}
|
||||
dataChanged(index(1, 0), index(columnCount(), typeids.size_s() - 1));
|
||||
emit headerDataChanged(Qt::Horizontal, 1, columnCount());
|
||||
}
|
||||
|
||||
|
||||
void ContainersModel::clear() {
|
||||
beginRemoveRows(QModelIndex(), 0, typeids.size_s() - 1);
|
||||
typedata.clear();
|
||||
prev_typedata.clear();
|
||||
typenames.clear();
|
||||
typeids.clear();
|
||||
all.fill(0L);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
|
||||
int ContainersModel::rowCount(const QModelIndex & parent) const {
|
||||
return typeids.size_s();
|
||||
}
|
||||
|
||||
|
||||
int ContainersModel::columnCount(const QModelIndex & parent) const {
|
||||
return ccColumnCount;
|
||||
}
|
||||
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
|
||||
bool ContainersModel::hasChildren(const QModelIndex & parent) const {
|
||||
if (!parent.isValid()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QVariant ContainersModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if (orientation != Qt::Horizontal || role != Qt::DisplayRole) return QVariant();
|
||||
PIVector<llong> ret = all;
|
||||
if (mode_changes) {
|
||||
for (int i = 0; i < all.size_s(); ++i)
|
||||
ret[i] -= prev_all[i];
|
||||
}
|
||||
switch (section) {
|
||||
case ccType : return tr("Type");
|
||||
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])));
|
||||
default: break;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
QVariant ContainersModel::data(const QModelIndex & index, int role) const {
|
||||
if (role != Qt::DisplayRole && role != Qt::UserRole) 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));
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
Qt::ItemFlags ContainersModel::flags(const QModelIndex & index) const {
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
|
||||
void ContainersModel::setChangesMode(bool yes) {
|
||||
mode_changes = yes;
|
||||
dataChanged(index(1, 0), index(columnCount(), typeids.size_s() - 1));
|
||||
emit headerDataChanged(Qt::Horizontal, 1, columnCount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ContainersView::ContainersView(QWidget * parent): QWidget(parent) {
|
||||
setupUi(this);
|
||||
model = new ContainersModel();
|
||||
connect(radioChanges, SIGNAL(toggled(bool)), model, SLOT(setChangesMode(bool)));
|
||||
QSortFilterProxyModel * proxy = new QSortFilterProxyModel();
|
||||
proxy->setSourceModel(model);
|
||||
proxy->setSortRole(Qt::UserRole);
|
||||
proxy->setDynamicSortFilter(false);
|
||||
treeContainers->setModel(proxy);
|
||||
}
|
||||
|
||||
|
||||
ContainersView::~ContainersView() {
|
||||
}
|
||||
|
||||
|
||||
void ContainersView::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ContainersView::showContainers(const PIMap<uint, PIIntrospectionContainers::Type> & data, const PIMap<uint, PIString> & typenames) {
|
||||
model->update(data, typenames);
|
||||
}
|
||||
|
||||
|
||||
void ContainersView::clear() {
|
||||
model->clear();
|
||||
}
|
||||
|
||||
66
piqt_utils/piintrospector/containers_view.h
Normal file
66
piqt_utils/piintrospector/containers_view.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef CONTAINERS_VIEW_H
|
||||
#define CONTAINERS_VIEW_H
|
||||
|
||||
#include "ui_containers_view.h"
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
#include "piqt.h"
|
||||
#include "piintrospection_containers_p.h"
|
||||
|
||||
|
||||
class ContainersModel: public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ContainersModel();
|
||||
|
||||
void update(const PIMap<uint, PIIntrospectionContainers::Type> & td, const PIMap<uint, PIString> & tn);
|
||||
void clear();
|
||||
|
||||
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex & parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex & child) const override {return QModelIndex();}
|
||||
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override;
|
||||
bool hasChildren(const QModelIndex & parent = QModelIndex()) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
QVariant data(const QModelIndex & index, int role) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex & index) const override;
|
||||
|
||||
protected:
|
||||
PIMap<uint, PIIntrospectionContainers::Type> typedata, prev_typedata;
|
||||
PIMap<uint, PIString> typenames;
|
||||
PIVector<uint> typeids;
|
||||
PIVector<llong> all, prev_all;
|
||||
bool mode_changes;
|
||||
|
||||
public slots:
|
||||
void setChangesMode(bool yes);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class ContainersView: public QWidget, private Ui::ContainersView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ContainersView(QWidget * parent = 0);
|
||||
~ContainersView();
|
||||
|
||||
void showContainers(const PIMap<uint, PIIntrospectionContainers::Type> & data, const PIMap<uint, PIString> & typenames);
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * e);
|
||||
|
||||
QStringList src_header;
|
||||
ContainersModel * model;
|
||||
|
||||
private slots:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // CONTAINERS_VIEW_H
|
||||
93
piqt_utils/piintrospector/containers_view.ui
Normal file
93
piqt_utils/piintrospector/containers_view.ui
Normal file
@@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ContainersView</class>
|
||||
<widget class="QWidget" name="ContainersView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>610</width>
|
||||
<height>406</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioOverall">
|
||||
<property name="text">
|
||||
<string>Overall</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioChanges">
|
||||
<property name="text">
|
||||
<string>Changes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>1</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="treeContainers">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
60
piqt_utils/piintrospector/objects_view.cpp
Normal file
60
piqt_utils/piintrospector/objects_view.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "objects_view.h"
|
||||
#include <QScrollBar>
|
||||
#include <QTreeWidget>
|
||||
|
||||
|
||||
enum ColumnObjects {
|
||||
coClassName,
|
||||
coName,
|
||||
coParents,
|
||||
coQueuedEvents,
|
||||
};
|
||||
|
||||
|
||||
ObjectsView::ObjectsView(QWidget * parent): QWidget(parent) {
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
|
||||
ObjectsView::~ObjectsView() {
|
||||
}
|
||||
|
||||
|
||||
void ObjectsView::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ObjectsView::showObjects(const PIVector<PIIntrospection::ObjectInfo> & objects) {
|
||||
QHash<QString, int> stat;
|
||||
|
||||
int vpos = treeObjects->verticalScrollBar()->value();
|
||||
treeObjects->clear();
|
||||
piForeachC (PIIntrospection::ObjectInfo & i, objects) {
|
||||
stat[PI2QString(i.classname)]++;
|
||||
QTreeWidgetItem * ti = new QTreeWidgetItem();
|
||||
ti->setText(coClassName, PI2QString(i.classname));
|
||||
ti->setText(coName, PI2QString(i.name));
|
||||
ti->setText(coParents, PI2QString(i.parents.join(":")));
|
||||
ti->setText(coQueuedEvents, QString::number(i.queued_events));
|
||||
treeObjects->addTopLevelItem(ti);
|
||||
}
|
||||
treeObjects->verticalScrollBar()->setValue(vpos);
|
||||
|
||||
vpos = treeObjectsStat->verticalScrollBar()->value();
|
||||
treeObjectsStat->clear();
|
||||
for (auto i = stat.constBegin(); i != stat.constEnd(); ++i) {
|
||||
QTreeWidgetItem * ti = new QTreeWidgetItem();
|
||||
ti->setText(0, i.key());
|
||||
ti->setText(1, QString::number(i.value()));
|
||||
treeObjectsStat->addTopLevelItem(ti);
|
||||
}
|
||||
treeObjectsStat->verticalScrollBar()->setValue(vpos);
|
||||
}
|
||||
28
piqt_utils/piintrospector/objects_view.h
Normal file
28
piqt_utils/piintrospector/objects_view.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef OBJECTS_VIEW_H
|
||||
#define OBJECTS_VIEW_H
|
||||
|
||||
#include "ui_objects_view.h"
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
#include "piqt.h"
|
||||
#include "piintrospection_server_p.h"
|
||||
|
||||
class ObjectsView: public QWidget, private Ui::ObjectsView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ObjectsView(QWidget * parent = 0);
|
||||
~ObjectsView();
|
||||
|
||||
void showObjects(const PIVector<PIIntrospection::ObjectInfo> & objects);
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * e);
|
||||
|
||||
private slots:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // OBJECTS_VIEW_H
|
||||
101
piqt_utils/piintrospector/objects_view.ui
Normal file
101
piqt_utils/piintrospector/objects_view.ui
Normal file
@@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ObjectsView</class>
|
||||
<widget class="QWidget" name="ObjectsView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>614</width>
|
||||
<height>413</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidgetObjects">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_5">
|
||||
<attribute name="title">
|
||||
<string>List</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="treeObjects">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>class</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>parents</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>queued_events</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_6">
|
||||
<attribute name="title">
|
||||
<string>Statictic</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="treeObjectsStat">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>class</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>count</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user