code format

This commit is contained in:
2022-12-14 14:14:33 +03:00
parent 09e5342956
commit cdb02fc9be
278 changed files with 15371 additions and 12176 deletions

View File

@@ -1,14 +1,14 @@
#include <QApplication>
#include "blockeditor.h"
#include <QApplication>
int main(int argc, char * argv[]) {
QApplication a(argc, argv);
enableHighDPI();
a.setWindowIcon(QIcon(":/icons/blockview.png"));
BlockEditor w;
if (a.arguments().size() > 1)
w.loadFile(a.arguments().back());
if (a.arguments().size() > 1) w.loadFile(a.arguments().back());
w.show();
return a.exec();
}

View File

@@ -1,8 +1,9 @@
#include "containers_view.h"
#include <QTreeView>
#include <QPainter>
#include <QStyle>
#include <QSortFilterProxyModel>
#include <QStyle>
#include <QTreeView>
enum ColumnContainers {
@@ -15,12 +16,10 @@ enum ColumnContainers {
};
ContainersModel::ContainersModel() {
mode_changes = false;
ls_column = 0;
ls_order = Qt::AscendingOrder;
ls_column = 0;
ls_order = Qt::AscendingOrder;
all.resize(columnCount(), 0L);
prev_all.resize(all.size(), 0L);
}
@@ -29,20 +28,20 @@ ContainersModel::ContainersModel() {
void ContainersModel::update(const PIVector<PIIntrospectionContainers::TypeInfo> & t) {
prev_data.clear();
all.fill(0U);
piForeachC (PIIntrospectionContainers::TypeInfo & i, cur_data) {
piForeachC(PIIntrospectionContainers::TypeInfo & i, cur_data) {
prev_data[i.id] = i;
}
piForeachC (PIIntrospectionContainers::TypeInfo & i, t) {
all[ccCount] += i.count;
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
piForeachC(PIIntrospectionContainers::TypeInfo & i, t) {
all[ccCount] += i.count;
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
all[ccBytesAllocated] += i.allocated_bytes;
all[ccBytesUsed] += i.used_bytes;
all[ccBytesUsed] += i.used_bytes;
#else
all[ccBytesAllocated] += i.allocated;
all[ccBytesUsed] += i.used;
all[ccBytesUsed] += i.used;
#endif
}
int pts = cur_data.size_s();
int pts = cur_data.size_s();
cur_data = t;
if (t.size_s() > pts) {
beginInsertRows(QModelIndex(), pts, t.size_s() - 1);
@@ -96,11 +95,11 @@ QVariant ContainersModel::headerData(int section, Qt::Orientation orientation, i
ret[i] -= prev_all[i];
}
switch (section) {
case ccType : return tr("Type");
case ccItemSize : return tr("Item size");
case ccCount : return tr("Count (%1)").arg(ret[ccCount]);
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])));
case ccBytesUsed: return tr("Used (%1)").arg(PI2QString(PIString::readableSize(ret[ccBytesUsed])));
default: break;
}
return QVariant();
@@ -108,16 +107,16 @@ 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();
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 ccType: return PI2QString(t.name);
case ccItemSize:
if (role == Qt::UserRole) return t.item_size;
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
return PI2QString(t.item_size_str);
#else
return PI2QString(PIString::readableSize(t.item_size));
@@ -128,7 +127,7 @@ QVariant ContainersModel::data(const QModelIndex & index, int role) const {
switch (index.column()) {
case ccCount: return int(t.count) - int(prev_data.value(id).count);
case ccBytesAllocated:
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
v = t.allocated_bytes;
v -= prev_data.value(id).allocated_bytes;
#else
@@ -138,7 +137,7 @@ QVariant ContainersModel::data(const QModelIndex & index, int role) const {
if (role == Qt::UserRole) return piAbs(v);
return PI2QString(PIString::readableSize(v));
case ccBytesUsed:
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
v = t.used_bytes;
v -= prev_data.value(id).used_bytes;
#else
@@ -152,7 +151,7 @@ QVariant ContainersModel::data(const QModelIndex & index, int role) const {
switch (index.column()) {
case ccCount: return t.count;
case ccBytesAllocated:
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
if (role == Qt::UserRole) return t.allocated_bytes;
return PI2QString(t.allocated_str);
case ccBytesUsed:
@@ -163,12 +162,12 @@ QVariant ContainersModel::data(const QModelIndex & index, int role) const {
return PI2QString(PIString::readableSize(t.allocated));
case ccBytesUsed:
if (role == Qt::UserRole) return t.used;
return PI2QString(PIString::readableSize(t.used));
return PI2QString(PIString::readableSize(t.used));
#endif
}
}
}
if (role == (Qt::UserRole+1) && (index.column() == ccCount)) {
if (role == (Qt::UserRole + 1) && (index.column() == ccCount)) {
return t.count;
}
return QVariant();
@@ -180,21 +179,21 @@ Qt::ItemFlags ContainersModel::flags(const QModelIndex & index) const {
}
//bool cmp(const PIIntrospectionContainers::TypeInfo & a, const PIIntrospectionContainers::TypeInfo & b);
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
// bool cmp(const PIIntrospectionContainers::TypeInfo & a, const PIIntrospectionContainers::TypeInfo & b);
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
bool cmp_func_name_a(const PIIntrospectionContainers::TypeInfo & t0, const PIIntrospectionContainers::TypeInfo & t1) {
return QString::localeAwareCompare(PI2QString(t0.name), PI2QString(t1.name)) < 0;
}
bool cmp_func_name_d(const PIIntrospectionContainers::TypeInfo & t0, const PIIntrospectionContainers::TypeInfo & t1) {
return !cmp_func_name_a(t0, t1);
}
# define CMP_FUNC(field) \
bool cmp_func_##field##_a(const PIIntrospectionContainers::TypeInfo & t0, const PIIntrospectionContainers::TypeInfo & t1) { \
return t0.field < t1.field; \
} \
bool cmp_func_##field##_d(const PIIntrospectionContainers::TypeInfo & t0, const PIIntrospectionContainers::TypeInfo & t1) { \
return t0.field > t1.field; \
}
# define CMP_FUNC(field) \
bool cmp_func_##field##_a(const PIIntrospectionContainers::TypeInfo & t0, const PIIntrospectionContainers::TypeInfo & t1) { \
return t0.field < t1.field; \
} \
bool cmp_func_##field##_d(const PIIntrospectionContainers::TypeInfo & t0, const PIIntrospectionContainers::TypeInfo & t1) { \
return t0.field > t1.field; \
}
#else
int cmp_func_name_a(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) {
return QString::localeAwareCompare(PI2QString(t0->name), PI2QString(t1->name));
@@ -202,17 +201,17 @@ int cmp_func_name_a(const PIIntrospectionContainers::TypeInfo * t0, const PIIntr
int cmp_func_name_d(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) {
return -cmp_func_name_a(t0, t1);
}
# define CMP_FUNC(field) \
int cmp_func_##field##_a(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) { \
return (t0->field) <= (t1->field) ? -1 : ((t0->field) == (t1->field) ? 0 : 1); \
} \
int cmp_func_##field##_d(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) { \
return -cmp_func_##field##_a(t0, t1); \
}
# define CMP_FUNC(field) \
int cmp_func_##field##_a(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) { \
return (t0->field) <= (t1->field) ? -1 : ((t0->field) == (t1->field) ? 0 : 1); \
} \
int cmp_func_##field##_d(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) { \
return -cmp_func_##field##_a(t0, t1); \
}
#endif
CMP_FUNC(item_size)
CMP_FUNC(count)
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
CMP_FUNC(allocated_bytes)
CMP_FUNC(used_bytes)
#else
@@ -222,30 +221,30 @@ CMP_FUNC(used)
#undef CMP_FUNC
void ContainersModel::sort(int column, Qt::SortOrder order) {
ls_column = column;
ls_order = order;
ls_order = order;
if (cur_data.isEmpty()) return;
PIVector<PIIntrospectionContainers::TypeInfo>::CompareFunc cf = nullptr;
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
switch (column) {
case ccType : cf = order == Qt::AscendingOrder ? cmp_func_name_a : cmp_func_name_d ; break;
case ccItemSize : cf = order == Qt::AscendingOrder ? cmp_func_item_size_a : cmp_func_item_size_d ; break;
case ccCount : cf = order == Qt::AscendingOrder ? cmp_func_count_a : cmp_func_count_d ; break;
case ccType: cf = order == Qt::AscendingOrder ? cmp_func_name_a : cmp_func_name_d; break;
case ccItemSize: cf = order == Qt::AscendingOrder ? cmp_func_item_size_a : cmp_func_item_size_d; break;
case ccCount: cf = order == Qt::AscendingOrder ? cmp_func_count_a : cmp_func_count_d; break;
case ccBytesAllocated: cf = order == Qt::AscendingOrder ? cmp_func_allocated_bytes_a : cmp_func_allocated_bytes_d; break;
case ccBytesUsed : cf = order == Qt::AscendingOrder ? cmp_func_used_bytes_a : cmp_func_used_bytes_d ; break;
default : break;
case ccBytesUsed: cf = order == Qt::AscendingOrder ? cmp_func_used_bytes_a : cmp_func_used_bytes_d; break;
default: break;
}
#else
switch (column) {
case ccType : cf = order == Qt::AscendingOrder ? cmp_func_name_a : cmp_func_name_d ; break;
case ccItemSize : cf = order == Qt::AscendingOrder ? cmp_func_item_size_a : cmp_func_item_size_d; break;
case ccCount : cf = order == Qt::AscendingOrder ? cmp_func_count_a : cmp_func_count_d ; break;
case ccType: cf = order == Qt::AscendingOrder ? cmp_func_name_a : cmp_func_name_d; break;
case ccItemSize: cf = order == Qt::AscendingOrder ? cmp_func_item_size_a : cmp_func_item_size_d; break;
case ccCount: cf = order == Qt::AscendingOrder ? cmp_func_count_a : cmp_func_count_d; break;
case ccBytesAllocated: cf = order == Qt::AscendingOrder ? cmp_func_allocated_a : cmp_func_allocated_d; break;
case ccBytesUsed : cf = order == Qt::AscendingOrder ? cmp_func_used_a : cmp_func_used_d ; break;
default : break;
case ccBytesUsed: cf = order == Qt::AscendingOrder ? cmp_func_used_a : cmp_func_used_d; break;
default: break;
}
#endif
if (cf) cur_data.sort(cf);
//qDebug() << "sort" << column << order;
// qDebug() << "sort" << column << order;
dataChanged(index(0, 0), index(cur_data.size_s() - 1, columnCount()));
}
@@ -258,14 +257,11 @@ void ContainersModel::setChangesMode(bool yes) {
}
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) {
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)
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);
@@ -277,8 +273,6 @@ void ContainersDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
}
ContainersView::ContainersView(QWidget * parent): QWidget(parent) {
setupUi(this);
model = new ContainersModel();
@@ -292,18 +286,14 @@ ContainersView::ContainersView(QWidget * parent): QWidget(parent) {
}
ContainersView::~ContainersView() {
}
ContainersView::~ContainersView() {}
void ContainersView::changeEvent(QEvent * e) {
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
case QEvent::LanguageChange: retranslateUi(this); break;
default: break;
}
}

View File

@@ -1,16 +1,18 @@
#ifndef CONTAINERS_VIEW_H
#define CONTAINERS_VIEW_H
#include "ui_containers_view.h"
#include <QDebug>
#include <QWidget>
#include <QAbstractItemModel>
#include <QStyledItemDelegate>
#include "piqt.h"
#include "piintrospection_containers_p.h"
#include "piqt.h"
#include "ui_containers_view.h"
#include <QAbstractItemModel>
#include <QDebug>
#include <QStyledItemDelegate>
#include <QWidget>
class ContainersModel: public QAbstractItemModel {
Q_OBJECT
public:
ContainersModel();
@@ -19,7 +21,7 @@ public:
int rowCount(const QModelIndex & parent = QModelIndex()) const;
int columnCount(const QModelIndex & parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex & child) const {return QModelIndex();}
QModelIndex parent(const QModelIndex & child) const { return QModelIndex(); }
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
@@ -37,39 +39,40 @@ protected:
public slots:
void setChangesMode(bool yes);
};
class ContainersDelegate: public QStyledItemDelegate {
Q_OBJECT
public:
ContainersDelegate(QAbstractItemModel * m) {model = m;}
void paint(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex &index) const;
ContainersDelegate(QAbstractItemModel * m) { model = m; }
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
QAbstractItemModel * model;
};
class ContainersView: public QWidget, private Ui::ContainersView
{
class ContainersView
: public QWidget
, private Ui::ContainersView {
Q_OBJECT
public:
ContainersView(QWidget * parent = 0);
~ContainersView();
void showContainers(const PIVector<PIIntrospectionContainers::TypeInfo> & t);
void clear();
protected:
void changeEvent(QEvent * e);
ContainersModel * model;
private slots:
void sessionSave(QByteArray * data) {*data = treeContainers->header()->saveState();}
void sessionLoad(QByteArray * data) {treeContainers->header()->restoreState(*data);}
void sessionSave(QByteArray * data) { *data = treeContainers->header()->saveState(); }
void sessionLoad(QByteArray * data) { treeContainers->header()->restoreState(*data); }
public slots:
};

View File

@@ -1,4 +1,5 @@
#include "objects_view.h"
#include <QScrollBar>
#include <QTreeWidget>
@@ -16,18 +17,14 @@ ObjectsView::ObjectsView(QWidget * parent): QWidget(parent) {
}
ObjectsView::~ObjectsView() {
}
ObjectsView::~ObjectsView() {}
void ObjectsView::changeEvent(QEvent * e) {
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
case QEvent::LanguageChange: retranslateUi(this); break;
default: break;
}
}
@@ -37,7 +34,7 @@ void ObjectsView::showObjects(const PIVector<PIIntrospection::ObjectInfo> & obje
int vpos = treeObjects->verticalScrollBar()->value();
treeObjects->clear();
piForeachC (PIIntrospection::ObjectInfo & i, objects) {
piForeachC(PIIntrospection::ObjectInfo & i, objects) {
stat[PI2QString(i.classname)]++;
QTreeWidgetItem * ti = new QTreeWidgetItem();
ti->setText(coClassName, PI2QString(i.classname));

View File

@@ -1,28 +1,31 @@
#ifndef OBJECTS_VIEW_H
#define OBJECTS_VIEW_H
#include "piintrospection_server_p.h"
#include "piqt.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
{
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:
void sessionSave(QByteArray * data) {*data = treeObjects->header()->saveState();}
void sessionLoad(QByteArray * data) {treeObjects->header()->restoreState(*data);}
void sessionSave(QByteArray * data) { *data = treeObjects->header()->saveState(); }
void sessionLoad(QByteArray * data) { treeObjects->header()->restoreState(*data); }
public slots:
};
#endif // OBJECTS_VIEW_H

View File

@@ -1,11 +1,13 @@
#include "piintrospector.h"
#include <QClipboard>
#include <QScrollBar>
#include "ccm_piintrospector.h"
#include "pichunkstream.h"
#include "pidir.h"
#include "pifile.h"
#include "pitime.h"
#include "pidir.h"
#include "pichunkstream.h"
#include "ccm_piintrospector.h"
#include <QClipboard>
#include <QScrollBar>
QPIIntrospector::QPIIntrospector(QWidget * parent): EMainWindow(parent), peer("__introspection_client__") {
@@ -13,22 +15,22 @@ QPIIntrospector::QPIIntrospector(QWidget * parent): EMainWindow(parent), peer("_
request_timer = 0;
session.setFile("qpiintrospector_session.conf");
#if QT_VERSION >= 0x050000
//treeContainers->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
// treeContainers->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
//treeContainers->header()->setResizeMode(QHeaderView::ResizeToContents);
// treeContainers->header()->setResizeMode(QHeaderView::ResizeToContents);
#endif
CONNECTU_QUEUED(&peer, peerConnectedEvent, this, peersChanged, this);
CONNECTU_QUEUED(&peer, peerDisconnectedEvent, this, peersChanged, this);
CONNECTU_QUEUED(&peer, dataReceivedEvent, this, peerReceived, this);
//CONNECTU(&peer, peerConnectedEvent, this, reqProcPIEvents);
//CONNECTU(&peer, peerDisconnectedEvent, this, reqProcPIEvents);
//CONNECTU(&peer, dataReceivedEvent, this, reqProcPIEvents);
// CONNECTU(&peer, peerConnectedEvent, this, reqProcPIEvents);
// CONNECTU(&peer, peerDisconnectedEvent, this, reqProcPIEvents);
// CONNECTU(&peer, dataReceivedEvent, this, reqProcPIEvents);
session.addEntry(this);
session.addEntry(tabWidgetMain);
PICodeInfo::EnumInfo * ei = PICodeInfo::enumsInfo->value("PIIntrospection::InfoTypes");
if (ei) {
piForeachC (PICodeInfo::EnumeratorInfo & e, ei->members) {
#if PIP_VERSION >= PIP_MAKE_VERSION(2,39,0)
piForeachC(PICodeInfo::EnumeratorInfo & e, ei->members) {
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 39, 0)
QCheckBox * cb = new QCheckBox(PI2QString(e.name.mid(2).toString()));
#else
QCheckBox * cb = new QCheckBox(PI2QString(e.name.mid(2)));
@@ -54,19 +56,15 @@ QPIIntrospector::~QPIIntrospector() {
void QPIIntrospector::changeEvent(QEvent * e) {
EMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
case QEvent::LanguageChange: retranslateUi(this); break;
default: break;
}
}
void QPIIntrospector::timerEvent(QTimerEvent * e) {
if (e->timerId() == pip_timer)
callQueuedEvents();
if (e->timerId() == request_timer)
buttonRequest->click();
if (e->timerId() == pip_timer) callQueuedEvents();
if (e->timerId() == request_timer) buttonRequest->click();
}
@@ -86,9 +84,9 @@ void QPIIntrospector::buildTree(QByteArray d) {
pd >> threads;
treeContainers->clear();
piForeachC (PIIntrospectionThreads::ThreadInfo & t, threads) {
QTreeWidgetItem * ti = new QTreeWidgetItem();
ti->setText(0, QString(PI2QString(t.name) + " (%1)").arg(t.id));
treeContainers->addTopLevelItem(ti);
QTreeWidgetItem * ti = new QTreeWidgetItem();
ti->setText(0, QString(PI2QString(t.name) + " (%1)").arg(t.id));
treeContainers->addTopLevelItem(ti);
}*/
}
@@ -101,8 +99,7 @@ void QPIIntrospector::procRequestTimer() {
}
void QPIIntrospector::buildDumpSection(QTreeWidgetItem * pi, PIString & str) {
}
void QPIIntrospector::buildDumpSection(QTreeWidgetItem * pi, PIString & str) {}
void QPIIntrospector::showInfo() {
@@ -141,15 +138,15 @@ QString QPIIntrospector::durationStr(PISystemTime t) {
QString ret;
double s = t.toSeconds();
int d, h, m;
d = piFloor(s / (24*60*60));
d = piFloor(s / (24 * 60 * 60));
if (d > 0) {
ret += QString::number(d) + " d ";
s -= d * (24*60*60);
s -= d * (24 * 60 * 60);
}
h = piFloor(s / (60*60));
h = piFloor(s / (60 * 60));
if (h > 0) {
ret += QString::number(h) + " h ";
s -= h * (60*60);
s -= h * (60 * 60);
}
m = piFloor(s / 60);
if (m > 0) {
@@ -160,11 +157,11 @@ QString QPIIntrospector::durationStr(PISystemTime t) {
return ret;
}
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
void QPIIntrospector::prepareContainers(PIVector<PIIntrospectionContainers::TypeInfo> & data) {
for (PIIntrospectionContainers::TypeInfo & i: data) {
i.allocated_bytes = i.allocated * i.item_size;
i.used_bytes = i.used * i.item_size;
i.used_bytes = i.used * i.item_size;
i.item_size_str.setReadableSize(i.item_size);
i.allocated_str.setReadableSize(i.allocated_bytes);
i.used_str.setReadableSize(i.used_bytes);
@@ -174,56 +171,63 @@ void QPIIntrospector::prepareContainers(PIVector<PIIntrospectionContainers::Type
void QPIIntrospector::on_listApp_currentRowChanged(int r) {
PIString cs;
if (r < 0) cs.clear();
else cs = Q2PIString(listApp->item(r)->data(Qt::UserRole).toString());
if (cur_server != cs)
widgetContainers->clear();
if (r < 0)
cs.clear();
else
cs = Q2PIString(listApp->item(r)->data(Qt::UserRole).toString());
if (cur_server != cs) widgetContainers->clear();
cur_server = cs;
}
void QPIIntrospector::peerReceived(const PIString & from, const PIByteArray & data) {
if (from != cur_server) return;
//piCout << "rec" << data.size();
// piCout << "rec" << data.size();
PIByteArray ba(data);
if (ba.size_s() < 4) return;
uint sign(0); ba >> sign;
uint sign(0);
ba >> sign;
if (sign != PIIntrospection::sign) return;
PIChunkStream cs(ba);
PIByteArray pba;
while (!cs.atEnd()) {
switch (cs.read()) {
case PIIntrospection::itInfo: {
pba.clear(); cs.get(pba);
pba.clear();
cs.get(pba);
PIIntrospection::unpackInfo(pba, info);
} break;
} break;
case PIIntrospection::itProcStat: {
pba.clear(); cs.get(pba);
pba.clear();
cs.get(pba);
PIIntrospection::unpackProcStat(pba, stat);
widgetThreads->setStat(stat.threads);
//showInfo(info);
} break;
// showInfo(info);
} break;
case PIIntrospection::itContainers: {
pba.clear(); cs.get(pba);
pba.clear();
cs.get(pba);
PIVector<PIIntrospectionContainers::TypeInfo> data;
PIIntrospection::unpackContainers(pba, data);
#if PIP_VERSION >= PIP_MAKE_VERSION(2,35,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 35, 0)
prepareContainers(data);
#endif
widgetContainers->showContainers(data);
} break;
} break;
case PIIntrospection::itObjects: {
pba.clear(); cs.get(pba);
pba.clear();
cs.get(pba);
PIVector<PIIntrospection::ObjectInfo> objects;
PIIntrospection::unpackObjects(pba, objects);
widgetObjects->showObjects(objects);
} break;
} break;
case PIIntrospection::itThreads: {
pba.clear(); cs.get(pba);
pba.clear();
cs.get(pba);
PIVector<PIIntrospectionThreads::ThreadInfo> threads;
PIIntrospection::unpackThreads(pba, threads);
widgetThreads->showThreads(threads);
} break;
} break;
default: break;
}
}
@@ -237,14 +241,13 @@ void QPIIntrospector::peersChanged(const PIString & name) {
QString cs = listApp->currentItem() ? listApp->currentItem()->text() : "";
listApp->clear();
peer.lock();
piForeachC (PIPeer::PeerInfo & p, peer.allPeers()) {
piForeachC(PIPeer::PeerInfo & p, peer.allPeers()) {
QString pn = PI2QString(p.name);
if (!pn.contains(tag)) continue;
QListWidgetItem * li = new QListWidgetItem(pn.left(pn.indexOf(tag)));
li->setData(Qt::UserRole, pn);
listApp->addItem(li);
if (pn == cs)
listApp->setCurrentRow(listApp->count() - 1);
if (pn == cs) listApp->setCurrentRow(listApp->count() - 1);
}
peer.unlock();
listApp->blockSignals(false);
@@ -255,7 +258,7 @@ void QPIIntrospector::on_buttonRequest_clicked() {
if (cur_server.isEmpty()) return;
PIIntrospection::RequiredInfo info;
for (int i = 0; i < layoutRequestFlags->count(); ++i) {
QCheckBox * cb = qobject_cast<QCheckBox*>(layoutRequestFlags->itemAt(i)->widget());
QCheckBox * cb = qobject_cast<QCheckBox *>(layoutRequestFlags->itemAt(i)->widget());
if (!cb) continue;
if (!cb->isChecked()) continue;
info.types |= cb->property("__value__").toInt();

View File

@@ -1,26 +1,30 @@
#ifndef PIINTROSPECTOR_H
#define PIINTROSPECTOR_H
#include "piintrospection_server_p.h"
#include "pipeer.h"
#include "piqt.h"
#include "ui_piintrospector.h"
#include <QDebug>
#include <QImage>
#include <QTime>
#include <QDebug>
#include <emainwindow.h>
#include "piqt.h"
#include "pipeer.h"
#include "piintrospection_server_p.h"
class QPIIntrospector: public EMainWindow, private Ui::QPIIntrospector, public PIObject
{
class QPIIntrospector
: public EMainWindow
, private Ui::QPIIntrospector
, public PIObject {
Q_OBJECT
PIOBJECT(QPIIntrospector);
public:
QPIIntrospector(QWidget * parent = 0);
~QPIIntrospector();
protected:
void changeEvent(QEvent * e);
void timerEvent(QTimerEvent * );
void timerEvent(QTimerEvent *);
void savingSession(QPIConfig & conf);
void loadingSession(QPIConfig & conf);
@@ -37,7 +41,7 @@ protected:
PIIntrospection::ProcessStat stat;
PIPeer peer;
int request_timer, pip_timer;
private slots:
void buildTree(QByteArray d);
void procRequestTimer();
@@ -45,7 +49,6 @@ private slots:
void on_buttonRequest_clicked();
public slots:
};
#endif // PIINTROSPECTOR_H

View File

@@ -1,9 +1,8 @@
#include "piintrospector.h"
#include "qcodeedit.h"
#include <QApplication>
#include <QPlainTextEdit>
#include "piintrospector.h"
#include "qcodeedit.h"
int main(int argc, char * argv[]) {
QApplication a(argc, argv);
enableHighDPI();
@@ -11,24 +10,24 @@ int main(int argc, char * argv[]) {
/*QCodeEdit w;
w.setEditorFont(QFont("dejavu sans mono", 10));
w.setText(
"Telegram.addCommand(\"Поискать 💰\", \"find_money\");\n"
"Telegram.addCommand(\"🔍Исследования\", \"research\");\n"
"Telegram.addCommand(\"📖Инфо/🌍Планета\", \"planet_info\");\n"
"Telegram.addCommand(\"📖Инфо/💻Дерево исследований\", \"research_map\");\n"
"Telegram.addCommand(\"📖Инфо/🌌Сканер планет\", \"map_info\");\n"
"Telegram.addCommand(\"🛠Строительство/📖Инфо\", \"planet_info\");\n"
"Telegram.addCommand(\"🛠Строительство/⛏Шахта\", \"info_plant\");\n"
"Telegram.addCommand(\"🛠Строительство/⛏Шахта/📖Инфо\", \"info_plant\");\n"
"Telegram.addCommand(\"🛠Строительство/⛏Шахта/🛠Cтроить ⛏Шахту\", \"build_plant\");\n"
"Telegram.addCommand(\"🛠Строительство/⚡️Электростанция\", \"info_solar\");\n"
"Telegram.addCommand(\"🛠Строительство/⚡️Электростанция/📖Инфо\", \"info_solar\");\n"
"Telegram.addCommand(\"🛠Строительство/⚡️Электростанция/🛠Cтроить ⚡️Электростанцию\", \"build_solar\");\n"
"Telegram.addCommand(\"🛠Строительство/🔋Аккумулятор\", \"info_accum\");\n"
"Telegram.addCommand(\"🛠Строительство/🔋Аккумулятор/📖Инфо\", \"info_accum\");\n"
"Telegram.addCommand(\"🛠Строительство/🔋Аккумулятор/🛠Cтроить 🔋Аккумулятор\", \"build_accum\");\n"
"Telegram.addCommand(\"🛠Строительство/📦Хранилище\", \"info_storage\");\n"
"Telegram.addCommand(\"🛠Строительство/📦Хранилище/📖Инфо\", \"info_storage\");\n"
);
"Telegram.addCommand(\"Поискать 💰\", \"find_money\");\n"
"Telegram.addCommand(\"🔍Исследования\", \"research\");\n"
"Telegram.addCommand(\"📖Инфо/🌍Планета\", \"planet_info\");\n"
"Telegram.addCommand(\"📖Инфо/💻Дерево исследований\", \"research_map\");\n"
"Telegram.addCommand(\"📖Инфо/🌌Сканер планет\", \"map_info\");\n"
"Telegram.addCommand(\"🛠Строительство/📖Инфо\", \"planet_info\");\n"
"Telegram.addCommand(\"🛠Строительство/⛏Шахта\", \"info_plant\");\n"
"Telegram.addCommand(\"🛠Строительство/⛏Шахта/📖Инфо\", \"info_plant\");\n"
"Telegram.addCommand(\"🛠Строительство/⛏Шахта/🛠Cтроить ⛏Шахту\", \"build_plant\");\n"
"Telegram.addCommand(\"🛠Строительство/⚡️Электростанция\", \"info_solar\");\n"
"Telegram.addCommand(\"🛠Строительство/⚡️Электростанция/📖Инфо\", \"info_solar\");\n"
"Telegram.addCommand(\"🛠Строительство/⚡️Электростанция/🛠Cтроить ⚡️Электростанцию\", \"build_solar\");\n"
"Telegram.addCommand(\"🛠Строительство/🔋Аккумулятор\", \"info_accum\");\n"
"Telegram.addCommand(\"🛠Строительство/🔋Аккумулятор/📖Инфо\", \"info_accum\");\n"
"Telegram.addCommand(\"🛠Строительство/🔋Аккумулятор/🛠Cтроить 🔋Аккумулятор\", \"build_accum\");\n"
"Telegram.addCommand(\"🛠Строительство/📦Хранилище\", \"info_storage\");\n"
"Telegram.addCommand(\"🛠Строительство/📦Хранилище/📖Инфо\", \"info_storage\");\n"
);
//w.textEdit()->setCursorWidth(1);*/
w.show();
return a.exec();

View File

@@ -1,10 +1,12 @@
#include "threads_view.h"
#include <QTreeView>
#include <QPainter>
#include <QStyle>
#include <QSortFilterProxyModel>
#include "ccm_piintrospector.h"
#include <QPainter>
#include <QSortFilterProxyModel>
#include <QStyle>
#include <QTreeView>
enum ColumnThreads {
ctClassname,
@@ -19,13 +21,11 @@ enum ColumnThreads {
};
ThreadsModel::ThreadsModel() {
PICodeInfo::EnumInfo * ei = PICodeInfo::enumsInfo->value("PIIntrospectionThreads::ThreadState");
if (ei) {
piForeachC (PICodeInfo::EnumeratorInfo & e, ei->members) {
#if PIP_VERSION >= PIP_MAKE_VERSION(2,39,0)
piForeachC(PICodeInfo::EnumeratorInfo & e, ei->members) {
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 39, 0)
state_names[e.value] = PI2QString(e.name.mid(1).toString());
#else
state_names[e.value] = PI2QString(e.name.mid(1));
@@ -51,7 +51,7 @@ void ThreadsModel::update(const PIVector<PIIntrospectionThreads::ThreadInfo> & t
endRemoveRows();
}
dataChanged(index(0, 0), index(threads.size_s() - 1, columnCount()));
//emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
// emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
}
@@ -94,13 +94,13 @@ QVariant ThreadsModel::headerData(int section, Qt::Orientation orientation, int
if (orientation != Qt::Horizontal || role != Qt::DisplayRole) return QVariant();
switch (section) {
case ctClassname: return tr("Classname");
case ctName : return tr("Name");
case ctID : return tr("pID (pri)");
case ctDelay : return tr("Delay, ms");
case ctState : return tr("State");
case ctLoad : return tr("CPU, %");
case ctRunCost : return tr("Run cost, avg");
case ctRunCount : return tr("Run counts");
case ctName: return tr("Name");
case ctID: return tr("pID (pri)");
case ctDelay: return tr("Delay, ms");
case ctState: return tr("State");
case ctLoad: return tr("CPU, %");
case ctRunCost: return tr("Run cost, avg");
case ctRunCount: return tr("Run counts");
default: break;
}
return QVariant();
@@ -113,26 +113,32 @@ QVariant ThreadsModel::data(const QModelIndex & index, int role) const {
if (role == Qt::DisplayRole) {
switch (index.column()) {
case ctClassname: return PI2QString(ti.classname);
case ctName : return PI2QString(ti.name);
case ctID : return QString("%1 (%2)").arg(ti.id).arg(ti.priority);
case ctDelay : return QString::number(ti.delay);
case ctState : return state_names.value(ti.state);
case ctLoad : {
piForeachC (PISystemMonitor::ThreadStats & s, stat) {
case ctName: return PI2QString(ti.name);
case ctID: return QString("%1 (%2)").arg(ti.id).arg(ti.priority);
case ctDelay: return QString::number(ti.delay);
case ctState: return state_names.value(ti.state);
case ctLoad: {
piForeachC(PISystemMonitor::ThreadStats & s, stat) {
if (s.id == llong(ti.id)) {
return QString::number(s.cpu_load_kernel + s.cpu_load_user, 'f', 2) + " %";
}
}
return "-";
}
case ctRunCost : {
double v = ti.run_us;
}
case ctRunCost: {
double v = ti.run_us;
QByteArray suff = " us";
if (v > 1000.) {v /= 1000.; suff = " ms";}
if (v > 1000.) {v /= 1000.; suff = " s";}
return QString::number(v, 'f', 1) + suff;
if (v > 1000.) {
v /= 1000.;
suff = " ms";
}
case ctRunCount : return QString::number(ti.run_count);
if (v > 1000.) {
v /= 1000.;
suff = " s";
}
return QString::number(v, 'f', 1) + suff;
}
case ctRunCount: return QString::number(ti.run_count);
}
}
if (index.column() == ctState) {
@@ -152,43 +158,39 @@ Qt::ItemFlags ThreadsModel::flags(const QModelIndex & index) const {
}
/*
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));
}
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));
}
}
*/
ThreadsView::ThreadsView(QWidget * parent): QWidget(parent) {
setupUi(this);
model = new ThreadsModel();
model = new ThreadsModel();
QSortFilterProxyModel * proxy = new QSortFilterProxyModel();
proxy->setSourceModel(model);
proxy->setSortRole(Qt::UserRole);
proxy->setDynamicSortFilter(false);
treeThreads->setModel(model);
connect(checkHideStopped, SIGNAL(toggled(bool)), this, SLOT(updateHidden()));
//treeContainers->setItemDelegate(new ContainersDelegate(model));
// treeContainers->setItemDelegate(new ContainersDelegate(model));
}
ThreadsView::~ThreadsView() {
}
ThreadsView::~ThreadsView() {}
void ThreadsView::setStat(const PIVector<PISystemMonitor::ThreadStats> & stat) {
@@ -199,20 +201,18 @@ void ThreadsView::setStat(const PIVector<PISystemMonitor::ThreadStats> & stat) {
void ThreadsView::changeEvent(QEvent * e) {
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
case QEvent::LanguageChange: retranslateUi(this); break;
default: break;
}
}
void ThreadsView::updateHidden() {
bool hide_stopped = checkHideStopped->isChecked();
QModelIndex root = treeThreads->rootIndex();
QModelIndex root = treeThreads->rootIndex();
for (int i = 0; i < model->rowCount(); ++i) {
if (!hide_stopped) treeThreads->setRowHidden(i, root, false);
if (!hide_stopped)
treeThreads->setRowHidden(i, root, false);
else {
if (model->index(i, ctState).data(Qt::UserRole).toInt() == PIIntrospectionThreads::sStopped)
treeThreads->setRowHidden(i, root, true);

View File

@@ -1,20 +1,22 @@
#ifndef THREADS_VIEW_H
#define THREADS_VIEW_H
#include "ui_threads_view.h"
#include <QDebug>
#include <QWidget>
#include <QHash>
#include <QTreeView>
#include <QAbstractItemModel>
#include <QStyledItemDelegate>
#include "piintrospection_threads_p.h"
#include "piqt.h"
#include "pisystemmonitor.h"
#include "piintrospection_threads_p.h"
#include "ui_threads_view.h"
#include <QAbstractItemModel>
#include <QDebug>
#include <QHash>
#include <QStyledItemDelegate>
#include <QTreeView>
#include <QWidget>
class ThreadsModel: public QAbstractItemModel {
Q_OBJECT
public:
ThreadsModel();
@@ -24,7 +26,7 @@ public:
int rowCount(const QModelIndex & parent = QModelIndex()) const;
int columnCount(const QModelIndex & parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex & child) const {return QModelIndex();}
QModelIndex parent(const QModelIndex & child) const { return QModelIndex(); }
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
@@ -36,25 +38,25 @@ protected:
PIVector<PISystemMonitor::ThreadStats> stat;
QHash<int, QString> state_names;
QHash<int, QColor> state_colors;
};
/*
class ContainersDelegate: public QStyledItemDelegate {
Q_OBJECT
Q_OBJECT
public:
ContainersDelegate(QAbstractItemModel * m) {model = m;}
void paint(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex &index) const override;
QAbstractItemModel * model;
ContainersDelegate(QAbstractItemModel * m) {model = m;}
void paint(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex &index) const override;
QAbstractItemModel * model;
};
*/
class ThreadsView: public QWidget, private Ui::ThreadsView
{
class ThreadsView
: public QWidget
, private Ui::ThreadsView {
Q_OBJECT
public:
ThreadsView(QWidget * parent = 0);
~ThreadsView();
@@ -69,12 +71,11 @@ protected:
ThreadsModel * model;
private slots:
void sessionSave(QByteArray * data) {*data = treeThreads->header()->saveState();}
void sessionLoad(QByteArray * data) {treeThreads->header()->restoreState(*data);}
void sessionSave(QByteArray * data) { *data = treeThreads->header()->saveState(); }
void sessionLoad(QByteArray * data) { treeThreads->header()->restoreState(*data); }
void updateHidden();
public slots:
};