forked from qt-creator/qt-creator
analyzer: re-organize the main models' ::data() functions
Change-Id: I14e152eebf8261741874443ce373dee9d2619c2c Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -169,38 +169,42 @@ QModelIndex CallModel::index(int row, int column, const QModelIndex &parent) con
|
|||||||
|
|
||||||
QVariant CallModel::data(const QModelIndex &index, int role) const
|
QVariant CallModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(index.isValid() && index.model() == this, return QVariant());
|
//QTC_ASSERT(index.isValid() && index.model() == this, return QVariant());
|
||||||
QTC_ASSERT(index.column() >= 0 && index.column() < columnCount(index.parent()), return QVariant());
|
//QTC_ASSERT(index.column() >= 0 && index.column() < columnCount(index.parent()), return QVariant());
|
||||||
QTC_ASSERT(index.row() >= 0 && index.row() < rowCount(index.parent()), return QVariant());
|
//QTC_ASSERT(index.row() >= 0 && index.row() < rowCount(index.parent()), return QVariant());
|
||||||
|
|
||||||
const FunctionCall *call = d->m_calls.at(index.row());
|
const FunctionCall *call = d->m_calls.at(index.row());
|
||||||
const quint64 callCost = call->cost(d->m_event);
|
if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
|
||||||
const quint64 parentCost = d->m_function->inclusiveCost(d->m_event);
|
|
||||||
if (role == ParentCostRole) {
|
|
||||||
return parentCost;
|
|
||||||
}
|
|
||||||
else if (role == FunctionCallRole
|
|
||||||
|| role == RelativeParentCostRole || role == RelativeTotalCostRole) {
|
|
||||||
if (role == FunctionCallRole)
|
|
||||||
return QVariant::fromValue(call);
|
|
||||||
|
|
||||||
if (role == RelativeTotalCostRole) {
|
|
||||||
const quint64 totalCost = d->m_data->totalCost(d->m_event);
|
|
||||||
return (float) callCost / totalCost;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (role == RelativeParentCostRole)
|
|
||||||
return (float) callCost / parentCost;
|
|
||||||
}
|
|
||||||
else if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
|
|
||||||
if (index.column() == CalleeColumn)
|
if (index.column() == CalleeColumn)
|
||||||
return call->callee()->name();
|
return call->callee()->name();
|
||||||
else if (index.column() == CallerColumn)
|
if (index.column() == CallerColumn)
|
||||||
return call->caller()->name();
|
return call->caller()->name();
|
||||||
else if (index.column() == CostColumn && role != Qt::ToolTipRole)
|
if (index.column() == CostColumn && role != Qt::ToolTipRole)
|
||||||
return callCost;
|
return call->cost(d->m_event);
|
||||||
else if (index.column() == CallsColumn && role != Qt::ToolTipRole)
|
if (index.column() == CallsColumn && role != Qt::ToolTipRole)
|
||||||
return call->calls();
|
return call->calls();
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == ParentCostRole) {
|
||||||
|
const quint64 parentCost = d->m_function->inclusiveCost(d->m_event);
|
||||||
|
return parentCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == FunctionCallRole) {
|
||||||
|
return QVariant::fromValue(call);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == RelativeTotalCostRole) {
|
||||||
|
const quint64 totalCost = d->m_data->totalCost(d->m_event);
|
||||||
|
const quint64 callCost = call->cost(d->m_event);
|
||||||
|
return double(callCost) / totalCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == RelativeParentCostRole) {
|
||||||
|
const quint64 parentCost = d->m_function->inclusiveCost(d->m_event);
|
||||||
|
const quint64 callCost = call->cost(d->m_event);
|
||||||
|
return double(callCost) / parentCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|||||||
@@ -217,40 +217,13 @@ static QString noWrap(const QString &str)
|
|||||||
|
|
||||||
QVariant DataModel::data(const QModelIndex &index, int role) const
|
QVariant DataModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(index.isValid() && index.model() == this, return QVariant());
|
//QTC_ASSERT(index.isValid() && index.model() == this, return QVariant());
|
||||||
QTC_ASSERT(index.column() >= 0 && index.column() < columnCount(index.parent()), return QVariant());
|
//QTC_ASSERT(index.column() >= 0 && index.column() < columnCount(index.parent()), return QVariant());
|
||||||
QTC_ASSERT(index.row() >= 0 && index.row() < rowCount(index.parent()), return QVariant());
|
//QTC_ASSERT(index.row() >= 0 && index.row() < rowCount(index.parent()), return QVariant());
|
||||||
|
|
||||||
const Function *func = d->m_functions.at(index.row());
|
const Function *func = d->m_functions.at(index.row());
|
||||||
const quint64 selfCost = func->selfCost(d->m_event);
|
|
||||||
const quint64 inclusiveCost = func->inclusiveCost(d->m_event);
|
|
||||||
const quint64 totalCost = d->m_data->totalCost(d->m_event);
|
|
||||||
|
|
||||||
if (role == FunctionRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
return QVariant::fromValue(func);
|
|
||||||
}
|
|
||||||
else if (role == ParentCostRole) {
|
|
||||||
return totalCost;
|
|
||||||
}
|
|
||||||
// the data model does not know about parent<->child relationship
|
|
||||||
else if (role == RelativeParentCostRole || role == RelativeTotalCostRole) {
|
|
||||||
if (index.column() == SelfCostColumn)
|
|
||||||
return (float)selfCost / totalCost;
|
|
||||||
if (index.column() == InclusiveCostColumn)
|
|
||||||
return (float)inclusiveCost / totalCost;
|
|
||||||
}
|
|
||||||
else if (role == LineNumberRole) {
|
|
||||||
return func->lineNumber();
|
|
||||||
}
|
|
||||||
else if (role == FileNameRole) {
|
|
||||||
return func->file();
|
|
||||||
}
|
|
||||||
else if (role == Qt::TextAlignmentRole) {
|
|
||||||
if (index.column() == CalledColumn) {
|
|
||||||
return Qt::AlignRight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (role == Qt::DisplayRole) {
|
|
||||||
if (index.column() == NameColumn)
|
if (index.column() == NameColumn)
|
||||||
return func->name();
|
return func->name();
|
||||||
if (index.column() == LocationColumn)
|
if (index.column() == LocationColumn)
|
||||||
@@ -258,10 +231,13 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
|
|||||||
if (index.column() == CalledColumn)
|
if (index.column() == CalledColumn)
|
||||||
return func->called();
|
return func->called();
|
||||||
if (index.column() == SelfCostColumn)
|
if (index.column() == SelfCostColumn)
|
||||||
return selfCost;
|
return func->selfCost(d->m_event);
|
||||||
if (index.column() == InclusiveCostColumn)
|
if (index.column() == InclusiveCostColumn)
|
||||||
return inclusiveCost;
|
return func->inclusiveCost(d->m_event);
|
||||||
} else if (role == Qt::ToolTipRole) {
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == Qt::ToolTipRole) {
|
||||||
if (!d->m_verboseToolTips)
|
if (!d->m_verboseToolTips)
|
||||||
return data(index, Qt::DisplayRole);
|
return data(index, Qt::DisplayRole);
|
||||||
|
|
||||||
@@ -317,6 +293,38 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role == FunctionRole) {
|
||||||
|
return QVariant::fromValue(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == ParentCostRole) {
|
||||||
|
const quint64 totalCost = d->m_data->totalCost(d->m_event);
|
||||||
|
return totalCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the data model does not know about parent<->child relationship
|
||||||
|
if (role == RelativeParentCostRole || role == RelativeTotalCostRole) {
|
||||||
|
const quint64 totalCost = d->m_data->totalCost(d->m_event);
|
||||||
|
if (index.column() == SelfCostColumn)
|
||||||
|
return double(func->selfCost(d->m_event)) / totalCost;
|
||||||
|
if (index.column() == InclusiveCostColumn) {
|
||||||
|
return double(func->inclusiveCost(d->m_event)) / totalCost;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == LineNumberRole) {
|
||||||
|
return func->lineNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == FileNameRole) {
|
||||||
|
return func->file();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == Qt::TextAlignmentRole) {
|
||||||
|
if (index.column() == CalledColumn)
|
||||||
|
return Qt::AlignRight;
|
||||||
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user