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,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);