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