OSDN Git Service

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