1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
/* -*- Mode: C++ -*-
$Id$
KDGantt - a multi-platform charting engine
*/
/****************************************************************************
** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
**
** This file is part of the KDGantt library.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid commercial KDGantt licenses may use this file in
** accordance with the KDGantt Commercial License Agreement provided with
** the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
** information about KDGantt Commercial License Agreements.
**
** Contact info@klaralvdalens-datakonsult.se if any conditions of this
** licensing are not clear to you.
**
** As a special exception, permission is given to link this program
** with any edition of Qt, and distribute the resulting executable,
** without including the source code for Qt in the source distribution.
**
**********************************************************************/
#include "KDGanttViewTaskLinkGroup.h"
#include "KDGanttXMLTools.h"
#include "KDGanttView.h"
QDict<KDGanttViewTaskLinkGroup> KDGanttViewTaskLinkGroup::sGroupDict;
/*! \class KDGanttViewTaskLinkGroup KDGanttViewTaskLinkGroup.h
A group of task links.
This class groups a number of task links together in order to
manipulate them uniformly.
*/
/*!
Constructs an empty task link group
*/
KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup()
{
generateAndInsertName(QString());
}
/*!
Destructor
Removes this task link group from the list of task link groups in the
KDGanttView class.
*/
KDGanttViewTaskLinkGroup::~KDGanttViewTaskLinkGroup()
{
if (!myTaskLinkList.isEmpty()) {
myTaskLinkList.first()->from().first()->myGanttView->removeTaskLinkGroup(this);
}
}
/*!
Constructs an empty task link group and records it under the name \a
name so that it can later be found again with
KDGanttViewTaskLinkGroup::find().
\param name the search name of this task link group
*/
KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup( const QString& name )
{
generateAndInsertName( name );
}
/*!
Adds a task link LINK to this group. If the task link is already a member of
another group, it will be removed from it.
This function is equivalent to LINK->setGroup(this), where this is
a pointer to this TaskLinkGroup.
\param link a pointer to the task link to add to this task link group
visible, and false to hide them
\sa remove()
*/
void KDGanttViewTaskLinkGroup::insert (KDGanttViewTaskLink* link)
{
link->setGroup(this);
}
/*!
Removes a task link LINK from this group.
You may remove a tasklink LINK from its group with LINK->setGroup(0).
\param link a pointer to the task link to remove from this task link group
\return true if the task link was a member of this group
\sa insert()
*/
bool KDGanttViewTaskLinkGroup::remove (KDGanttViewTaskLink* link)
{
KDGanttViewTaskLinkGroup* g = link->group();
if ((g == this))
link->setGroup(0);
return (g == this);
}
/*!
Specifies whether the task links of this group should be visible or not.
\param show visible pass true to make the task links of this group
visible, and false to hide them
\sa isVisible()
*/
void KDGanttViewTaskLinkGroup::setVisible( bool show )
{
isvisible = show;
QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
for ( ; it.current(); ++it ) {
it.current()->setVisible(show);
}
}
/*!
Returns whether the task links of this group should be visible or not.
\return true if the task links of this group are visible
\sa setVisible()
*/
bool KDGanttViewTaskLinkGroup::visible() const
{
return isvisible;
}
/*!
Specifies whether the task links of this group should be shown
highlighted. The user can also highlight a task link with the mouse.
\param highlight pass true in order to highlight the task links in
this group
\sa highlight()
*/
void KDGanttViewTaskLinkGroup::setHighlight( bool highlight )
{
ishighlighted= highlight;
QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
for ( ; it.current(); ++it )
it.current()->setHighlight(highlight );
}
/*!
Returns whether all task links in this group are highlighted, either
programmatically by setHighlight() or by the user with the
mouse. This method is not particularly useful and is mainly provided
for API uniformity reasons.
\return true if all the task links in this group are highlighted
\sa setHighlight()
*/
bool KDGanttViewTaskLinkGroup::highlight() const
{
return ishighlighted;
}
/*!
Specifies the color to draw the task links in this group in.
\param color the color to draw the task links in this group in
\sa color()
*/
void KDGanttViewTaskLinkGroup::setColor( const QColor& color )
{
myColor = color;
QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
for ( ; it.current(); ++it )
it.current()->setColor(color);
}
/*!
Returns the color in which the task links in this group are
drawn. If task links have been assigned individual colors, the
return value of this method is undefined. This method is not
particularly useful and is mainly provided for API uniformity
reasons.
\return the color in which the task links in this group are drawn
\sa setColor()
*/
QColor KDGanttViewTaskLinkGroup::color() const
{
return myColor;
}
/*!
Specifies the highlight color to draw the task links in this group in.
\param color the highlight color to draw the task links in this group in
\sa color()
*/
void KDGanttViewTaskLinkGroup::setHighlightColor( const QColor& color )
{
myColorHL = color;
QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
for ( ; it.current(); ++it )
it.current()->setHighlightColor(color);
}
/*!
Returns the highlight color in which the task links in this group are
drawn. If task links have been assigned individual highlight colors,
the return value of this method is undefined. This method is not
particularly useful and is mainly provided for API uniformity reasons.
\return the highlight color in which the task links in this group
are drawn
\sa setColor()
*/
QColor KDGanttViewTaskLinkGroup::highlightColor() const
{
return myColorHL;
}
/*!
Adds a task link LINK to this group. If the task link is already a member of
another group, it will not be removed from it.
\param a pointer to the task link to add to this task link group
visible, and false to hide them
\sa removeItem()
*/
void KDGanttViewTaskLinkGroup::insertItem (KDGanttViewTaskLink* link)
{
myTaskLinkList.append (link);
}
/*!
Removes a task link LINK from this group.
\param a pointer to the task link to remove from this task link group
\sa insertItem()
*/
void KDGanttViewTaskLinkGroup::removeItem (KDGanttViewTaskLink* link)
{
myTaskLinkList.remove(link);
}
/*!
Returns the task link group with the specified name.
\param name the name to search for
\return the task link group with the specified name; 0 if no group
with that name exists
*/
KDGanttViewTaskLinkGroup* KDGanttViewTaskLinkGroup::find( const QString& name )
{
if (name.isEmpty()) // avoid error msg from QDict
return 0;
return sGroupDict.find( name );
}
/*!
Creates a DOM node that describes this task link group.
\param doc the DOM document to which the node belongs
\param parentElement the element into which to insert this node
*/
void KDGanttViewTaskLinkGroup::createNode( QDomDocument& doc,
QDomElement& parentElement )
{
QDomElement taskLinkGroupElement = doc.createElement( "TaskLink" );
parentElement.appendChild( taskLinkGroupElement );
KDGanttXML::createBoolNode( doc, taskLinkGroupElement, "Highlight",
highlight() );
KDGanttXML::createColorNode( doc, taskLinkGroupElement, "Color", color() );
KDGanttXML::createColorNode( doc, taskLinkGroupElement, "HighlightColor",
highlightColor() );
KDGanttXML::createBoolNode( doc, taskLinkGroupElement, "Visible",
visible() );
KDGanttXML::createStringNode( doc, taskLinkGroupElement, "Name", _name );
}
/*!
Creates a KDGanttViewTaskLinkGroup according to the specification in a DOM
element.
\param element the DOM element from which to read the specification
\return the newly created task link group
*/
KDGanttViewTaskLinkGroup* KDGanttViewTaskLinkGroup::createFromDomElement( QDomElement& element )
{
QDomNode node = element.firstChild();
bool highlight = false, visible = false;
QColor color, highlightColor;
QString name;
while( !node.isNull() ) {
QDomElement element = node.toElement();
if( !element.isNull() ) { // was really an element
QString tagName = element.tagName();
if( tagName == "Highlight" ) {
bool value;
if( KDGanttXML::readBoolNode( element, value ) )
highlight = value;
} else if( tagName == "Visible" ) {
bool value;
if( KDGanttXML::readBoolNode( element, value ) )
visible = value;
} else if( tagName == "Color" ) {
QColor value;
if( KDGanttXML::readColorNode( element, value ) )
color = value;
} else if( tagName == "HighlightColor" ) {
QColor value;
if( KDGanttXML::readColorNode( element, value ) )
highlightColor = value;
} else if( tagName == "Name" ) {
QString value;
if( KDGanttXML::readStringNode( element, value ) )
name = value;
} else {
qDebug( "Unrecognized tag name: %s", tagName.latin1() );
Q_ASSERT( false );
}
}
node = node.nextSibling();
}
KDGanttViewTaskLinkGroup* tlg;
if( !name.isEmpty() )
tlg = new KDGanttViewTaskLinkGroup( name );
else
tlg = new KDGanttViewTaskLinkGroup();
tlg->setHighlight( highlight );
tlg->setVisible( visible );
tlg->setHighlightColor( highlightColor );
tlg->setColor( color );
return tlg;
}
/*!
Generates a unique name if necessary and inserts it into the group
dictionary.
*/
void KDGanttViewTaskLinkGroup::generateAndInsertName( const QString& name )
{
// First check if we already had a name. This can be the case if
// the item was reconstructed from an XML file.
if( !_name.isEmpty() )
// We had a name, remove it
sGroupDict.remove( _name );
QString newName;
if ( name.isEmpty() || sGroupDict.find( name ) ) {
// create unique name
newName.sprintf( "%p", (void* )this );
while( sGroupDict.find( newName ) ) {
newName += "_0";
}
} else {
newName = name;
}
sGroupDict.insert( newName, this );
_name = newName;
//qDebug("KDGanttViewTaskLinkGroup::generateAndInsertName: inserted '%s'",newName.latin1());
}
|