kdgantt1
KDGanttViewTaskLinkGroup.cpp
Go to the documentation of this file.00001
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 #include "KDGanttView.h"
00034
00035 #include "KDGanttViewTaskLinkGroup.h"
00036 #include "KDGanttXMLTools.h"
00037
00038 QDict<KDGanttViewTaskLinkGroup> KDGanttViewTaskLinkGroup::sGroupDict;
00039
00050 KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup()
00051 {
00052
00053 }
00054
00060 KDGanttViewTaskLinkGroup::~KDGanttViewTaskLinkGroup()
00061 {
00062 if (!myTaskLinkList.isEmpty()) {
00063 KDGanttViewItem* item = myTaskLinkList.first()->from().first();
00064 KDGanttView * gv = 0;
00065 if ( item )
00066 gv = item->myGanttView;
00067 KDGanttViewTaskLink * tl = myTaskLinkList.first();
00068 while ( tl ) {
00069 tl->resetGroup();
00070 tl = myTaskLinkList.next();
00071 }
00072 if ( gv )
00073 gv->removeTaskLinkGroup(this);
00074 }
00075 }
00076
00077
00078
00086 KDGanttViewTaskLinkGroup::KDGanttViewTaskLinkGroup( const QString& name )
00087 {
00088 sGroupDict.insert( name, this );
00089 _name = name;
00090 }
00091
00092
00102 void KDGanttViewTaskLinkGroup::insert (KDGanttViewTaskLink* link)
00103 {
00104 link->setGroup(this);
00105 }
00106
00107
00116 bool KDGanttViewTaskLinkGroup::remove (KDGanttViewTaskLink* link)
00117 {
00118 KDGanttViewTaskLinkGroup* g = link->group();
00119 if ((g == this))
00120 link->setGroup(0);
00121 return (g == this);
00122 }
00123
00124
00132 void KDGanttViewTaskLinkGroup::setVisible( bool show )
00133 {
00134 isvisible = show;
00135 QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
00136 for ( ; it.current(); ++it ) {
00137 it.current()->setVisible(show);
00138 }
00139 }
00140
00141
00148 bool KDGanttViewTaskLinkGroup::visible() const
00149 {
00150 return isvisible;
00151 }
00152
00153
00162 void KDGanttViewTaskLinkGroup::setHighlight( bool highlight )
00163 {
00164 ishighlighted= highlight;
00165 QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
00166 for ( ; it.current(); ++it )
00167 it.current()->setHighlight(highlight );
00168
00169 }
00170
00171
00181 bool KDGanttViewTaskLinkGroup::highlight() const
00182 {
00183 return ishighlighted;
00184 }
00185
00186
00193 void KDGanttViewTaskLinkGroup::setColor( const QColor& color )
00194 {
00195 myColor = color;
00196 QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
00197 for ( ; it.current(); ++it )
00198 it.current()->setColor(color);
00199 }
00200
00201
00212 QColor KDGanttViewTaskLinkGroup::color() const
00213 {
00214 return myColor;
00215 }
00216
00217
00224 void KDGanttViewTaskLinkGroup::setHighlightColor( const QColor& color )
00225 {
00226
00227 myColorHL = color;
00228 QPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
00229 for ( ; it.current(); ++it )
00230 it.current()->setHighlightColor(color);
00231 }
00232
00233
00244 QColor KDGanttViewTaskLinkGroup::highlightColor() const
00245 {
00246 return myColorHL;
00247 }
00248
00249
00257 void KDGanttViewTaskLinkGroup::insertItem (KDGanttViewTaskLink* link)
00258 {
00259 myTaskLinkList.append (link);
00260 }
00261
00262
00269 void KDGanttViewTaskLinkGroup::removeItem (KDGanttViewTaskLink* link)
00270 {
00271 myTaskLinkList.remove(link);
00272 }
00273
00274
00282 KDGanttViewTaskLinkGroup* KDGanttViewTaskLinkGroup::find( const QString& name )
00283 {
00284 return sGroupDict.find( name );
00285 }
00286
00287
00294 void KDGanttViewTaskLinkGroup::createNode( QDomDocument& doc,
00295 QDomElement& parentElement )
00296 {
00297 QDomElement taskLinkGroupElement = doc.createElement( "TaskLink" );
00298 parentElement.appendChild( taskLinkGroupElement );
00299
00300 KDGanttXML::createBoolNode( doc, taskLinkGroupElement, "Highlight",
00301 highlight() );
00302 KDGanttXML::createColorNode( doc, taskLinkGroupElement, "Color", color() );
00303 KDGanttXML::createColorNode( doc, taskLinkGroupElement, "HighlightColor",
00304 highlightColor() );
00305 KDGanttXML::createBoolNode( doc, taskLinkGroupElement, "Visible",
00306 visible() );
00307 KDGanttXML::createStringNode( doc, taskLinkGroupElement, "Name", _name );
00308 }
00309
00310
00318 KDGanttViewTaskLinkGroup* KDGanttViewTaskLinkGroup::createFromDomElement( QDomElement& element )
00319 {
00320 QDomNode node = element.firstChild();
00321 bool highlight = false, visible = false;
00322 QColor color, highlightColor;
00323 QString name;
00324 while( !node.isNull() ) {
00325 QDomElement element = node.toElement();
00326 if( !element.isNull() ) {
00327 QString tagName = element.tagName();
00328 if( tagName == "Highlight" ) {
00329 bool value;
00330 if( KDGanttXML::readBoolNode( element, value ) )
00331 highlight = value;
00332 } else if( tagName == "Visible" ) {
00333 bool value;
00334 if( KDGanttXML::readBoolNode( element, value ) )
00335 visible = value;
00336 } else if( tagName == "Color" ) {
00337 QColor value;
00338 if( KDGanttXML::readColorNode( element, value ) )
00339 color = value;
00340 } else if( tagName == "HighlightColor" ) {
00341 QColor value;
00342 if( KDGanttXML::readColorNode( element, value ) )
00343 highlightColor = value;
00344 } else if( tagName == "Name" ) {
00345 QString value;
00346 if( KDGanttXML::readStringNode( element, value ) )
00347 name = value;
00348 } else {
00349 qDebug( "Unrecognized tag name: %s", qPrintable(tagName) );
00350 Q_ASSERT( false );
00351 }
00352 }
00353 node = node.nextSibling();
00354 }
00355
00356 KDGanttViewTaskLinkGroup* tlg;
00357 if( !name.isEmpty() )
00358 tlg = new KDGanttViewTaskLinkGroup( name );
00359 else
00360 tlg = new KDGanttViewTaskLinkGroup();
00361
00362 tlg->setHighlight( highlight );
00363 tlg->setVisible( visible );
00364 tlg->setHighlightColor( highlightColor );
00365 tlg->setColor( color );
00366
00367 return tlg;
00368 }