| 1 |
/* |
| 2 |
* ResourceList.cpp - TaskJuggler |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2001, 2002, 2003, 2004 Chris Schlaeger <[email protected]> |
| 5 |
* SPDX-FileCopyrightText: 2011 Dag Andersen <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of version 2 of the GNU General Public License as |
| 9 |
* published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* $Id$ |
| 12 |
*/ |
| 13 |
|
| 14 |
// clazy:excludeall=qstring-arg |
| 15 |
#include "ResourceList.h" |
| 16 |
|
| 17 |
#include "TjMessageHandler.h" |
| 18 |
#include "Resource.h" |
| 19 |
#include "Project.h" |
| 20 |
#include "UsageLimits.h" |
| 21 |
|
| 22 |
namespace TJ |
| 23 |
{ |
| 24 |
|
| 25 |
ResourceList::ResourceList() : |
| 26 |
CoreAttributesList() |
| 27 |
{ |
| 28 |
sorting[0] = CoreAttributesList::TreeMode; |
| 29 |
sorting[1] = CoreAttributesList::IdUp; |
| 30 |
} |
| 31 |
|
| 32 |
bool |
| 33 |
ResourceList::isSupportedSortingCriteria(int sc) |
| 34 |
{ |
| 35 |
switch (sc) |
| 36 |
{ |
| 37 |
case TreeMode: |
| 38 |
case MinEffortUp: |
| 39 |
case MinEffortDown: |
| 40 |
case MaxEffortUp: |
| 41 |
case MaxEffortDown: |
| 42 |
case RateUp: |
| 43 |
case RateDown: |
| 44 |
return true; |
| 45 |
default: |
| 46 |
return CoreAttributesList::isSupportedSortingCriteria(sc); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
int |
| 51 |
ResourceList::compareItemsLevel(CoreAttributes* c1, CoreAttributes* c2, |
| 52 |
int level) |
| 53 |
{ |
| 54 |
Resource* r1 = static_cast<Resource*>(c1); |
| 55 |
Resource* r2 = static_cast<Resource*>(c2); |
| 56 |
|
| 57 |
if (level < 0 || level >= maxSortingLevel) |
| 58 |
return -1; |
| 59 |
|
| 60 |
switch (sorting[level]) |
| 61 |
{ |
| 62 |
case TreeMode: |
| 63 |
if (level == 0) |
| 64 |
return compareTreeItemsT(this, r1, r2); |
| 65 |
else |
| 66 |
return r1->getSequenceNo() == r2->getSequenceNo() ? 0 : |
| 67 |
r1->getSequenceNo() < r2->getSequenceNo() ? -1 : 1; |
| 68 |
case MinEffortUp: |
| 69 |
return r1->minEffort == r2->minEffort ? 0 : |
| 70 |
r1->minEffort < r2->minEffort ? -1 : 1; |
| 71 |
case MinEffortDown: |
| 72 |
return r1->minEffort == r2->minEffort ? 0 : |
| 73 |
r1->minEffort < r2->minEffort ? 1 : -1; |
| 74 |
case MaxEffortUp: |
| 75 |
return r1->limits->getDailyMax() == r2->limits->getDailyMax() ? 0 : |
| 76 |
r1->limits->getDailyMax() < r2->limits->getDailyMax() ? -1 : 1; |
| 77 |
case MaxEffortDown: |
| 78 |
return r1->limits->getDailyMax() == r2->limits->getDailyMax() ? 0 : |
| 79 |
r1->limits->getDailyMax() < r2->limits->getDailyMax() ? 1 : -1; |
| 80 |
case RateUp: |
| 81 |
return r1->rate == r2->rate ? 0 : r1->rate < r2->rate ? -1 : 1; |
| 82 |
case RateDown: |
| 83 |
return r1->rate == r2->rate ? 0 : r1->rate < r2->rate ? 1 : -1; |
| 84 |
default: |
| 85 |
return CoreAttributesList::compareItemsLevel(r1, r2, level); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
Resource* |
| 90 |
ResourceList::getResource(const QString& id) const |
| 91 |
{ |
| 92 |
for (ResourceListIterator rli(*this); *rli != nullptr; ++rli) |
| 93 |
if ((*rli)->getId() == id) |
| 94 |
return *rli; |
| 95 |
|
| 96 |
return nullptr; |
| 97 |
} |
| 98 |
|
| 99 |
Resource* ResourceListIterator::operator*() |
| 100 |
{ |
| 101 |
return static_cast<Resource*>(CoreAttributesListIterator::operator*()); |
| 102 |
} |
| 103 |
|
| 104 |
} // namespace TJ |