2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-05-06 15:05:37 +02:00
|
|
|
**
|
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>
|
|
|
|
|
|
2018-05-02 15:02:00 +02:00
|
|
|
using namespace Utils;
|
2011-05-23 13:50:28 +02:00
|
|
|
using namespace Valgrind::Internal;
|
2011-04-04 14:39:29 +02:00
|
|
|
using namespace Valgrind::Callgrind;
|
|
|
|
|
|
2015-04-17 12:46:28 +02:00
|
|
|
namespace Constants { const char CALLGRIND_TEXT_MARK_CATEGORY[] = "Callgrind.Textmark"; }
|
|
|
|
|
|
2011-04-04 14:39:29 +02:00
|
|
|
CallgrindTextMark::CallgrindTextMark(const QPersistentModelIndex &index,
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath &fileName, int lineNumber)
|
2017-03-16 10:50:58 +01:00
|
|
|
: TextEditor::TextMark(fileName, lineNumber, Constants::CALLGRIND_TEXT_MARK_CATEGORY, 4.0)
|
2015-04-17 12:46:28 +02:00
|
|
|
, m_modelIndex(index)
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
2014-07-19 11:27:28 +02:00
|
|
|
setPriority(TextEditor::TextMark::HighPriority);
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-20 08:28:10 +02:00
|
|
|
void CallgrindTextMark::paintIcon(QPainter *painter, const QRect &paintRect) const
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
|
|
|
|
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())
|
2018-12-10 08:11:18 +01:00
|
|
|
return nullptr;
|
2011-04-04 14:39:29 +02:00
|
|
|
|
|
|
|
|
return m_modelIndex.data(DataModel::FunctionRole).value<const Function *>();
|
|
|
|
|
}
|
|
|
|
|
|