2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-05-06 15:05:37 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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);
|
2012-05-02 13:10:14 +02:00
|
|
|
setWidthFactor(4.0);
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(ok, return);
|
|
|
|
|
QTC_ASSERT(costs >= 0.0 && costs <= 100.0, return);
|
2011-04-04 14:39:29 +02:00
|
|
|
|
|
|
|
|
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 *>();
|
|
|
|
|
}
|
|
|
|
|
|