kdgantt

KDGanttViewTaskLink.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 "KDGanttViewTaskLink.h"
36 #include "KDGanttViewTaskLinkGroup.h"
37 #include "KDGanttViewSubwidgets.h"
38 #include "KDGanttXMLTools.h"
39 
40 
65 KDGanttViewTaskLink::KDGanttViewTaskLink( TQPtrList<KDGanttViewItem> from,
66  TQPtrList<KDGanttViewItem> to,
67  LinkType type )
68 {
69  fromList= from;
70  toList = to;
71  myGroup = 0;
72  setLinkType(type);
73  initTaskLink();
74 }
75 
76 
89  KDGanttViewItem* to,
90  LinkType type )
91 {
92  fromList.append(from);
93  toList.append(to);
94  myGroup = 0;
95  setLinkType(type);
96  initTaskLink();
97 
98 }
99 
112  TQPtrList<KDGanttViewItem> from,
113  TQPtrList<KDGanttViewItem> to,
114  LinkType type )
115 {
116  fromList = from;
117  toList = to;
118  myGroup = 0;
119  setLinkType(type);
120  initTaskLink();
121  setGroup(group);
122 }
123 
139  KDGanttViewItem* from,
140  KDGanttViewItem* to,
141  LinkType type )
142 {
143  fromList.append(from);
144  toList.append(to);
145  myGroup = 0;
146  setLinkType(type);
147  initTaskLink();
148  setGroup(group);
149 }
150 
151 
152 KDGanttViewTaskLink::~KDGanttViewTaskLink( )
153 {
154  setGroup(0);
155  myTimeTable->myTaskLinkList.remove(this);
156  delete horLineList;
157  delete verLineList;
158  delete horLineList2;
159  delete verLineList2;
160  delete horLineList3;
161  delete topList;
162  delete topLeftList;
163  delete topRightList;
164 }
165 
166 
167 void KDGanttViewTaskLink::initTaskLink()
168 {
169  horLineList = new TQPtrList<KDCanvasLine>;
170  verLineList = new TQPtrList<KDCanvasLine>;
171  horLineList2 = new TQPtrList<KDCanvasLine>;
172  verLineList2 = new TQPtrList<KDCanvasLine>;
173  horLineList3 = new TQPtrList<KDCanvasLine>;
174  topList = new TQPtrList<KDCanvasPolygon>;
175  topLeftList = new TQPtrList<KDCanvasPolygon>;
176  topRightList = new TQPtrList<KDCanvasPolygon>;
177  horLineList->setAutoDelete( true );
178  verLineList->setAutoDelete( true );
179  horLineList2->setAutoDelete( true );
180  verLineList2->setAutoDelete( true );
181  horLineList3->setAutoDelete( true );
182  topList->setAutoDelete( true );
183  topLeftList->setAutoDelete( true );
184  topRightList->setAutoDelete( true );
185  myTimeTable = fromList.getFirst()->myGanttView->myTimeTable;
186  KDCanvasLine* horLine,*verLine;
187  KDCanvasLine* horLine2,*verLine2;
188  KDCanvasLine* horLine3;
189  KDCanvasPolygon* top;
190  KDCanvasPolygon* topLeft;
191  KDCanvasPolygon* topRight;
192  unsigned int i, j;
193  for ( i = 0;i < fromList.count();++i) {
194  for ( j = 0;j < toList.count();++j) {
195  horLine = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
196  verLine = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
197  horLine2 = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
198  verLine2 = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
199  horLine3 = new KDCanvasLine(myTimeTable,this,Type_is_KDGanttTaskLink);
200  top = new KDCanvasPolygon(myTimeTable,this,Type_is_KDGanttTaskLink);
201  topLeft = new KDCanvasPolygon(myTimeTable,this,Type_is_KDGanttTaskLink);
202  topRight = new KDCanvasPolygon(myTimeTable,this,Type_is_KDGanttTaskLink);
203  TQPointArray arr = TQPointArray(3);
204  arr.setPoint(0,-4,-5);
205  arr.setPoint(1,4,-5);
206  arr.setPoint(2,0,0);
207  top->setPoints(arr);
208  arr.setPoint(0,5,-5); // need an extra y pixel, canvas bug?
209  arr.setPoint(1,5,5); // need an extra y pixel, canvas bug?
210  arr.setPoint(2,0,0);
211  topLeft->setPoints(arr);
212  arr.setPoint(0,-5,-4);
213  arr.setPoint(1,-5,4);
214  arr.setPoint(2,0,0);
215  topRight->setPoints(arr);
216  horLineList->append(horLine);
217  verLineList->append(verLine);
218  horLineList2->append(horLine2);
219  verLineList2->append(verLine2);
220  horLineList3->append(horLine3);
221  topList->append(top);
222  topLeftList->append(topLeft);
223  topRightList->append(topRight);
224  horLine->setZ(1);
225  verLine->setZ(1);
226  horLine2->setZ(1);
227  verLine2->setZ(1);
228  horLine3->setZ(1);
229  top->setZ(1);
230  topLeft->setZ(1);
231  topRight->setZ(1);
232  }
233  }
234 
235  setTooltipText( "Tasklink" );
236  setWhatsThisText( "Tasklink" );
237  myTimeTable->myTaskLinkList.append(this);
238  setHighlight( false);
239  setHighlightColor(TQt::red );
240  setColor(TQt::black);
241  setVisible(true);
242 }
243 
244 
254 {
255  showMe ( visible );
256  myTimeTable->updateMyContent();
257 }
258 void KDGanttViewTaskLink::showMe( bool visible )
259 {
260  if (linkType() != None) {
261  showMeType(visible);
262  return;
263  }
264  hide();
265 
266  isvisible = visible;
267  int wid = 1;
268  TQPen p;
269  TQBrush b;
270  p.setWidth(wid);
271  b.setStyle(TQt::SolidPattern);
272  if (ishighlighted) {
273  b.setColor(myColorHL);
274  p.setColor(myColorHL);
275 
276  } else {
277  b.setColor(myColor);
278  p.setColor(myColor);
279  }
280  TQPoint start, end;
281  TQPtrListIterator<KDCanvasLine> horIt(*horLineList);
282  TQPtrListIterator<KDCanvasLine> verIt(*verLineList);
283  TQPtrListIterator<KDCanvasPolygon> topIt(*topList);
284  TQPtrListIterator<KDGanttViewItem> fromIt(fromList);
285  TQPtrListIterator<KDGanttViewItem> toIt(toList);
286  for ( ; fromIt.current(); ++fromIt ) {
287  (*fromIt)->setTextOffset(TQPoint(0,0));
288  toIt.toFirst();
289  for ( ; toIt.current(); ++toIt ) {
290  (*toIt)->setTextOffset(TQPoint(0,0));
291  if (!isvisible || ! (*fromIt)->isVisibleInGanttView || !(*toIt)->isVisibleInGanttView || !myTimeTable->taskLinksVisible) {
292  (*horIt)->hide();
293  (*verIt)->hide();
294  (*topIt)->hide();
295  ++horIt;
296  ++verIt;
297  ++topIt;
298  } else {
299  (*horIt)->setPen(p);
300  (*verIt)->setPen(p);
301  (*topIt)->setBrush(b);
302  end = (*toIt)->getTaskLinkEndCoord();
303  start = (*fromIt)->getTaskLinkStartCoord(end);
304  (*horIt)->setPoints(start.x(),start.y(),end.x()+wid,start.y());
305  (*verIt)->setPoints(end.x()+wid/2,start.y(),end.x()+wid/2,end.y()-2);
306  (*topIt)->move(end.x()+wid/2,end.y());
307  (*horIt)->show();
308  (*verIt)->show();
309  (*topIt)->show();
310  ++horIt;
311  ++verIt;
312  ++topIt;
313 
314  }
315  }
316  }
317  while ( horIt.current() ) {
318  (*horIt)->hide();
319  (*verIt)->hide();
320  (*topIt)->hide();
321  ++horIt;
322  ++verIt;
323  ++topIt;
324  }
325 }
326 
327 void KDGanttViewTaskLink::showMeType( bool visible )
328 {
329  //tqDebug("KDGanttViewTaskLink::showMeType %d",linkType());
330  hide();
331  isvisible = visible;
332  int wid = 1;
333  TQPen p;
334  TQBrush b;
335  p.setWidth(wid);
336  b.setStyle(TQt::SolidPattern);
337  if (ishighlighted) {
338  b.setColor(myColorHL);
339  p.setColor(myColorHL);
340 
341  } else {
342  b.setColor(myColor);
343  p.setColor(myColor);
344  }
345  TQPoint start, end;
346  TQPtrListIterator<KDCanvasLine> horIt(*horLineList);
347  TQPtrListIterator<KDCanvasLine> verIt(*verLineList);
348  TQPtrListIterator<KDCanvasLine> horIt2(*horLineList2);
349  TQPtrListIterator<KDCanvasLine> verIt2(*verLineList2);
350  TQPtrListIterator<KDCanvasLine> horIt3(*horLineList3);
351  TQPtrListIterator<KDCanvasPolygon> topIt(*topList);
352  TQPtrListIterator<KDCanvasPolygon> topLeftIt(*topLeftList);
353  TQPtrListIterator<KDCanvasPolygon> topRightIt(*topRightList);
354  TQPtrListIterator<KDGanttViewItem> fromIt(fromList);
355  TQPtrListIterator<KDGanttViewItem> toIt(toList);
356  for ( ; fromIt.current(); ++fromIt ) {
357  (*fromIt)->setTextOffset(TQPoint(30,0));
358  (*fromIt)->moveTextCanvas();
359  toIt.toFirst();
360  for ( ; toIt.current(); ++toIt ) {
361  if (isvisible && (*fromIt)->isVisibleInGanttView &&
362  (*toIt)->isVisibleInGanttView && myTimeTable->taskLinksVisible) {
363  (*horIt)->setPen(p);
364  (*verIt)->setPen(p);
365  (*horIt2)->setPen(p);
366  (*verIt2)->setPen(p);
367  (*horIt3)->setPen(p);
368  (*topIt)->setBrush(b);
369  (*topLeftIt)->setBrush(b);
370  (*topRightIt)->setBrush(b);
371  (*toIt)->setTextOffset(TQPoint(30,0));
372  (*toIt)->moveTextCanvas();
373  switch (linkType()) {
374  case StartStart: {
375  start = (*fromIt)->middleLeft();
376  end = (*toIt)->middleLeft()-TQPoint(12,0);
377  bool down = start.y() < end.y();
378  (*horIt)->setPoints(start.x()-xOffset(*fromIt),start.y(),
379  start.x()-10, start.y());
380  (*verIt)->setPoints(
381  (*horIt)->endPoint().x(),
382  (*horIt)->endPoint().y(),
383  (*horIt)->endPoint().x(),
384  (down ? (*toIt)->itemPos()+1
385  : (*toIt)->itemPos()+(*toIt)->height()-1));
386  (*horIt2)->setPoints((*verIt)->endPoint().x(),
387  (*verIt)->endPoint().y(),
388  end.x()-12,
389  (*verIt)->endPoint().y());
390  (*verIt2)->setPoints((*horIt2)->endPoint().x(),
391  (*horIt2)->endPoint().y(),
392  (*horIt2)->endPoint().x(),
393  end.y());
394  (*horIt3)->setPoints((*verIt2)->endPoint().x(),
395  (*verIt2)->endPoint().y(),
396  end.x(),
397  end.y());
398  (*topRightIt)->move(end.x(),end.y());
399  (*topRightIt)->show();
400  break;
401  }
402  case FinishFinish: {
403  start = (*fromIt)->middleRight();
404  end = (*toIt)->middleRight()+TQPoint(12,0);
405  bool down = start.y() < end.y();
406  (*horIt)->setPoints(start.x()+xOffset(*fromIt),start.y(),
407  start.x()+10, start.y());
408  (*verIt)->setPoints(
409  (*horIt)->endPoint().x(),
410  (*horIt)->endPoint().y(),
411  (*horIt)->endPoint().x(),
412  (down ? (*toIt)->itemPos()+1
413  : (*toIt)->itemPos()+(*toIt)->height()-1));
414  (*horIt2)->setPoints((*verIt)->endPoint().x(),
415  (*verIt)->endPoint().y(),
416  end.x()+12,
417  (*verIt)->endPoint().y());
418  (*verIt2)->setPoints((*horIt2)->endPoint().x(),
419  (*horIt2)->endPoint().y(),
420  (*horIt2)->endPoint().x(),
421  end.y());
422  (*horIt3)->setPoints((*verIt2)->endPoint().x(),
423  (*verIt2)->endPoint().y(),
424  end.x(),
425  end.y());
426  (*topLeftIt)->move(end.x(),end.y());
427  (*topLeftIt)->show();
428  break;
429  }
430  case FinishStart: {
431  start = (*fromIt)->middleRight();
432  end = (*toIt)->middleLeft() - TQPoint(12,0);
433  bool down = start.y() < end.y();
434  (*horIt)->setPoints(start.x()+xOffset(*fromIt),start.y(),
435  start.x()+10,start.y());
436  (*verIt)->setPoints(
437  (*horIt)->endPoint().x(),
438  (*horIt)->endPoint().y(),
439  (*horIt)->endPoint().x(),
440  (down ? (*toIt)->itemPos()+1
441  : (*toIt)->itemPos()+(*toIt)->height()-1));
442  (*horIt2)->setPoints((*verIt)->endPoint().x(),
443  (*verIt)->endPoint().y(),
444  end.x()-12,
445  (*verIt)->endPoint().y());
446  (*verIt2)->setPoints((*horIt2)->endPoint().x(),
447  (*horIt2)->endPoint().y(),
448  (*horIt2)->endPoint().x(),
449  end.y());
450  (*horIt3)->setPoints((*verIt2)->endPoint().x(),
451  (*verIt2)->endPoint().y(),
452  end.x(),
453  end.y());
454  (*topRightIt)->move(end.x(),end.y());
455 
456  (*topRightIt)->show();
457 
458  break;
459  }
460  case StartFinish: {
461  start = (*fromIt)->middleRight();
462  end = (*toIt)->middleRight()+TQPoint(12,0);
463  bool down = start.y() < end.y();
464  (*horIt)->setPoints(start.x()+xOffset(*fromIt),start.y(),
465  start.x()+10, start.y());
466  (*verIt)->setPoints(
467  (*horIt)->endPoint().x(),
468  (*horIt)->endPoint().y(),
469  (*horIt)->endPoint().x(),
470  (down ? (*toIt)->itemPos()+1
471  : (*toIt)->itemPos()+(*toIt)->height()-1));
472  (*horIt2)->setPoints((*verIt)->endPoint().x(),
473  (*verIt)->endPoint().y(),
474  end.x()-12,
475  (*verIt)->endPoint().y());
476  (*verIt2)->setPoints((*horIt2)->endPoint().x(),
477  (*horIt2)->endPoint().y(),
478  (*horIt2)->endPoint().x(),
479  end.y());
480  (*horIt3)->setPoints((*verIt2)->endPoint().x(),
481  (*verIt2)->endPoint().y(),
482  end.x(),
483  end.y());
484  (*topRightIt)->move(end.x(),end.y());
485  (*topRightIt)->show();
486  break;
487  }
488  default:
489  tqWarning("KDGanttViewTaskLink: Unknown link type");
490  break;
491  }
492  (*horIt)->show();
493  (*verIt)->show();
494  (*horIt2)->show();
495  (*verIt2)->show();
496  (*horIt3)->show();
497  }
498  ++horIt;
499  ++verIt;
500  ++horIt2;
501  ++verIt2;
502  ++horIt3;
503  ++topIt;
504  ++topLeftIt;
505  ++topRightIt;
506  }
507  }
508 }
509 
517 {
518 
519  return isvisible;
520 }
521 
522 
531 {
532  return myGroup;
533 }
534 
535 
545 {
546 
547  myTimeTable->myGanttView->addTaskLinkGroup(group);
548  if(myGroup == group)
549  return;
550  if (myGroup != 0)
551  myGroup->removeItem(this);
552  myGroup = group;
553  if (myGroup != 0)
554  myGroup->insertItem(this);
555 }
556 
557 
565 void KDGanttViewTaskLink::setHighlight( bool highlight )
566 {
567  ishighlighted = highlight ;
568  // if ( isvisible) setVisible(true );
569  myTimeTable->updateMyContent();
570 }
571 
572 
581 {
582  return ishighlighted;
583 }
584 
585 
592 void KDGanttViewTaskLink::setColor( const TQColor& color )
593 {
594  myColor = color;
595  //if ( isvisible) setVisible(true );
596  myTimeTable->updateMyContent();
597 }
598 
599 
607 {
608  return myColor;
609 }
610 
611 
618 void KDGanttViewTaskLink::setHighlightColor( const TQColor& color )
619 {
620  myColorHL = color;
621  //if ( isvisible) setVisible(true );
622  myTimeTable->updateMyContent();
623 }
624 
625 
633 {
634  return myColorHL;
635 }
636 
637 
644 void KDGanttViewTaskLink::setTooltipText( const TQString& text )
645 {
646  myToolTipText = text;
647 }
648 
649 
657 {
658  return myToolTipText;
659 }
660 
661 
668 void KDGanttViewTaskLink::setWhatsThisText( const TQString& text )
669 {
670  myWhatsThisText = text;
671 
672 }
673 
674 
682 {
683  return myWhatsThisText;
684 }
685 
686 
693 TQPtrList<KDGanttViewItem> KDGanttViewTaskLink::from() const
694 {
695  return fromList;
696 }
697 
698 
705 {
706  bool itemremoved = false;
707  if (fromList.remove( item )) {
708  itemremoved = true;
709  }
710  if ( toList.remove( item )) {
711  itemremoved = true;
712  }
713  if ( itemremoved ) {
714  setVisible( isvisible );
715  }
716 }
717 
718 
725 TQPtrList<KDGanttViewItem> KDGanttViewTaskLink::to() const
726 {
727  return toList;
728 }
729 
730 
737 void KDGanttViewTaskLink::createNode( TQDomDocument& doc,
738  TQDomElement& parentElement )
739 {
740  TQDomElement taskLinkElement = doc.createElement( "TaskLink" );
741  parentElement.appendChild( taskLinkElement );
742 
743  TQDomElement fromItemsElement = doc.createElement( "FromItems" );
744  taskLinkElement.appendChild( fromItemsElement );
745  TQPtrList<KDGanttViewItem> fromList = from();
746  KDGanttViewItem* item;
747  for( item = fromList.first(); item;
748  item = fromList.next() )
749  KDGanttXML::createStringNode( doc, fromItemsElement, "Item", item->name() );
750 
751  TQDomElement toItemsElement = doc.createElement( "ToItems" );
752  taskLinkElement.appendChild( toItemsElement );
753  TQPtrList<KDGanttViewItem> toList = to();
754  for( item = toList.first(); item;
755  item = toList.next() )
756  KDGanttXML::createStringNode( doc, toItemsElement, "Item", item->name() );
757 
758  KDGanttXML::createBoolNode( doc, taskLinkElement, "Highlight", highlight() );
759  KDGanttXML::createColorNode( doc, taskLinkElement, "Color", color() );
760  KDGanttXML::createColorNode( doc, taskLinkElement, "HighlightColor",
761  highlightColor() );
762  KDGanttXML::createStringNode( doc, taskLinkElement, "TooltipText",
763  tooltipText() );
764  KDGanttXML::createStringNode( doc, taskLinkElement, "WhatsThisText",
765  whatsThisText() );
766  if( group() )
767  KDGanttXML::createStringNode( doc, taskLinkElement, "Group",
768  group()->name() );
769  KDGanttXML::createBoolNode( doc, taskLinkElement, "Visible",
770  isVisible() );
771  KDGanttXML::createStringNode( doc, taskLinkElement, "Linktype",
772  linkTypeToString( myLinkType ) );
773 }
774 
775 
784 {
785  TQDomNode node = element.firstChild();
786  TQStringList fromList, toList;
787  bool highlight = false, visible = false;
788  TQColor color, highlightColor;
789  TQString tooltipText, whatsThisText, group;
790  LinkType linktype=None;
791  while( !node.isNull() ) {
792  TQDomElement element = node.toElement();
793  if( !element.isNull() ) { // was really an element
794  TQString tagName = element.tagName();
795  if( tagName == "FromItems" ) {
796  TQDomNode node = element.firstChild();
797  while( !node.isNull() ) {
798  TQDomElement element = node.toElement();
799  if( !element.isNull() ) { // was really an element
800  TQString tagName = element.tagName();
801  if( tagName == "Item" ) {
802  TQString value;
803  if( KDGanttXML::readStringNode( element, value ) )
804  fromList << value;
805  } else {
806  tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
807  Q_ASSERT( false );
808  }
809  }
810  node = node.nextSibling();
811  }
812  } else if( tagName == "ToItems" ) {
813  TQDomNode node = element.firstChild();
814  while( !node.isNull() ) {
815  TQDomElement element = node.toElement();
816  if( !element.isNull() ) { // was really an element
817  TQString tagName = element.tagName();
818  if( tagName == "Item" ) {
819  TQString value;
820  if( KDGanttXML::readStringNode( element, value ) )
821  toList << value;
822  } else {
823  tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
824  Q_ASSERT( false );
825  }
826  }
827  node = node.nextSibling();
828  }
829  } else if( tagName == "Highlight" ) {
830  bool value;
831  if( KDGanttXML::readBoolNode( element, value ) )
832  highlight = value;
833  } else if( tagName == "Visible" ) {
834  bool value;
835  if( KDGanttXML::readBoolNode( element, value ) )
836  visible = value;
837  } else if( tagName == "Color" ) {
838  TQColor value;
839  if( KDGanttXML::readColorNode( element, value ) )
840  color = value;
841  } else if( tagName == "HighlightColor" ) {
842  TQColor value;
843  if( KDGanttXML::readColorNode( element, value ) )
844  highlightColor = value;
845  } else if( tagName == "TooltipText" ) {
846  TQString value;
847  if( KDGanttXML::readStringNode( element, value ) )
848  tooltipText = value;
849  } else if( tagName == "WhatsThisText" ) {
850  TQString value;
851  if( KDGanttXML::readStringNode( element, value ) )
852  whatsThisText = value;
853  } else if( tagName == "Group" ) {
854  TQString value;
855  if( KDGanttXML::readStringNode( element, value ) )
856  group = value;
857  } else if( tagName == "Linktype" ) {
858  TQString value;
859  if( KDGanttXML::readStringNode( element, value ) )
860  linktype = stringToLinkType( value );
861  } else {
862  tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
863  Q_ASSERT( false );
864  }
865  }
866  node = node.nextSibling();
867  }
868 
869  TQPtrList<KDGanttViewItem> fromItemList;
870  TQPtrList<KDGanttViewItem> toItemList;
871  for( TQStringList::const_iterator fromIt = fromList.begin();
872  fromIt != fromList.end(); ++fromIt ) {
873  KDGanttViewItem* item = KDGanttViewItem::find( *fromIt );
874  if( item )
875  fromItemList.append( item );
876  }
877  for( TQStringList::const_iterator toIt = toList.begin();
878  toIt != toList.end(); ++toIt ) {
879  KDGanttViewItem* item = KDGanttViewItem::find( *toIt );
880  if( item )
881  toItemList.append( item );
882  }
883  // safeguard aginst incorrect names
884  if (fromItemList.isEmpty()) {
885  tqDebug("Cannot create link: fromItemList is empty");
886  return 0;
887  }
888  if (toItemList.isEmpty()) {
889  tqDebug("Cannot create link: toItemList is empty");
890  return 0;
891  }
892  KDGanttViewTaskLink* tl = new KDGanttViewTaskLink( fromItemList,
893  toItemList );
894  tl->setLinkType( linktype );
895  tl->setVisible( visible );
896  tl->setHighlight( highlight );
897  tl->setColor( color );
902  if( gr )
903  tl->setGroup( gr );
904 
905  return tl;
906 }
907 
908 int KDGanttViewTaskLink::linkType()
909 {
910  return myLinkType;
911 }
912 
913 void KDGanttViewTaskLink::setLinkType(int type)
914 {
915  myLinkType = static_cast<LinkType>(type);
916 }
917 
918 int KDGanttViewTaskLink::xOffset(KDGanttViewItem *item)
919 {
920  switch (item->type()) {
921  case KDGanttViewItem::Task:
922  return 0;
923  break;
924  case KDGanttViewItem::Event:
925  return 4;
926  break;
927  case KDGanttViewItem::Summary:
928  return 4;
929  break;
930  default:
931  break;
932  }
933  return 0;
934 }
935 
936 void KDGanttViewTaskLink::hide()
937 {
938  TQPtrListIterator<KDCanvasLine> horIt(*horLineList);
939  TQPtrListIterator<KDCanvasLine> verIt(*verLineList);
940  TQPtrListIterator<KDCanvasLine> horIt2(*horLineList2);
941  TQPtrListIterator<KDCanvasLine> verIt2(*verLineList2);
942  TQPtrListIterator<KDCanvasLine> horIt3(*horLineList3);
943  TQPtrListIterator<KDCanvasPolygon> topIt(*topList);
944  TQPtrListIterator<KDCanvasPolygon> topLeftIt(*topLeftList);
945  TQPtrListIterator<KDCanvasPolygon> topRightIt(*topRightList);
946  TQPtrListIterator<KDGanttViewItem> fromIt(fromList);
947  TQPtrListIterator<KDGanttViewItem> toIt(toList);
948  for ( ; fromIt.current(); ++fromIt ) {
949  toIt.toFirst();
950  for ( ; toIt.current(); ++toIt ) {
951  (*horIt)->hide();
952  (*verIt)->hide();
953  (*horIt2)->hide();
954  (*verIt2)->hide();
955  (*horIt3)->hide();
956  (*topIt)->hide();
957  (*topLeftIt)->hide();
958  (*topRightIt)->hide();
959  ++horIt;
960  ++verIt;
961  ++horIt2;
962  ++verIt2;
963  ++horIt3;
964  ++topIt;
965  ++topLeftIt;
966  ++topRightIt;
967  }
968  }
969 }
970 
971 TQString KDGanttViewTaskLink::linkTypeToString( LinkType type )
972 {
973  switch( type ) {
974  case None:
975  return "None";
976  break;
977  case FinishStart:
978  return "FinishStart";
979  break;
980  case FinishFinish:
981  return "FinishFinish";
982  break;
983  case StartStart:
984  return "StartStart";
985  break;
986  case StartFinish:
987  return "StartFinish";
988  break;
989  default:
990  break;
991  }
992  return "";
993 }
994 
995 KDGanttViewTaskLink::LinkType KDGanttViewTaskLink::stringToLinkType( const TQString type )
996 {
997  if (type == "FinishStart")
998  return FinishStart;
999  if (type == "FinishFinish")
1000  return FinishFinish;
1001  if (type == "StartStart")
1002  return StartStart;
1003  if (type == "StartFinish")
1004  return StartFinish;
1005 
1006  return None;
1007 }
static KDGanttViewItem * find(const TQString &name)
TQString name() const
static KDGanttViewTaskLinkGroup * find(const TQString &name)