Debian Codegraph @

src/plugins/schedulers/tj/taskjuggler/CoreAttributesList.h

raw
1 /*
2 * CoreAttributesList.h - 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 #ifndef _CoreAttributesList_h_
14 #define _CoreAttributesList_h_
15
16 #include "plantj_export.h"
17
18 #include <QList>
19
20 #include "CoreAttributes.h"
21
22 class QString;
23
24 namespace TJ
25 {
26
27 /**
28 * @short The class stores a list of CoreAttributes.
29 * @see CoreAttributes
30 * @author Chris Schlaeger <[email protected]>
31 */
32 class PLANTJ_EXPORT CoreAttributesList : public QList<CoreAttributes*>
33 {
34 public:
35 CoreAttributesList() : m_autodelete(false)
36 {
37 for (int i = 0; i < maxSortingLevel; i++)
38 sorting[i] = SequenceUp;
39 }
40 CoreAttributesList(const CoreAttributesList& l) :
41 QList<CoreAttributes*>(l),
42 m_autodelete(false)
43 {
44 for (int i = 0; i < maxSortingLevel; i++)
45 sorting[i] = l.sorting[i];
46 }
47
48 virtual ~CoreAttributesList();
49
50 void setAutoDelete(bool on);
51 bool autoDelete() const;
52
53 void deleteContents();
54
55 enum SortCriteria {
56 SequenceUp = 0, SequenceDown,
57 TreeMode, NameUp, NameDown, FullNameUp,
58 FullNameDown, IdUp, IdDown, IndexUp, IndexDown,
59 StatusUp, StatusDown, CompletedUp, CompletedDown,
60 PrioUp, PrioDown,
61 ResponsibleUp, ResponsibleDown,
62 MinEffortUp, MinEffortDown,
63 MaxEffortUp, MaxEffortDown,
64 RateUp, RateDown,
65 StartUp, StartDown, EndUp, EndDown,
66 CriticalnessUp, CriticalnessDown,
67 PathCriticalnessUp, PathCriticalnessDown
68 };
69
70 static const int maxSortingLevel = 3;
71 void setSorting(int s, int level);
72 int getSorting(int level) const { return level < maxSortingLevel ? sorting[ level ] : 0; }
73 void sort();
74 void createIndex(bool initial = false);
75 int getIndex(const QString& id) const;
76 uint maxDepth() const;
77
78 static bool isSupportedSortingCriteria(int sc);
79
80 virtual int compareItemsLevel(CoreAttributes* c1, CoreAttributes* c2,
81 int level);
82
83 int inSort(CoreAttributes *attr);
84
85 static QStringList getSortCriteria();
86
87 protected:
88 virtual int compareItems(CoreAttributes* c1, CoreAttributes* c2);
89
90 bool m_autodelete;
91 int sorting[maxSortingLevel];
92 } ;
93
94 /**
95 * @short Iterator for CoreAttributesList objects.
96 * @author Chris Schlaeger <[email protected]>
97 */
98 class CoreAttributesListIterator : public QListIterator<CoreAttributes*>
99 {
100 public:
101 explicit CoreAttributesListIterator(const CoreAttributesList& l) :
102 QListIterator<CoreAttributes*>(l) { }
103 virtual ~CoreAttributesListIterator() { }
104 void operator++() { if (hasNext()) next(); }
105 CoreAttributes *operator*() { return hasNext() ? peekNext() : nullptr; }
106 } ;
107
108 template<class TL, class T> int compareTreeItemsT(TL* list, T* c1, T* c2)
109 {
110 if (c1 == c2)
111 return 0;
112
113 QList<T*> cl1, cl2;
114 int res1 = 0;
115 for (; c1 || c2;)
116 {
117 if (c1)
118 {
119 cl1.prepend(c1);
120 c1 = c1->getParent();
121 }
122 else
123 res1 = -1;
124 if (c2)
125 {
126 cl2.prepend(c2);
127 c2 = c2->getParent();
128 }
129 else
130 res1 = 1;
131 }
132
133 QListIterator<T*> cal1(cl1);
134 QListIterator<T*> cal2(cl2);
135 while (cal1.hasNext() && cal2.hasNext())
136 {
137 CoreAttributes *a1 = cal1.next();
138 CoreAttributes *a2 = cal2.next();
139 int res;
140 for (int j = 1; j < CoreAttributesList::maxSortingLevel; ++j)
141 {
142 if ((res = list->compareItemsLevel(a1, a2, j)) != 0)
143 return res;
144 }
145 if ((res = a1->getSequenceNo() - a2->getSequenceNo()) != 0)
146 return res < 0 ? -1 : 1;
147 }
148 return res1;
149 }
150
151 } // namespace TJ
152
153 PLANTJ_EXPORT QDebug operator<<(QDebug dbg, const TJ::CoreAttributesList& lst);
154
155 #endif