File 2003-tooltip.patch of Package libksysguard6
diff --git a/processcore/process_data_model.cpp b/processcore/process_data_model.cpp
index 7eb4c8494336c9f7aa5e2253cf3de0296faa19ca..9b5ff78812a6e7f50846367788531f9e69686595 100644
--- a/processcore/process_data_model.cpp
+++ b/processcore/process_data_model.cpp
@@ -13,6 +13,8 @@
#include "processcore/process_attribute_model.h"
#include "processcore/process_data_provider.h"
+#include <KLocalizedString>
+
#include <QMetaEnum>
#include <QTimer>
@@ -31,6 +33,7 @@ public:
void update();
QModelIndex getQModelIndex(Process *process, int column) const;
+ QString toolTipForIndex(const QModelIndex &index, bool scaled = false) const;
ProcessDataModel *q;
KSysGuard::Process *m_rootProcess;
@@ -108,6 +111,10 @@ QVariant ProcessDataModel::data(const QModelIndex &index, int role) const
const QVariant value = attribute->data(process);
return KSysGuard::Formatter::formatValue(value, attribute->unit());
}
+ case Qt::ToolTipRole:
+ return d->toolTipForIndex(index);
+ case ScaledToolTipRole:
+ return d->toolTipForIndex(index, true);
case Value: {
KSysGuard::Process *process = reinterpret_cast<KSysGuard::Process *>(index.internalPointer());
const QVariant value = attribute->data(process);
@@ -395,6 +402,107 @@ QModelIndex ProcessDataModel::Private::getQModelIndex(KSysGuard::Process *proces
return q->createIndex(row, column, process);
}
+QString ProcessDataModel::Private::toolTipForIndex(const QModelIndex &index, bool scaled) const
+{
+ QString toolTip;
+
+ if (!index.isValid()) {
+ return toolTip;
+ }
+
+ const KSysGuard::ProcessAttribute *attribute = m_enabledAttributes.value(index.column());
+ if (!attribute) {
+ return toolTip;
+ }
+
+ KSysGuard::Process *process = reinterpret_cast<KSysGuard::Process *>(index.internalPointer());
+ if (!process) {
+ return toolTip;
+ }
+
+ QList<const KSysGuard::ProcessAttribute *> attributes;
+ if (attribute->id() == QStringLiteral("name")) {
+ attributes = {
+ attribute,
+ m_availableAttributes.value(QStringLiteral("pid")),
+ m_availableAttributes.value(QStringLiteral("username")),
+ m_availableAttributes.value(QStringLiteral("numThreads")),
+ m_availableAttributes.value(QStringLiteral("command")),
+ };
+ } else if (attribute->id() == QStringLiteral("usage")) {
+ attributes = {
+ attribute,
+ m_availableAttributes.value(QStringLiteral("userUsage")),
+ m_availableAttributes.value(QStringLiteral("sysUsage")),
+ m_availableAttributes.value(QStringLiteral("totalUserUsage")),
+ m_availableAttributes.value(QStringLiteral("totalSysUsage")),
+ m_availableAttributes.value(QStringLiteral("status")),
+ m_availableAttributes.value(QStringLiteral("numThreads")),
+ m_availableAttributes.value(QStringLiteral("niceLevel")),
+ };
+ } else if (attribute->id() == QStringLiteral("vmPSS")) {
+ attributes = {
+ attribute,
+ m_availableAttributes.value(QStringLiteral("vmURSS")),
+ m_availableAttributes.value(QStringLiteral("vmShared")),
+ };
+ }
+
+ if (!attributes.isEmpty()) {
+ QStringList toolTipParts;
+ for (auto attribute : std::as_const(attributes)) {
+ if (!attribute) {
+ continue;
+ }
+
+ static const QStringList scalableAttributeIds = {
+ QStringLiteral("usage"),
+ QStringLiteral("userUsage"),
+ QStringLiteral("sysUsage"),
+ QStringLiteral("totalUserUsage"),
+ QStringLiteral("totalSysUsage"),
+ };
+
+ QVariant value = attribute->data(process);
+ if (scaled && scalableAttributeIds.contains(attribute->id())) {
+ value = 100 * value.toReal() / attribute->max();
+ }
+ const QString formattedValue = KSysGuard::Formatter::formatValue(value, attribute->unit(), KSysGuard::MetricPrefixAutoAdjust, KSysGuard::FormatOptionShowNull);
+ if (!formattedValue.isEmpty()) {
+ toolTipParts << i18nc("@info:tooltip <key>: <value>", "%1: %2", attribute->name(), formattedValue);
+ }
+ }
+
+ if (attribute->id() == QStringLiteral("name")) {
+ int insertIndex = std::distance(attributes.cbegin(), std::find_if(attributes.cbegin(), attributes.cend(), [](const KSysGuard::ProcessAttribute *attribute) {
+ return attribute && attribute->id() == QStringLiteral("username");
+ }));
+
+ const long parentPid = process->parentPid();
+ if (parentPid != -1) {
+ const KSysGuard::Process *parentProcess = m_processes->getProcess(parentPid);
+ if (parentProcess) {
+ toolTipParts.insert(insertIndex++, i18nc("@info:tooltip <key>: <value>", "Parent: %1", parentProcess->name()));
+ toolTipParts.insert(insertIndex++, i18nc("@info:tooltip <key>: <value>", "Parent PID: %1", parentPid));
+ }
+ }
+
+ const long tracerPid = process->tracerpid();
+ if (tracerPid != -1) {
+ const KSysGuard::Process *tracerProcess = m_processes->getProcess(tracerPid);
+ if (tracerProcess) {
+ toolTipParts.insert(insertIndex++, i18nc("@info:tooltip <key>: <value>", "Tracer: %1", tracerProcess->name()));
+ toolTipParts.insert(insertIndex++, i18nc("@info:tooltip <key>: <value>", "Tracer PID: %1", tracerPid));
+ }
+ }
+ }
+
+ toolTip = toolTipParts.join(u'\n');
+ }
+
+ return toolTip;
+}
+
ProcessAttributeModel *ProcessDataModel::attributesModel()
{
// lazy load
diff --git a/processcore/process_data_model.h b/processcore/process_data_model.h
index 47d27ddd5fe505e5608942f4985c9ce0ca500144..124e6eb1da30f050a3afbc52c76f914981fd6a35 100644
--- a/processcore/process_data_model.h
+++ b/processcore/process_data_model.h
@@ -77,6 +77,8 @@ public:
Unit, /// The unit associated with this attribute. Returned value is of the type KSysGuard::Unit
UpdateInterval, /// The amount of time in milliseconds between each update of the model.
+
+ ScaledToolTipRole,
};
Q_ENUM(AdditionalRoles)