Waste less space in nested layouts.
[kdepim.git] / kdgantt1 / KDGanttViewTaskLinkGroup.cpp
blob13da879a889455ae44aeeb78d120a2178266c70c
1 /* -*- Mode: C++ -*-
2 $Id$
3 KDGantt - a multi-platform charting engine
4 */
5 /****************************************************************************
6 ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
7 **
8 ** This file is part of the KDGantt library.
9 **
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).
17 **
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.
22 **
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.
47 /*!
48 Constructs an empty task link group
50 KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup()
55 /*!
56 Destructor
57 Removes this task link group from the list of task link groups in the
58 KDGanttView class.
60 KDGanttViewTaskLinkGroup::~KDGanttViewTaskLinkGroup()
62 if (!myTaskLinkList.isEmpty()) {
63 KDGanttViewItem* item = myTaskLinkList.first()->from().first();
64 KDGanttView * gv = 0;
65 if ( item )
66 gv = item->myGanttView;
67 KDGanttViewTaskLink * tl = myTaskLinkList.first();
68 while ( tl ) {
69 tl->resetGroup();
70 tl = myTaskLinkList.next();
72 if ( gv )
73 gv->removeTaskLinkGroup(this);
79 /*!
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 );
89 _name = name;
93 /*!
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
100 \sa remove()
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
114 \sa insert()
116 bool KDGanttViewTaskLinkGroup::remove (KDGanttViewTaskLink* link)
118 KDGanttViewTaskLinkGroup* g = link->group();
119 if ((g == this))
120 link->setGroup(0);
121 return (g == this);
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
130 \sa isVisible()
132 void KDGanttViewTaskLinkGroup::setVisible( bool show )
134 isvisible = 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
146 \sa setVisible()
148 bool KDGanttViewTaskLinkGroup::visible() const
150 return isvisible;
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
159 this group
160 \sa highlight()
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
179 \sa setHighlight()
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
191 \sa color()
193 void KDGanttViewTaskLinkGroup::setColor( const QColor& color )
195 myColor = 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
207 reasons.
209 \return the color in which the task links in this group are drawn
210 \sa setColor()
212 QColor KDGanttViewTaskLinkGroup::color() const
214 return myColor;
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
222 \sa color()
224 void KDGanttViewTaskLinkGroup::setHighlightColor( const QColor& color )
227 myColorHL = 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
241 are drawn
242 \sa setColor()
244 QColor KDGanttViewTaskLinkGroup::highlightColor() const
246 return myColorHL;
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
255 \sa removeItem()
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
267 \sa insertItem()
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",
301 highlight() );
302 KDGanttXML::createColorNode( doc, taskLinkGroupElement, "Color", color() );
303 KDGanttXML::createColorNode( doc, taskLinkGroupElement, "HighlightColor",
304 highlightColor() );
305 KDGanttXML::createBoolNode( doc, taskLinkGroupElement, "Visible",
306 visible() );
307 KDGanttXML::createStringNode( doc, taskLinkGroupElement, "Name", _name );
312 Creates a KDGanttViewTaskLinkGroup according to the specification in a DOM
313 element.
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;
323 QString name;
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" ) {
329 bool value;
330 if( KDGanttXML::readBoolNode( element, value ) )
331 highlight = value;
332 } else if( tagName == "Visible" ) {
333 bool value;
334 if( KDGanttXML::readBoolNode( element, value ) )
335 visible = value;
336 } else if( tagName == "Color" ) {
337 QColor value;
338 if( KDGanttXML::readColorNode( element, value ) )
339 color = value;
340 } else if( tagName == "HighlightColor" ) {
341 QColor value;
342 if( KDGanttXML::readColorNode( element, value ) )
343 highlightColor = value;
344 } else if( tagName == "Name" ) {
345 QString value;
346 if( KDGanttXML::readStringNode( element, value ) )
347 name = value;
348 } else {
349 qDebug( "Unrecognized tag name: %s", qPrintable(tagName) );
350 Q_ASSERT( false );
353 node = node.nextSibling();
356 KDGanttViewTaskLinkGroup* tlg;
357 if( !name.isEmpty() )
358 tlg = new KDGanttViewTaskLinkGroup( name );
359 else
360 tlg = new KDGanttViewTaskLinkGroup();
362 tlg->setHighlight( highlight );
363 tlg->setVisible( visible );
364 tlg->setHighlightColor( highlightColor );
365 tlg->setColor( color );
367 return tlg;