OSDN Git Service

Removing redundant error checking related to booking declaration.
[tjqt4port/tj2qt4.git] / taskjuggler / CoreAttributesList.h
1 /*
2  * CoreAttributesList.h - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
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 #ifndef _CoreAttributesList_h_
13 #define _CoreAttributesList_h_
14
15 #include <qptrlist.h>
16
17 #include "CoreAttributes.h"
18
19 class QString;
20
21 /**
22  * @short The class stores a list of CoreAttributes.
23  * @see CoreAttributes
24  * @author Chris Schlaeger <cs@kde.org>
25  */
26 class CoreAttributesList : public QPtrList<CoreAttributes>
27 {
28 public:
29     CoreAttributesList()
30     {
31         for (int i = 0; i < maxSortingLevel; i++)
32             sorting[i] = SequenceUp;
33     }
34     CoreAttributesList(const CoreAttributesList& l) :
35         QPtrList<CoreAttributes>(l)
36     {
37         for (int i = 0; i < maxSortingLevel; i++)
38             sorting[i] = l.sorting[i];
39     }
40
41     virtual ~CoreAttributesList();
42
43     void deleteContents();
44
45     enum SortCriteria {
46         SequenceUp = 0, SequenceDown,
47         TreeMode, NameUp, NameDown, FullNameUp,
48         FullNameDown, IdUp, IdDown, IndexUp, IndexDown,
49         StatusUp, StatusDown, CompletedUp, CompletedDown,
50         PrioUp, PrioDown,
51         ResponsibleUp, ResponsibleDown,
52         MinEffortUp, MinEffortDown,
53         MaxEffortUp, MaxEffortDown,
54         RateUp, RateDown,
55         StartUp, StartDown, EndUp, EndDown,
56         CriticalnessUp, CriticalnessDown,
57         PathCriticalnessUp, PathCriticalnessDown
58     };
59
60     static const int maxSortingLevel = 3;
61     void setSorting(int s, int level);
62     void createIndex(bool initial = false);
63     int getIndex(const QString& id) const;
64     uint maxDepth() const;
65
66     static bool isSupportedSortingCriteria(int sc);
67
68     virtual int compareItemsLevel(CoreAttributes* c1, CoreAttributes* c2,
69                                   int level);
70
71 protected:
72     virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
73
74     int sorting[maxSortingLevel];
75 } ;
76
77 /**
78  * @short Iterator for CoreAttributesList objects.
79  * @author Chris Schlaeger <cs@kde.org>
80  */
81 class CoreAttributesListIterator : public QPtrListIterator<CoreAttributes>
82 {
83 public:
84     CoreAttributesListIterator(const CoreAttributesList& l) :
85         QPtrListIterator<CoreAttributes>(l) { }
86     virtual ~CoreAttributesListIterator() { }
87 } ;
88
89 template<class TL, class T> int compareTreeItemsT(TL* list, T* c1, T* c2)
90 {
91     if (c1 == c2)
92         return 0;
93
94     QPtrList<T> cl1, cl2;
95     int res1 = 0;
96     for ( ; c1 || c2; )
97     {
98         if (c1)
99         {
100             cl1.prepend(c1);
101             c1 = c1->getParent();
102         }
103         else
104             res1 = -1;
105         if (c2)
106         {
107             cl2.prepend(c2);
108             c2 = c2->getParent();
109         }
110         else
111             res1 = 1;
112     }
113
114     QPtrListIterator<T> cal1(cl1);
115     QPtrListIterator<T> cal2(cl2);
116     for ( ; *cal1 != 0 && *cal2 != 0; ++cal1, ++cal2)
117     {
118         int res;
119         for (int j = 1; j < CoreAttributesList::maxSortingLevel; ++j)
120         {
121             if ((res = list->compareItemsLevel(*cal1, *cal2, j)) != 0)
122                 return res;
123         }
124         if ((res = (*cal1)->getSequenceNo() - (*cal2)->getSequenceNo()) != 0)
125             return res < 0 ? -1 : 1;
126     }
127     return res1;
128 }
129
130 #endif
131