kdgantt

KDGanttViewTaskLinkGroup.cpp
1 /*
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 distributed and/or modified under the terms of the
11  ** GNU General Public License version 2 as published by the Free Software
12  ** Foundation and appearing in the file LICENSE.GPL included in the
13  ** packaging of this file.
14  **
15  ** Licensees holding valid commercial KDGantt licenses may use this file in
16  ** accordance with the KDGantt Commercial License Agreement provided with
17  ** the Software.
18  **
19  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21  **
22  ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
23  ** information about KDGantt Commercial License Agreements.
24  **
25  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
26  ** licensing are not clear to you.
27  **
28  ** As a special exception, permission is given to link this program
29  ** with any edition of TQt, and distribute the resulting executable,
30  ** without including the source code for TQt in the source distribution.
31  **
32  **********************************************************************/
33 
34 
35 #include "KDGanttViewTaskLinkGroup.h"
36 #include "KDGanttXMLTools.h"
37 #include "KDGanttView.h"
38 
39 TQDict<KDGanttViewTaskLinkGroup> KDGanttViewTaskLinkGroup::sGroupDict;
40 
52 {
53  generateAndInsertName(TQString());
54 }
55 
62 {
63  if (!myTaskLinkList.isEmpty()) {
64  myTaskLinkList.first()->from().first()->myGanttView->removeTaskLinkGroup(this);
65  }
66 }
67 
68 
69 
78 {
79  generateAndInsertName( name );
80 }
81 
92 {
93  link->setGroup(this);
94 }
95 
96 
106 {
107  KDGanttViewTaskLinkGroup* g = link->group();
108  if ((g == this))
109  link->setGroup(0);
110  return (g == this);
111 }
112 
113 
122 {
123  isvisible = show;
124  TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
125  for ( ; it.current(); ++it ) {
126  it.current()->setVisible(show);
127  }
128 }
129 
130 
138 {
139  return isvisible;
140 }
141 
142 
152 {
153  ishighlighted= highlight;
154  TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
155  for ( ; it.current(); ++it )
156  it.current()->setHighlight(highlight );
157 
158 }
159 
160 
171 {
172  return ishighlighted;
173 }
174 
175 
182 void KDGanttViewTaskLinkGroup::setColor( const TQColor& color )
183 {
184  myColor = color;
185  TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
186  for ( ; it.current(); ++it )
187  it.current()->setColor(color);
188 }
189 
190 
202 {
203  return myColor;
204 }
205 
206 
214 {
215 
216  myColorHL = color;
217  TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
218  for ( ; it.current(); ++it )
219  it.current()->setHighlightColor(color);
220 }
221 
222 
234 {
235  return myColorHL;
236 }
237 
238 
246 void KDGanttViewTaskLinkGroup::insertItem (KDGanttViewTaskLink* link)
247 {
248  myTaskLinkList.append (link);
249 }
250 
251 
258 void KDGanttViewTaskLinkGroup::removeItem (KDGanttViewTaskLink* link)
259 {
260  myTaskLinkList.remove(link);
261 }
262 
263 
272 {
273  if (name.isEmpty()) // avoid error msg from TQDict
274  return 0;
275  return sGroupDict.find( name );
276 }
277 
278 
285 void KDGanttViewTaskLinkGroup::createNode( TQDomDocument& doc,
286  TQDomElement& parentElement )
287 {
288  TQDomElement taskLinkGroupElement = doc.createElement( "TaskLink" );
289  parentElement.appendChild( taskLinkGroupElement );
290 
291  KDGanttXML::createBoolNode( doc, taskLinkGroupElement, "Highlight",
292  highlight() );
293  KDGanttXML::createColorNode( doc, taskLinkGroupElement, "Color", color() );
294  KDGanttXML::createColorNode( doc, taskLinkGroupElement, "HighlightColor",
295  highlightColor() );
296  KDGanttXML::createBoolNode( doc, taskLinkGroupElement, "Visible",
297  visible() );
298  KDGanttXML::createStringNode( doc, taskLinkGroupElement, "Name", _name );
299 }
300 
301 
310 {
311  TQDomNode node = element.firstChild();
312  bool highlight = false, visible = false;
313  TQColor color, highlightColor;
314  TQString name;
315  while( !node.isNull() ) {
316  TQDomElement element = node.toElement();
317  if( !element.isNull() ) { // was really an element
318  TQString tagName = element.tagName();
319  if( tagName == "Highlight" ) {
320  bool value;
321  if( KDGanttXML::readBoolNode( element, value ) )
322  highlight = value;
323  } else if( tagName == "Visible" ) {
324  bool value;
325  if( KDGanttXML::readBoolNode( element, value ) )
326  visible = value;
327  } else if( tagName == "Color" ) {
328  TQColor value;
329  if( KDGanttXML::readColorNode( element, value ) )
330  color = value;
331  } else if( tagName == "HighlightColor" ) {
332  TQColor value;
333  if( KDGanttXML::readColorNode( element, value ) )
334  highlightColor = value;
335  } else if( tagName == "Name" ) {
336  TQString value;
337  if( KDGanttXML::readStringNode( element, value ) )
338  name = value;
339  } else {
340  tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
341  Q_ASSERT( false );
342  }
343  }
344  node = node.nextSibling();
345  }
346 
348  if( !name.isEmpty() )
349  tlg = new KDGanttViewTaskLinkGroup( name );
350  else
351  tlg = new KDGanttViewTaskLinkGroup();
352 
353  tlg->setHighlight( highlight );
354  tlg->setVisible( visible );
356  tlg->setColor( color );
357 
358  return tlg;
359 }
360 
366 {
367  // First check if we already had a name. This can be the case if
368  // the item was reconstructed from an XML file.
369  if( !_name.isEmpty() )
370  // We had a name, remove it
371  sGroupDict.remove( _name );
372 
373  TQString newName;
374  if ( name.isEmpty() || sGroupDict.find( name ) ) {
375  // create unique name
376  newName.sprintf( "%p", (void* )this );
377  while( sGroupDict.find( newName ) ) {
378  newName += "_0";
379  }
380  } else {
381  newName = name;
382  }
383  sGroupDict.insert( newName, this );
384  _name = newName;
385  //tqDebug("KDGanttViewTaskLinkGroup::generateAndInsertName: inserted '%s'",newName.latin1());
386 }
387 
static KDGanttViewTaskLinkGroup * find(const TQString &name)
void insert(KDGanttViewTaskLink *)
void setHighlightColor(const TQColor &color)
static KDGanttViewTaskLinkGroup * createFromDomElement(TQDomElement &)
void generateAndInsertName(const TQString &name)
bool remove(KDGanttViewTaskLink *)
void setColor(const TQColor &color)
void createNode(TQDomDocument &doc, TQDomElement &parentElement)