kdgantt
KDGanttViewTaskLinkGroup.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "KDGanttViewTaskLinkGroup.h"
00036 #include "KDGanttXMLTools.h"
00037 #include "KDGanttView.h"
00038
00039 QDict<KDGanttViewTaskLinkGroup> KDGanttViewTaskLinkGroup::sGroupDict;
00040
00051 KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup()
00052 {
00053 generateAndInsertName(QString());
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 QString& 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 QPtrListIterator<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 QPtrListIterator<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 QColor& color )
00183 {
00184 myColor = color;
00185 QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
00186 for ( ; it.current(); ++it )
00187 it.current()->setColor(color);
00188 }
00189
00190
00201 QColor KDGanttViewTaskLinkGroup::color() const
00202 {
00203 return myColor;
00204 }
00205
00206
00213 void KDGanttViewTaskLinkGroup::setHighlightColor( const QColor& color )
00214 {
00215
00216 myColorHL = color;
00217 QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
00218 for ( ; it.current(); ++it )
00219 it.current()->setHighlightColor(color);
00220 }
00221
00222
00233 QColor 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 QString& name )
00272 {
00273 if (name.isEmpty())
00274 return 0;
00275 return sGroupDict.find( name );
00276 }
00277
00278
00285 void KDGanttViewTaskLinkGroup::createNode( QDomDocument& doc,
00286 QDomElement& parentElement )
00287 {
00288 QDomElement 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( QDomElement& element )
00310 {
00311 QDomNode node = element.firstChild();
00312 bool highlight = false, visible = false;
00313 QColor color, highlightColor;
00314 QString name;
00315 while( !node.isNull() ) {
00316 QDomElement element = node.toElement();
00317 if( !element.isNull() ) {
00318 QString 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 QColor value;
00329 if( KDGanttXML::readColorNode( element, value ) )
00330 color = value;
00331 } else if( tagName == "HighlightColor" ) {
00332 QColor value;
00333 if( KDGanttXML::readColorNode( element, value ) )
00334 highlightColor = value;
00335 } else if( tagName == "Name" ) {
00336 QString value;
00337 if( KDGanttXML::readStringNode( element, value ) )
00338 name = value;
00339 } else {
00340 qDebug( "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 QString& name )
00366 {
00367
00368
00369 if( !_name.isEmpty() )
00370
00371 sGroupDict.remove( _name );
00372
00373 QString newName;
00374 if ( name.isEmpty() || sGroupDict.find( name ) ) {
00375
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
00386 }
00387
|