3 KDGantt - a multi-platform charting engine
5 /****************************************************************************
6 ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
8 ** This file is part of the KDGantt library.
10 ** This file may be used under the terms of the GNU General Public
11 ** License versions 2.0 or 3.0 as published by the Free Software
12 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
13 ** included in the packaging of this file. Alternatively you may (at
14 ** your option) use any later version of the GNU General Public
15 ** License if such license has been publicly approved by
16 ** Klarälvdalens Datakonsult AB (or its successors, if any).
18 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
19 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
20 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
21 ** not expressly granted herein.
23 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 ** As a special exception, permission is given to link this program
27 ** with any edition of Qt, and distribute the resulting executable,
28 ** without including the source code for Qt in the source distribution.
30 **********************************************************************/
33 #include "KDGanttView.h"
35 #include "KDGanttViewTaskLinkGroup.h"
36 #include "KDGanttXMLTools.h"
38 QDict
<KDGanttViewTaskLinkGroup
> KDGanttViewTaskLinkGroup::sGroupDict
;
40 /*! \class KDGanttViewTaskLinkGroup KDGanttViewTaskLinkGroup.h
41 A group of task links.
43 This class groups a number of task links together in order to
44 manipulate them uniformly.
48 Constructs an empty task link group
50 KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup()
57 Removes this task link group from the list of task link groups in the
60 KDGanttViewTaskLinkGroup::~KDGanttViewTaskLinkGroup()
62 if (!myTaskLinkList
.isEmpty()) {
63 KDGanttViewItem
* item
= myTaskLinkList
.first()->from().first();
66 gv
= item
->myGanttView
;
67 KDGanttViewTaskLink
* tl
= myTaskLinkList
.first();
70 tl
= myTaskLinkList
.next();
73 gv
->removeTaskLinkGroup(this);
80 Constructs an empty task link group and records it under the name \a
81 name so that it can later be found again with
82 KDGanttViewTaskLinkGroup::find().
84 \param name the search name of this task link group
86 KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup( const QString
& name
)
88 sGroupDict
.insert( name
, this );
94 Adds a task link LINK to this group. If the task link is already a member of
95 another group, it will be removed from it.
96 This function is equivalent to LINK->setGroup(this), where this is
97 a pointer to this TaskLinkGroup.
98 \param link a pointer to the task link to add to this task link group
99 visible, and false to hide them
102 void KDGanttViewTaskLinkGroup::insert (KDGanttViewTaskLink
* link
)
104 link
->setGroup(this);
109 Removes a task link LINK from this group.
110 You may remove a tasklink LINK from its group with LINK->setGroup(0).
112 \param link a pointer to the task link to remove from this task link group
113 \return true if the task link was a member of this group
116 bool KDGanttViewTaskLinkGroup::remove (KDGanttViewTaskLink
* link
)
118 KDGanttViewTaskLinkGroup
* g
= link
->group();
126 Specifies whether the task links of this group should be visible or not.
128 \param show visible pass true to make the task links of this group
129 visible, and false to hide them
132 void KDGanttViewTaskLinkGroup::setVisible( bool show
)
135 QPtrListIterator
<KDGanttViewTaskLink
> it(myTaskLinkList
);
136 for ( ; it
.current(); ++it
) {
137 it
.current()->setVisible(show
);
143 Returns whether the task links of this group should be visible or not.
145 \return true if the task links of this group are visible
148 bool KDGanttViewTaskLinkGroup::visible() const
155 Specifies whether the task links of this group should be shown
156 highlighted. The user can also highlight a task link with the mouse.
158 \param highlight pass true in order to highlight the task links in
162 void KDGanttViewTaskLinkGroup::setHighlight( bool highlight
)
164 ishighlighted
= highlight
;
165 QPtrListIterator
<KDGanttViewTaskLink
> it(myTaskLinkList
);
166 for ( ; it
.current(); ++it
)
167 it
.current()->setHighlight(highlight
);
173 Returns whether all task links in this group are highlighted, either
174 programmatically by setHighlight() or by the user with the
175 mouse. This method is not particularly useful and is mainly provided
176 for API uniformity reasons.
178 \return true if all the task links in this group are highlighted
181 bool KDGanttViewTaskLinkGroup::highlight() const
183 return ishighlighted
;
188 Specifies the color to draw the task links in this group in.
190 \param color the color to draw the task links in this group in
193 void KDGanttViewTaskLinkGroup::setColor( const QColor
& color
)
196 QPtrListIterator
<KDGanttViewTaskLink
> it(myTaskLinkList
);
197 for ( ; it
.current(); ++it
)
198 it
.current()->setColor(color
);
203 Returns the color in which the task links in this group are
204 drawn. If task links have been assigned individual colors, the
205 return value of this method is undefined. This method is not
206 particularly useful and is mainly provided for API uniformity
209 \return the color in which the task links in this group are drawn
212 QColor
KDGanttViewTaskLinkGroup::color() const
219 Specifies the highlight color to draw the task links in this group in.
221 \param color the highlight color to draw the task links in this group in
224 void KDGanttViewTaskLinkGroup::setHighlightColor( const QColor
& color
)
228 QPtrListIterator
<KDGanttViewTaskLink
> it(myTaskLinkList
);
229 for ( ; it
.current(); ++it
)
230 it
.current()->setHighlightColor(color
);
235 Returns the highlight color in which the task links in this group are
236 drawn. If task links have been assigned individual highlight colors,
237 the return value of this method is undefined. This method is not
238 particularly useful and is mainly provided for API uniformity reasons.
240 \return the highlight color in which the task links in this group
244 QColor
KDGanttViewTaskLinkGroup::highlightColor() const
251 Adds a task link LINK to this group. If the task link is already a member of
252 another group, it will not be removed from it.
253 \param a pointer to the task link to add to this task link group
254 visible, and false to hide them
257 void KDGanttViewTaskLinkGroup::insertItem (KDGanttViewTaskLink
* link
)
259 myTaskLinkList
.append (link
);
264 Removes a task link LINK from this group.
266 \param a pointer to the task link to remove from this task link group
269 void KDGanttViewTaskLinkGroup::removeItem (KDGanttViewTaskLink
* link
)
271 myTaskLinkList
.remove(link
);
276 Returns the task link group with the specified name.
278 \param name the name to search for
279 \return the task link group with the specified name; 0 if no group
280 with that name exists
282 KDGanttViewTaskLinkGroup
* KDGanttViewTaskLinkGroup::find( const QString
& name
)
284 return sGroupDict
.find( name
);
289 Creates a DOM node that describes this task link group.
291 \param doc the DOM document to which the node belongs
292 \param parentElement the element into which to insert this node
294 void KDGanttViewTaskLinkGroup::createNode( QDomDocument
& doc
,
295 QDomElement
& parentElement
)
297 QDomElement taskLinkGroupElement
= doc
.createElement( "TaskLink" );
298 parentElement
.appendChild( taskLinkGroupElement
);
300 KDGanttXML::createBoolNode( doc
, taskLinkGroupElement
, "Highlight",
302 KDGanttXML::createColorNode( doc
, taskLinkGroupElement
, "Color", color() );
303 KDGanttXML::createColorNode( doc
, taskLinkGroupElement
, "HighlightColor",
305 KDGanttXML::createBoolNode( doc
, taskLinkGroupElement
, "Visible",
307 KDGanttXML::createStringNode( doc
, taskLinkGroupElement
, "Name", _name
);
312 Creates a KDGanttViewTaskLinkGroup according to the specification in a DOM
315 \param element the DOM element from which to read the specification
316 \return the newly created task link group
318 KDGanttViewTaskLinkGroup
* KDGanttViewTaskLinkGroup::createFromDomElement( QDomElement
& element
)
320 QDomNode node
= element
.firstChild();
321 bool highlight
= false, visible
= false;
322 QColor color
, highlightColor
;
324 while( !node
.isNull() ) {
325 QDomElement element
= node
.toElement();
326 if( !element
.isNull() ) { // was really an element
327 QString tagName
= element
.tagName();
328 if( tagName
== "Highlight" ) {
330 if( KDGanttXML::readBoolNode( element
, value
) )
332 } else if( tagName
== "Visible" ) {
334 if( KDGanttXML::readBoolNode( element
, value
) )
336 } else if( tagName
== "Color" ) {
338 if( KDGanttXML::readColorNode( element
, value
) )
340 } else if( tagName
== "HighlightColor" ) {
342 if( KDGanttXML::readColorNode( element
, value
) )
343 highlightColor
= value
;
344 } else if( tagName
== "Name" ) {
346 if( KDGanttXML::readStringNode( element
, value
) )
349 qDebug( "Unrecognized tag name: %s", qPrintable(tagName
) );
353 node
= node
.nextSibling();
356 KDGanttViewTaskLinkGroup
* tlg
;
357 if( !name
.isEmpty() )
358 tlg
= new KDGanttViewTaskLinkGroup( name
);
360 tlg
= new KDGanttViewTaskLinkGroup();
362 tlg
->setHighlight( highlight
);
363 tlg
->setVisible( visible
);
364 tlg
->setHighlightColor( highlightColor
);
365 tlg
->setColor( color
);