1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
/*
* The TaskJuggler Project Management Software
*
* Copyright (c) 2001, 2002, 2003, 2004, 2005 by Chris Schlaeger <cs@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* $Id$
*/
#include "TjResourceReport.h"
#include <qcanvas.h>
#include <klistview.h>
#include <klocale.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kdebug.h>
#include <kcursor.h>
#include <kmessagebox.h>
#include "Project.h"
#include "Resource.h"
#include "ExpressionTree.h"
#include "QtResourceReport.h"
#include "TjPrintResourceReport.h"
#include "TjGanttChart.h"
TjResourceReport::TjResourceReport(QWidget* p, ReportManager* m,
Report* const rDef,
const QString& n) : TjReport(p, m, rDef, n)
{
}
TjResourceReport::~TjResourceReport()
{
}
TjPrintReport*
TjResourceReport::newPrintReport(KPrinter* pr)
{
return new TjPrintResourceReport(report, pr);
}
QtReportElement*
TjResourceReport::getReportElement() const
{
return reportElement;
}
bool
TjResourceReport::generateList()
{
// Remove all items and columns from list view.
listView->clear();
ca2lviDict.clear();
lvi2caDict.clear();
while (listView->columns())
listView->removeColumn(0);
maxDepth = 0;
if (!report)
return false;
// We need those values frequently. So let's store them in a more
// accessible place.
reportElement = dynamic_cast<QtResourceReportElement*>(
dynamic_cast<QtResourceReport*>(report)->getTable());
scenario = reportElement->getScenario(0);
resourceList = report->getProject()->getResourceList();
taskList = report->getProject()->getTaskList();
if (!reportElement->filterResourceList
(resourceList, 0, reportElement->getHideResource(), 0))
return false;
reportElement->sortResourceList(resourceList);
if (resourceList.isEmpty())
return true;
generateListHeader(i18n("Resource"), reportElement);
/* The resource list need to be generated in two phases. First we insert
* all resources and the nested tasks, and then we fill the rest of all
* the lines. For some columns we need to know the maximum tree depth, so
* we have to fill the table first with all entries before we can fill
* those columns. */
int i = 0;
bool treeMode = reportElement->getResourceSorting(0) ==
CoreAttributesList::TreeMode;
for (ResourceListIterator rli(resourceList); *rli; ++rli)
{
/* Create a new item. If it has a parent, we need to look up the
* parent LVI, so it get's inserted as child of that parent. */
KListViewItem* newLvi;
if ((*rli)->getParent() && treeMode &&
resourceList.findRef((*rli)->getParent()) >= 0 &&
ca2lviDict[QString("r:") + (*rli)->getParent()->getId()])
newLvi = new KListViewItem
(ca2lviDict[QString("r:") + (*rli)->getParent()->getId()],
(*rli)->getName());
else
newLvi = new KListViewItem(listView, (*rli)->getName());
newLvi->setText(1, QString().sprintf("%07d", i++));
// Store the new LVI into the dictionary and check if we have reached
// a new tree level maximum.
ca2lviDict[QString("r:") + (*rli)->getId()] = newLvi;
lvi2caDict[QString().sprintf("%p", newLvi)] = *rli;
if (treeLevel(newLvi) > maxDepth)
maxDepth = treeLevel(newLvi);
if ((*rli)->hasSubs())
{
// We have just inserted a resource group. So we need to check
// whether the resource group's children should be shown or not.
// The user can specify this in the report declaration.
newLvi->setPixmap(0, KGlobal::iconLoader()->
loadIcon("tj_resource_group", KIcon::Small));
if (reportElement->getRollUpResource())
{
if (!report->isRolledUp(*rli,
reportElement->getRollUpResource()))
newLvi->setOpen(true);
// Check if during the evaluation of the expression an error
// had occured.
if (reportElement->getRollUpResource()->getErrorFlag())
return false;
}
else
newLvi->setOpen(true);
}
else
{
// We have just inserted an idividual resource.
newLvi->setPixmap(0, KGlobal::iconLoader()->loadIcon
("tj_resource", KIcon::Small));
newLvi->setOpen(false);
// Now we add all tasks that this resource is working on, if the
// user did not want to hide this task.
TaskList filteredTaskList = taskList;
if (!reportElement->filterTaskList
(filteredTaskList, *rli, reportElement->getHideTask(), 0))
return false;
reportElement->sortTaskList(filteredTaskList);
for (TaskListIterator tli(filteredTaskList); *tli; ++tli)
{
/* We iterate through the filtered task list and check whether
* we need to insert the tasks in a tree or not. */
int parentIdx = 0;
KListViewItem* lvi;
if ((*tli)->getParent() &&
reportElement->showTaskTree() &&
(parentIdx =
filteredTaskList.findRef((*tli)->getParent())) >= 0)
{
// Find the corresponding parent LVI and insert the task
// as a child of it.
CoreAttributes* parent = filteredTaskList.at(parentIdx);
KListViewItem* parentLvi =
ca2lviDict[QString("t:") + (*rli)->getId() +
":" + parent->getId()];
lvi = new KListViewItem(parentLvi, (*tli)->getName());
}
else
{
// Insert the task as child of the resource.
lvi = new KListViewItem(newLvi, (*tli)->getName());
}
lvi->setText(1, QString().sprintf("%07d", i++));
// The the proper icon for the task.
lvi->setPixmap(0, KGlobal::iconLoader()->
loadIcon(((*tli)->isContainer() ?
"tj_task_group" : "tj_task"),
KIcon::Small));
// Insert the task in the LVI lookup dictionary.
ca2lviDict[QString("t:") + (*rli)->getId() +
":" + (*tli)->getId()] = lvi;
lvi2caDict[QString().sprintf("%p", lvi)] = *tli;
lvi2ParentCaDict[QString().sprintf("%p", lvi)] = *rli;
// Adjust the maxDepth setting if new treelevel maximum has
// been found.
if (treeLevel(lvi) > maxDepth)
maxDepth = treeLevel(lvi);
}
}
}
// Now we know the maximum tree depth and can fill in the rest of the
// columns.
for (ResourceListIterator rli(resourceList); *rli; ++rli)
{
generateResourceListLine
(reportElement,
*rli, ca2lviDict[QString("r:") + (*rli)->getId()]);
if (!(*rli)->hasSubs())
{
for (TaskListIterator tli((*rli)->getTaskListIterator(scenario));
*tli; ++tli)
{
KListViewItem* lvi = ca2lviDict[QString("t:") +
(*rli)->getId() + ":" + (*tli)->getId()];
// Some tasks may be hidden, so we have to ignore those.
if (lvi)
generateTaskListLine(reportElement, *tli, lvi, *rli);
}
}
}
return true;
}
QString
TjResourceReport::generateStatusBarText(const QPoint& pos,
CoreAttributes* ca,
CoreAttributes* parent)
{
QPoint chartPos = ganttChartView->viewportToContents(pos);
time_t refTime = ganttChart->x2time(chartPos.x());
Interval iv = ganttChart->stepInterval(refTime);
QString ivName = ganttChart->stepIntervalName(refTime);
QString text;
if (ca->getType() == CA_Task)
{
Task* t = dynamic_cast<Task*>(ca);
Resource* r = dynamic_cast<Resource*>(parent);
double load = t->getLoad(scenario, iv, r);
double allocatedTimeLoad = t->getAllocatedTimeLoad(scenario, iv, r);
text = i18n("%1(%2) - %3 - Effort: %4 Allocated Time: %5 Task %6(%7)")
.arg(r->getName())
.arg(r->getId())
.arg(ivName)
.arg(reportElement->scaledLoad
(load, report->getNumberFormat(), true, false))
.arg(reportElement->scaledLoad
(allocatedTimeLoad, report->getNumberFormat(), true, false))
.arg(t->getName())
.arg(t->getId());
}
else
{
Resource* r = dynamic_cast<Resource*>(ca);
double load = r->getEffectiveLoad(scenario, iv, AllAccounts);
double allocatedTimeLoad = r->getAllocatedTimeLoad
(scenario, iv, AllAccounts);
double freeLoad = r->getEffectiveFreeLoad(scenario, iv);
double freeTimeLoad = r->getAvailableTimeLoad (scenario, iv);
double totalLoad = load + freeLoad;
double totalTimeLoad = allocatedTimeLoad + freeTimeLoad;
text = i18n("%1(%2) - %3 - Effort: %4 (%5%) "
"Allocated Time: %6 (%7%) Free: %8")
.arg(r->getName())
.arg(r->getId())
.arg(ivName)
.arg(reportElement->scaledLoad
(load, report->getNumberFormat(), true, false))
.arg(totalLoad > 0.0 ? (int) ((load / totalLoad) * 100.0): 100)
.arg(reportElement->scaledLoad
(allocatedTimeLoad, report->getNumberFormat(), true, false))
.arg(totalTimeLoad > 0.0 ?
(int) ((allocatedTimeLoad / totalTimeLoad) * 100.0) : 100)
.arg(reportElement->scaledLoad
(freeLoad, report->getNumberFormat(), true, false));
}
return text;
}
|