KDGanttViewTaskLinkGroup.cpp
00001 /* -*- Mode: C++ -*- 00002 $Id$ 00003 KDGantt - a multi-platform charting engine 00004 */ 00005 /**************************************************************************** 00006 ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved. 00007 ** 00008 ** This file is part of the KDGantt library. 00009 ** 00010 ** This file may be distributed and/or modified under the terms of the 00011 ** GNU General Public License version 2 as published by the Free Software 00012 ** Foundation and appearing in the file LICENSE.GPL included in the 00013 ** packaging of this file. 00014 ** 00015 ** Licensees holding valid commercial KDGantt licenses may use this file in 00016 ** accordance with the KDGantt Commercial License Agreement provided with 00017 ** the Software. 00018 ** 00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00021 ** 00022 ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for 00023 ** information about KDGantt Commercial License Agreements. 00024 ** 00025 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this 00026 ** licensing are not clear to you. 00027 ** 00028 ** As a special exception, permission is given to link this program 00029 ** with any edition of TQt, and distribute the resulting executable, 00030 ** without including the source code for TQt in the source distribution. 00031 ** 00032 **********************************************************************/ 00033 00034 00035 #include "KDGanttViewTaskLinkGroup.h" 00036 #include "KDGanttXMLTools.h" 00037 #include "KDGanttView.h" 00038 00039 TQDict<KDGanttViewTaskLinkGroup> KDGanttViewTaskLinkGroup::sGroupDict; 00040 00051 KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup() 00052 { 00053 generateAndInsertName(TQString()); 00054 } 00055 00061 KDGanttViewTaskLinkGroup::~KDGanttViewTaskLinkGroup() 00062 { 00063 if (!myTaskLinkList.isEmpty()) { 00064 myTaskLinkList.first()->from().first()->myGanttView->removeTaskLinkGroup(this); 00065 } 00066 } 00067 00068 00069 00077 KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup( const TQString& name ) 00078 { 00079 generateAndInsertName( name ); 00080 } 00081 00091 void KDGanttViewTaskLinkGroup::insert (KDGanttViewTaskLink* link) 00092 { 00093 link->setGroup(this); 00094 } 00095 00096 00105 bool KDGanttViewTaskLinkGroup::remove (KDGanttViewTaskLink* link) 00106 { 00107 KDGanttViewTaskLinkGroup* g = link->group(); 00108 if ((g == this)) 00109 link->setGroup(0); 00110 return (g == this); 00111 } 00112 00113 00121 void KDGanttViewTaskLinkGroup::setVisible( bool show ) 00122 { 00123 isvisible = show; 00124 TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList); 00125 for ( ; it.current(); ++it ) { 00126 it.current()->setVisible(show); 00127 } 00128 } 00129 00130 00137 bool KDGanttViewTaskLinkGroup::visible() const 00138 { 00139 return isvisible; 00140 } 00141 00142 00151 void KDGanttViewTaskLinkGroup::setHighlight( bool highlight ) 00152 { 00153 ishighlighted= highlight; 00154 TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList); 00155 for ( ; it.current(); ++it ) 00156 it.current()->setHighlight(highlight ); 00157 00158 } 00159 00160 00170 bool KDGanttViewTaskLinkGroup::highlight() const 00171 { 00172 return ishighlighted; 00173 } 00174 00175 00182 void KDGanttViewTaskLinkGroup::setColor( const TQColor& color ) 00183 { 00184 myColor = color; 00185 TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList); 00186 for ( ; it.current(); ++it ) 00187 it.current()->setColor(color); 00188 } 00189 00190 00201 TQColor KDGanttViewTaskLinkGroup::color() const 00202 { 00203 return myColor; 00204 } 00205 00206 00213 void KDGanttViewTaskLinkGroup::setHighlightColor( const TQColor& color ) 00214 { 00215 00216 myColorHL = color; 00217 TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList); 00218 for ( ; it.current(); ++it ) 00219 it.current()->setHighlightColor(color); 00220 } 00221 00222 00233 TQColor KDGanttViewTaskLinkGroup::highlightColor() const 00234 { 00235 return myColorHL; 00236 } 00237 00238 00246 void KDGanttViewTaskLinkGroup::insertItem (KDGanttViewTaskLink* link) 00247 { 00248 myTaskLinkList.append (link); 00249 } 00250 00251 00258 void KDGanttViewTaskLinkGroup::removeItem (KDGanttViewTaskLink* link) 00259 { 00260 myTaskLinkList.remove(link); 00261 } 00262 00263 00271 KDGanttViewTaskLinkGroup* KDGanttViewTaskLinkGroup::find( const TQString& name ) 00272 { 00273 if (name.isEmpty()) // avoid error msg from TQDict 00274 return 0; 00275 return sGroupDict.find( name ); 00276 } 00277 00278 00285 void KDGanttViewTaskLinkGroup::createNode( TQDomDocument& doc, 00286 TQDomElement& parentElement ) 00287 { 00288 TQDomElement taskLinkGroupElement = doc.createElement( "TaskLink" ); 00289 parentElement.appendChild( taskLinkGroupElement ); 00290 00291 KDGanttXML::createBoolNode( doc, taskLinkGroupElement, "Highlight", 00292 highlight() ); 00293 KDGanttXML::createColorNode( doc, taskLinkGroupElement, "Color", color() ); 00294 KDGanttXML::createColorNode( doc, taskLinkGroupElement, "HighlightColor", 00295 highlightColor() ); 00296 KDGanttXML::createBoolNode( doc, taskLinkGroupElement, "Visible", 00297 visible() ); 00298 KDGanttXML::createStringNode( doc, taskLinkGroupElement, "Name", _name ); 00299 } 00300 00301 00309 KDGanttViewTaskLinkGroup* KDGanttViewTaskLinkGroup::createFromDomElement( TQDomElement& element ) 00310 { 00311 TQDomNode node = element.firstChild(); 00312 bool highlight = false, visible = false; 00313 TQColor color, highlightColor; 00314 TQString name; 00315 while( !node.isNull() ) { 00316 TQDomElement element = node.toElement(); 00317 if( !element.isNull() ) { // was really an element 00318 TQString tagName = element.tagName(); 00319 if( tagName == "Highlight" ) { 00320 bool value; 00321 if( KDGanttXML::readBoolNode( element, value ) ) 00322 highlight = value; 00323 } else if( tagName == "Visible" ) { 00324 bool value; 00325 if( KDGanttXML::readBoolNode( element, value ) ) 00326 visible = value; 00327 } else if( tagName == "Color" ) { 00328 TQColor value; 00329 if( KDGanttXML::readColorNode( element, value ) ) 00330 color = value; 00331 } else if( tagName == "HighlightColor" ) { 00332 TQColor value; 00333 if( KDGanttXML::readColorNode( element, value ) ) 00334 highlightColor = value; 00335 } else if( tagName == "Name" ) { 00336 TQString value; 00337 if( KDGanttXML::readStringNode( element, value ) ) 00338 name = value; 00339 } else { 00340 tqDebug( "Unrecognized tag name: %s", tagName.latin1() ); 00341 Q_ASSERT( false ); 00342 } 00343 } 00344 node = node.nextSibling(); 00345 } 00346 00347 KDGanttViewTaskLinkGroup* tlg; 00348 if( !name.isEmpty() ) 00349 tlg = new KDGanttViewTaskLinkGroup( name ); 00350 else 00351 tlg = new KDGanttViewTaskLinkGroup(); 00352 00353 tlg->setHighlight( highlight ); 00354 tlg->setVisible( visible ); 00355 tlg->setHighlightColor( highlightColor ); 00356 tlg->setColor( color ); 00357 00358 return tlg; 00359 } 00360 00365 void KDGanttViewTaskLinkGroup::generateAndInsertName( const TQString& name ) 00366 { 00367 // First check if we already had a name. This can be the case if 00368 // the item was reconstructed from an XML file. 00369 if( !_name.isEmpty() ) 00370 // We had a name, remove it 00371 sGroupDict.remove( _name ); 00372 00373 TQString newName; 00374 if ( name.isEmpty() || sGroupDict.find( name ) ) { 00375 // create unique name 00376 newName.sprintf( "%p", (void* )this ); 00377 while( sGroupDict.find( newName ) ) { 00378 newName += "_0"; 00379 } 00380 } else { 00381 newName = name; 00382 } 00383 sGroupDict.insert( newName, this ); 00384 _name = newName; 00385 //tqDebug("KDGanttViewTaskLinkGroup::generateAndInsertName: inserted '%s'",newName.latin1()); 00386 } 00387