You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
3.2 KiB
137 lines
3.2 KiB
15 years ago
|
/* This file is part of KCachegrind.
|
||
|
Copyright (C) 2002, 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
|
||
|
|
||
|
KCachegrind is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation, version 2.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; see the file COPYING. If not, write to
|
||
15 years ago
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
15 years ago
|
*/
|
||
|
|
||
|
#include <math.h>
|
||
|
|
||
14 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqregexp.h>
|
||
15 years ago
|
|
||
|
#include <klocale.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kapplication.h>
|
||
|
|
||
|
#include "listutils.h"
|
||
|
#include "costlistitem.h"
|
||
|
#include "coverage.h"
|
||
|
#include "configuration.h"
|
||
|
|
||
|
// CostListItem
|
||
|
|
||
|
|
||
13 years ago
|
CostListItem::CostListItem(TQListView* parent, TraceCostItem* costItem,
|
||
15 years ago
|
TraceCostType* ct, int size)
|
||
13 years ago
|
:TQListViewItem(parent)
|
||
15 years ago
|
{
|
||
|
_groupSize = size;
|
||
|
_skipped = 0;
|
||
|
_costItem = costItem;
|
||
|
setCostType(ct);
|
||
|
|
||
|
if (costItem) {
|
||
|
updateName();
|
||
|
setPixmap(1, colorPixmap(10, 10,
|
||
|
Configuration::groupColor(_costItem)));
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
CostListItem::CostListItem(TQListView* parent, int skipped,
|
||
15 years ago
|
TraceCostItem* costItem, TraceCostType* ct)
|
||
13 years ago
|
:TQListViewItem(parent)
|
||
15 years ago
|
{
|
||
|
_skipped = skipped;
|
||
|
_costItem = costItem;
|
||
|
setCostType(ct);
|
||
|
|
||
|
setText(1, i18n("(%n item skipped)", "(%n items skipped)", _skipped));
|
||
|
}
|
||
|
|
||
|
void CostListItem::setCostType(TraceCostType* ct)
|
||
|
{
|
||
|
_costType = ct;
|
||
|
update();
|
||
|
}
|
||
|
|
||
|
void CostListItem::updateName()
|
||
|
{
|
||
|
if (!_costItem) return;
|
||
|
|
||
14 years ago
|
TQString n = _costItem->prettyName();
|
||
13 years ago
|
if (_groupSize>=0) n += TQString(" (%1)").arg(_groupSize);
|
||
15 years ago
|
|
||
|
setText(1, n);
|
||
|
}
|
||
|
|
||
|
void CostListItem::setSize(int s)
|
||
|
{
|
||
|
_groupSize = s;
|
||
|
updateName();
|
||
|
}
|
||
|
|
||
|
void CostListItem::update()
|
||
|
{
|
||
|
if (!_costItem) return;
|
||
|
TraceData* d = _costItem->data();
|
||
|
|
||
|
double total = d->subCost(_costType);
|
||
|
if (total == 0.0) {
|
||
14 years ago
|
setText(0, TQString("---"));
|
||
|
setPixmap(0, TQPixmap());
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
_pure = _costItem->subCost(_costType);
|
||
|
double pure = 100.0 * _pure / total;
|
||
14 years ago
|
TQString str;
|
||
15 years ago
|
if (Configuration::showPercentage())
|
||
13 years ago
|
str = TQString("%1").arg(pure, 0, 'f', Configuration::percentPrecision());
|
||
15 years ago
|
else
|
||
|
str = _costItem->prettySubCost(_costType);
|
||
|
|
||
|
if (_skipped) {
|
||
|
// special handling for skip entries...
|
||
13 years ago
|
setText(0, TQString("< %1").arg(str));
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
setText(0, str);
|
||
|
setPixmap(0, costPixmap(_costType, _costItem, total, false));
|
||
|
}
|
||
|
|
||
14 years ago
|
int CostListItem::compare(TQListViewItem * i, int col, bool ascending ) const
|
||
15 years ago
|
{
|
||
|
const CostListItem* fi1 = this;
|
||
|
const CostListItem* fi2 = (CostListItem*) i;
|
||
|
|
||
|
// we always want descending order
|
||
|
if (ascending) {
|
||
|
fi1 = fi2;
|
||
|
fi2 = this;
|
||
|
}
|
||
|
|
||
|
// a skip entry is always sorted last
|
||
|
if (fi1->_skipped) return -1;
|
||
|
if (fi2->_skipped) return 1;
|
||
|
|
||
|
if (col==0) {
|
||
|
if (fi1->_pure < fi2->_pure) return -1;
|
||
|
if (fi1->_pure > fi2->_pure) return 1;
|
||
|
return 0;
|
||
|
}
|
||
14 years ago
|
return TQListViewItem::compare(i, col, ascending);
|
||
15 years ago
|
}
|