2011-04-04 14:39:29 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2011-05-06 15:05:37 +02:00
|
|
|
** This file is part of Qt Creator
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-05-06 15:05:37 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2011-05-06 15:05:37 +02:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "callgrindtextmark.h"
|
|
|
|
|
|
|
|
|
|
#include "callgrindhelper.h"
|
|
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
#include "callgrind/callgrinddatamodel.h"
|
|
|
|
|
#include "callgrind/callgrindfunction.h"
|
2011-04-04 14:39:29 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QPainter>
|
2011-04-04 14:39:29 +02:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
using namespace Valgrind::Internal;
|
2011-04-04 14:39:29 +02:00
|
|
|
using namespace Valgrind::Callgrind;
|
|
|
|
|
|
|
|
|
|
CallgrindTextMark::CallgrindTextMark(const QPersistentModelIndex &index,
|
|
|
|
|
const QString &fileName, int lineNumber)
|
2012-02-08 17:21:12 +01:00
|
|
|
: TextEditor::BaseTextMark(fileName, lineNumber), m_modelIndex(index)
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
|
|
|
|
setPriority(TextEditor::ITextMark::HighPriority);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindTextMark::paint(QPainter *painter, const QRect &paintRect) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_modelIndex.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool ok;
|
2011-04-05 11:11:57 +02:00
|
|
|
qreal costs = m_modelIndex.data(RelativeTotalCostRole).toReal(&ok);
|
2011-04-04 14:39:29 +02:00
|
|
|
QTC_ASSERT(ok, return)
|
|
|
|
|
QTC_ASSERT(costs >= 0.0 && costs <= 100.0, return)
|
|
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
|
|
|
|
|
|
// set up
|
|
|
|
|
painter->setPen(Qt::black);
|
|
|
|
|
|
|
|
|
|
// draw bar
|
|
|
|
|
QRect fillRect = paintRect;
|
|
|
|
|
fillRect.setWidth(paintRect.width() * costs);
|
|
|
|
|
painter->fillRect(paintRect, Qt::white);
|
|
|
|
|
painter->fillRect(fillRect, CallgrindHelper::colorForCostRatio(costs));
|
|
|
|
|
painter->drawRect(paintRect);
|
|
|
|
|
|
|
|
|
|
// draw text
|
|
|
|
|
const QTextOption flags = Qt::AlignHCenter | Qt::AlignVCenter;
|
|
|
|
|
const QString text = CallgrindHelper::toPercent(costs * 100.0f);
|
|
|
|
|
|
|
|
|
|
// decrease font size if paint rect is too small (very unlikely, but may happen)
|
|
|
|
|
QFont font = painter->font();
|
2012-03-13 17:10:23 +01:00
|
|
|
QFontMetrics fm = QFontMetrics(font);
|
2011-04-04 14:39:29 +02:00
|
|
|
while (fm.boundingRect(text).width() > paintRect.width()) {
|
|
|
|
|
font.setPointSize(font.pointSize() - 1);
|
2012-03-13 17:10:23 +01:00
|
|
|
fm = QFontMetrics(font);
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
painter->setFont(font);
|
|
|
|
|
|
|
|
|
|
painter->drawText(paintRect, text, flags);
|
|
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-18 17:05:49 +02:00
|
|
|
const Function *CallgrindTextMark::function() const
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
|
|
|
|
if (!m_modelIndex.isValid())
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return m_modelIndex.data(DataModel::FunctionRole).value<const Function *>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double CallgrindTextMark::widthFactor() const
|
|
|
|
|
{
|
|
|
|
|
return 4.0;
|
|
|
|
|
}
|