From: Milian Wolff Date: Thu, 10 Sep 2015 15:33:39 +0000 (+0200) Subject: Add basic tooltip functionality for stacked time charts X-Git-Tag: submit/tizen/20180620.112952^2~284 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=65a4e0a40613e502dc4e21df6b828c135c8a6143;p=sdk%2Ftools%2Fheaptrack.git Add basic tooltip functionality for stacked time charts --- diff --git a/gui/chartmodel.cpp b/gui/chartmodel.cpp index bc4f348..56ef325 100644 --- a/gui/chartmodel.cpp +++ b/gui/chartmodel.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -33,6 +34,23 @@ QColor colorForColumn(int column, int columnCount) { return QColor::fromHsv((1. - double(column + 1) / columnCount) * 255, 255, 255); } + +QVector columnValue(const ChartRows& data, int column) +{ + if (column == ChartModel::LeakedColumn) { + return data.leaked; + } else if (column == ChartModel::AllocationsColumn) { + return data.allocations; + } else { + return data.allocated; + } +} + +ChartRow indexValue(const ChartRows& data, int idx, int column) +{ + const auto& values = columnValue(data, column); + return idx < values.size() ? values[idx] : ChartRow(); +} } ChartModel::ChartModel(QObject* parent) @@ -90,23 +108,20 @@ QVariant ChartModel::data(const QModelIndex& index, int role) const return {}; } - if ( role == Qt::ToolTipRole ) { - // TODO - return {}; - } - const auto& data = m_data.at(index.row()); + if (column == TimeStampColumn) { return data.timeStamp; } - if (column == LeakedColumn) { - return idx < data.leaked.size() ? data.leaked[idx].cost : 0; - } else if (column == AllocationsColumn) { - return idx < data.allocations.size() ? data.allocations[idx].cost : 0; - } else { - return idx < data.allocated.size() ? data.allocated[idx].cost : 0; + const auto& chartRow = indexValue(data, idx, column); + + if ( role == Qt::ToolTipRole ) { + // TODO: use correct label for column, format cost and time properly in a human readable way + return i18n("%1: %2 at %3", chartRow.function, chartRow.cost, data.timeStamp); } + + return chartRow.cost; } int ChartModel::columnCount(const QModelIndex& /*parent*/) const diff --git a/gui/chartproxy.cpp b/gui/chartproxy.cpp index 2f8ce09..9b2e741 100644 --- a/gui/chartproxy.cpp +++ b/gui/chartproxy.cpp @@ -20,6 +20,8 @@ #include "chartproxy.h" #include "chartmodel.h" +#include + ChartProxy::ChartProxy(const QString& label, int column, QObject* parent) : QSortFilterProxyModel(parent) , m_label(label) @@ -37,6 +39,18 @@ QVariant ChartProxy::headerData(int section, Qt::Orientation orientation, int ro return QSortFilterProxyModel::headerData(section, orientation, role); } +QVariant ChartProxy::data(const QModelIndex& proxyIndex, int role) const +{ + static_assert(ChartModel::TimeStampColumn == 0, "The code below assumes the time stamp column comes with value 0."); + if (role == Qt::ToolTipRole && proxyIndex.column() == 0) { + // KChart queries the tooltip for the timestamp column, which is not useful for us + // instead, we want to use the m_column, or in proxy column value that is 1 + return QSortFilterProxyModel::data(index(proxyIndex.row(), 1, proxyIndex.parent()), role); + } else { + return QSortFilterProxyModel::data(proxyIndex, role); + } +} + bool ChartProxy::filterAcceptsColumn(int sourceColumn, const QModelIndex& /*sourceParent*/) const { const auto column = sourceColumn % 4; diff --git a/gui/chartproxy.h b/gui/chartproxy.h index d03a54b..3ed8e00 100644 --- a/gui/chartproxy.h +++ b/gui/chartproxy.h @@ -29,8 +29,10 @@ public: explicit ChartProxy(const QString& label, int column, QObject* parent = nullptr); virtual ~ChartProxy(); -protected: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + QVariant data(const QModelIndex & proxyIndex, int role = Qt::DisplayRole) const override; + +protected: bool filterAcceptsColumn(int sourceColumn, const QModelIndex& sourceParent) const override; private: @@ -38,4 +40,4 @@ private: int m_column; }; -#endif //CHARTPROXY_H \ No newline at end of file +#endif //CHARTPROXY_H