00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kpttask.h"
00021 #include "kptcanvasitem.h"
00022 #include "kptrelation.h"
00023 #include "kptpertcanvas.h"
00024 #include "kptganttview.h"
00025
00026 #include <klocale.h>
00027 #include <qpainter.h>
00028 #include <qpointarray.h>
00029 #include <qptrlist.h>
00030 #include <qpoint.h>
00031
00032 #include <kdebug.h>
00033
00034 namespace KPlato
00035 {
00036
00037 PertNodeItem::PertNodeItem( PertCanvas *view, Node &node, int row, int col )
00038 : QCanvasPolygon(view->canvas()),
00039 m_node(node),
00040 m_row(row),
00041 m_col(col)
00042 {
00043 m_x = m_y = 0;
00044 m_wgap = view->verticalGap();
00045 m_hgap = view->horizontalGap();
00046 m_width = view->itemSize().width();
00047 m_height = view->itemSize().height();
00048
00049 m_name = new QCanvasText(node.name(), view->canvas());
00050 m_childRelations.setAutoDelete(true);
00051 }
00052
00053 PertNodeItem::~PertNodeItem()
00054 {
00055 QCanvasItemList list = canvas()->allItems();
00056 QCanvasItemList::Iterator it = list.begin();
00057 for (; it != list.end(); ++it)
00058 {
00059 if ( *it == m_name )
00060 m_name->hide();
00061 if ( *it == m_leader )
00062 m_leader->hide();
00063 }
00064 hide();
00065 }
00066
00067 int PertNodeItem::rtti() const { return RTTI; }
00068 int PertNodeItem::RTTI = 2000;
00069
00070 void PertNodeItem::setVisible(bool yes)
00071 {
00072
00073 QCanvasPolygon::setVisible(yes);
00074 QCanvasItemList list = canvas()->allItems();
00075 QCanvasItemList::Iterator it = list.begin();
00076 for (; it != list.end(); ++it)
00077 {
00078 if ( *it == m_name )
00079 m_name->setVisible(yes);
00080 if ( *it == m_leader )
00081 m_leader->setVisible(yes);
00082 }
00083 }
00084
00085 void PertNodeItem::move(PertCanvas *view, int row, int col)
00086 {
00087
00088 m_row = row; m_col = col;
00089 view->mapNode(this);
00090
00091
00092 QPtrListIterator<PertNodeRelation> it(m_childRelations);
00093 for (; it.current(); ++it)
00094 {
00095 view->mapChildNode(this, it.current()->childItem, it.current()->relation->type());
00096 }
00097
00098
00099 m_x = x(col); m_y = y(row);
00100 m_left = QPoint(m_x, m_y + m_height/2);
00101 m_right = QPoint(m_x + m_width, m_y + m_height/2);
00102 QCanvasPolygon::move(m_x, m_y);
00103 if (m_name)
00104 m_name->move(m_x+5, m_y+2);
00105
00106 setVisible(true);
00107
00108 }
00109
00110 void PertNodeItem::drawShape(QPainter &p)
00111 {
00112
00113 if (isSelected())
00114 p.setPen(QPen(Qt::red, 2));
00115 QPointArray a = poly;
00116 int size = a.size()-1;
00117 for(int i = 0; i < size; ++i)
00118 {
00119
00120 p.drawLine(a[i], a[i+1]);
00121 }
00122
00123 }
00124
00125 QPoint PertNodeItem::exitPoint(Relation::Type type) const
00126 {
00127 QPoint ret;
00128 switch(type)
00129 {
00130 case Relation::FinishStart:
00131 case Relation::FinishFinish:
00132 ret = m_right + QPoint(pen().width(), 0);
00133 break;
00134 case Relation::StartStart:
00135 ret = m_left + QPoint(0, 4);
00136 break;
00137 }
00138 return ret;
00139 }
00140
00141 QPoint PertNodeItem::entryPoint(Relation::Type type) const
00142 {
00143 QPoint ret;
00144 switch(type)
00145 {
00146 case Relation::FinishStart:
00147 ret = m_left - QPoint(pen().width(), 0);
00148 break;
00149 case Relation::FinishFinish:
00150 ret = m_right - QPoint(pen().width(), 4);
00151 break;
00152 case Relation::StartStart:
00153 ret = m_left - QPoint(pen().width(), 0);
00154 break;
00155 }
00156 return ret;
00157 }
00158
00159 #ifndef NDEBUG
00160 void PertNodeItem::printDebug( int )
00161 {
00162 }
00163 #endif
00164
00166
00167 PertProjectItem::PertProjectItem(PertCanvas *view, Node &node, int row, int col)
00168 : PertNodeItem(view, node, row, col)
00169 {
00170
00171
00172 QPointArray a;
00173 a.putPoints(0, 5,
00174 m_x+6, m_y, m_x+m_width, m_y, m_x+m_width-6, m_y+m_height, m_x, m_y+m_height, m_x+6, m_y);
00175 setPoints(a);
00176
00177 setPen(QPen(Qt::cyan, 2));
00178 }
00179
00180 PertProjectItem::~PertProjectItem()
00181 {
00182 }
00183
00184 int PertProjectItem::rtti() const { return RTTI; }
00185 int PertProjectItem::RTTI = 2001;
00186
00187 #ifndef NDEBUG
00188 void PertProjectItem::printDebug( int )
00189 {
00190 }
00191 #endif
00192
00193
00195
00196 PertTaskItem::PertTaskItem(PertCanvas *view, Node &node, int row, int col)
00197 : PertNodeItem(view, node, row, col)
00198 {
00199
00200 QPointArray a;
00201 if (node.type() == Node::Type_Summarytask)
00202 {
00203 a.putPoints(0, 5, m_x+6, m_y, m_x+m_width, m_y, m_x+m_width-6, m_y+m_height, m_x, m_y+m_height, m_x+6, m_y);
00204 setPen(QPen(Qt::cyan, 2));
00205 }
00206 else
00207 {
00208 a.putPoints(0, 5, m_x, m_y, m_x+m_width, m_y, m_x+m_width, m_y+m_height, m_x, m_y+m_height, m_x, m_y);
00209 setPen(QPen(Qt::green, 2));
00210 }
00211 setPoints(a);
00212
00213 }
00214
00215 PertTaskItem::~PertTaskItem()
00216 {
00217 }
00218
00219 int PertTaskItem::rtti() const { return RTTI; }
00220 int PertTaskItem::RTTI = 2002;
00221
00222
00223 #ifndef NDEBUG
00224 void PertTaskItem::printDebug( int )
00225 {
00226 }
00227 #endif
00228
00229
00231
00232 PertMilestoneItem::PertMilestoneItem(PertCanvas *view, Node &node, int row, int col)
00233 : PertNodeItem(view, node, row, col)
00234 {
00235
00236
00237 QPointArray a;
00238 a.putPoints(0, 7,
00239 m_x, m_y+m_height/2,
00240 m_x+6, m_y,
00241 m_x+m_width-6, m_y,
00242 m_x+m_width, m_y+m_height/2,
00243 m_x+m_width-6, m_y+m_height,
00244 m_x+6, m_y+m_height,
00245 m_x, m_y+m_height/2);
00246
00247 setPoints(a);
00248
00249 setPen(QPen(Qt::blue, 2));
00250 }
00251
00252 PertMilestoneItem::~PertMilestoneItem()
00253 {
00254 }
00255
00256 int PertMilestoneItem::rtti() const { return RTTI; }
00257 int PertMilestoneItem::RTTI = 2003;
00258
00259 #ifndef NDEBUG
00260 void PertMilestoneItem::printDebug( int )
00261 {
00262 }
00263 #endif
00264
00265
00267
00268 PertRelationItem::PertRelationItem( PertCanvas *view, PertNodeItem *parent, PertNodeItem *child, Relation *rel)
00269 : QCanvasPolygon(view->canvas()),
00270 m_view(view),
00271 m_rel(rel),
00272 m_parentItem(parent),
00273 m_childItem(child)
00274 {
00275
00276 draw();
00277 setVisible(true);
00278 }
00279
00280 PertRelationItem::~PertRelationItem()
00281 {
00282 hide();
00283 }
00284
00285 int PertRelationItem::rtti() const { return RTTI; }
00286 int PertRelationItem::RTTI = 2020;
00287
00288 void PertRelationItem::draw()
00289 {
00290
00291
00292
00293
00294
00295
00296
00297 wgap = m_view->verticalGap();
00298 hgap = m_view->horizontalGap();
00299
00300
00301 parentTop = (int)(m_parentItem->y());
00302 parentBottom = parentTop + (int)(m_parentItem->height());
00303 childTop = (int)(m_childItem->y());
00304
00305 childRow = m_childItem->row();
00306 childCol = m_childItem->column();
00307 parentRow = m_parentItem->row();
00308 parentCol = m_parentItem->column();
00309
00310
00311 switch (type())
00312 {
00313 case Relation::FinishStart:
00314 setFinishStartPoints();
00315 break;
00316 case Relation::FinishFinish:
00317 setFinishFinishPoints();
00318 break;
00319 case Relation::StartStart:
00320 setStartStartPoints();
00321 break;
00322 }
00323 QPointArray a = poly;
00324 left = right = a[0].x();
00325 top = bottom = a[0].y();
00326 for (uint i = 0; i < a.size(); i++)
00327 {
00328 left = QMIN(a[i].x(), left);
00329 top = QMIN(a[i].y(), top);
00330 right = QMAX(a[i].x(), right);
00331 bottom = QMAX(a[i].y(), bottom);
00332 }
00333 top -= 3;
00334 bottom += 3;
00335
00336 setPen(Qt::black);
00337 setZ(45);
00338
00339
00340
00341
00342
00343
00344
00345
00346 }
00347
00348 void PertRelationItem::setFinishStartPoints()
00349 {
00350 QPoint parentPoint = m_parentItem->exitPoint(Relation::FinishStart);
00351 QPoint childPoint = m_childItem->entryPoint(Relation::FinishStart);
00352
00353 QPointArray a;
00354 a.putPoints(0, 1, parentPoint.x(), parentPoint.y());
00355
00356 if ( parentRow == childRow )
00357 {
00358 if (parentCol == childCol - 1 || rowFree(parentRow, parentCol+1, childCol-1))
00359 {
00360 a.putPoints(1, 1, childPoint.x(), childPoint.y());
00361 }
00362 else
00363 {
00364 a.putPoints(1, 9,
00365 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
00366 parentPoint.x()+(wgap/2), parentPoint.y()+3,
00367 parentPoint.x()+(wgap/2), parentBottom+(hgap/2)-3,
00368 parentPoint.x()+(wgap/2)+3, parentBottom+(hgap/2),
00369 childPoint.x()-(wgap/2)-3, parentBottom+(hgap/2),
00370 childPoint.x()-(wgap/2), parentBottom+(hgap/2)-3,
00371 childPoint.x()-(wgap/2), childPoint.y()+3,
00372 childPoint.x()-(wgap/2)+3, childPoint.y(),
00373 childPoint.x(), childPoint.y());
00374 }
00375 }
00376 else if ( parentRow > childRow )
00377 {
00378 if (parentCol == childCol - 1)
00379 {
00380 a.putPoints(1, 5,
00381 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
00382 parentPoint.x()+(wgap/2), parentPoint.y()-3,
00383 parentPoint.x()+wgap/2, childPoint.y()+3,
00384 parentPoint.x()+(wgap/2)+3, childPoint.y(),
00385 childPoint.x(), childPoint.y());
00386 }
00387 else
00388 {
00389 a.putPoints(1, 9,
00390 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
00391 parentPoint.x()+(wgap/2), parentPoint.y()-3,
00392 parentPoint.x()+wgap/2, parentTop-(hgap/2)+3,
00393 parentPoint.x()+(wgap/2)+3, parentTop-(hgap/2),
00394 childPoint.x()-(wgap/2)-3, parentTop-hgap/2,
00395 childPoint.x()-(wgap/2), parentTop-(hgap/2)-3,
00396 childPoint.x()-wgap/2, childPoint.y()+3,
00397 childPoint.x()-(wgap/2)+3, childPoint.y(),
00398 childPoint.x(), childPoint.y());
00399 }
00400 }
00401 else if ( parentRow < childRow )
00402 {
00403 if (parentCol == childCol - 1)
00404 {
00405 a.putPoints(1, 5,
00406 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
00407 parentPoint.x()+(wgap/2), parentPoint.y()+3,
00408 parentPoint.x()+wgap/2, childPoint.y()-3,
00409 parentPoint.x()+(wgap/2)+3, childPoint.y(),
00410 childPoint.x(), childPoint.y());
00411
00412 }
00413 else
00414 {
00415 a.putPoints(1, 9,
00416 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
00417 parentPoint.x()+(wgap/2), parentPoint.y()+3,
00418 parentPoint.x()+wgap/2, childTop-(hgap/2)-3,
00419 parentPoint.x()+(wgap/2)+3, childTop-(hgap/2),
00420 childPoint.x()-(wgap/2)-3, childTop-(hgap/2),
00421 childPoint.x()-(wgap/2), childTop-(hgap/2)+3,
00422 childPoint.x()-wgap/2, childPoint.y()-3,
00423 childPoint.x()-wgap/2+3, childPoint.y(),
00424 childPoint.x(), childPoint.y());
00425 }
00426 }
00427 setPoints(a);
00428 }
00429
00430 void PertRelationItem::setFinishFinishPoints()
00431 {
00432
00433 QPoint parentPoint = m_parentItem->exitPoint(Relation::FinishFinish);
00434 QPoint childPoint = m_childItem->entryPoint(Relation::FinishFinish);
00435
00436 QPointArray a;
00437 a.putPoints(0, 1, parentPoint.x(), parentPoint.y());
00438
00439
00440 if ( parentRow >= childRow )
00441 {
00442 if (parentCol == childCol)
00443 {
00444 a.putPoints(1, 5,
00445 childPoint.x()+(wgap/2)-3, parentPoint.y(),
00446 childPoint.x()+(wgap/2), parentPoint.y()-3,
00447 childPoint.x()+wgap/2, childPoint.y()+3,
00448 childPoint.x()+(wgap/2)-3, childPoint.y(),
00449 childPoint.x(), childPoint.y());
00450 }
00451 else if (parentCol < childCol)
00452 {
00453 a.putPoints(1, 9,
00454 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
00455 parentPoint.x()+(wgap/2), parentPoint.y()+3,
00456 parentPoint.x()+(wgap/2), parentBottom+(hgap/2)-3,
00457 parentPoint.x()+(wgap/2)+3, parentBottom+(hgap/2),
00458 childPoint.x()+(wgap/2)-3, parentBottom+(hgap/2),
00459 childPoint.x()+(wgap/2), parentBottom+(hgap/2)-3,
00460 childPoint.x()+(wgap/2), childPoint.y()+3,
00461 childPoint.x()+(wgap/2)-3, childPoint.y(),
00462 childPoint.x(), childPoint.y());
00463 }
00464 }
00465 else
00466 {
00467 if (parentCol == childCol)
00468 {
00469 a.putPoints(1, 5,
00470 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
00471 parentPoint.x()+(wgap/2), parentPoint.y()+3,
00472 parentPoint.x()+wgap/2, childPoint.y()-3,
00473 parentPoint.x()+(wgap/2)-3, childPoint.y(),
00474 childPoint.x(), childPoint.y());
00475 }
00476 else if (parentCol < childCol)
00477 {
00478 if (rowFree(parentRow, parentCol+1, childCol))
00479 a.putPoints(1, 5,
00480 childPoint.x()+(wgap/2)-3, parentPoint.y(),
00481 childPoint.x()+(wgap/2), parentPoint.y()+3,
00482 childPoint.x()+(wgap/2), childPoint.y()-3,
00483 childPoint.x()+(wgap/2)-3, childPoint.y(),
00484 childPoint.x(), childPoint.y());
00485 else
00486 a.putPoints(1, 9,
00487 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
00488 parentPoint.x()+(wgap/2), parentPoint.y()+3,
00489 parentPoint.x()+wgap/2, childTop-(hgap/2)-3,
00490 parentPoint.x()+(wgap/2)+3, childTop-(hgap/2),
00491 childPoint.x()+(wgap/2)-3, childTop-(hgap/2),
00492 childPoint.x()+(wgap/2), childTop-(hgap/2)+3,
00493 childPoint.x()+(wgap/2), childPoint.y()-3,
00494 childPoint.x()+(wgap/2)-3, childPoint.y(),
00495 childPoint.x(), childPoint.y());
00496 }
00497 else
00498 {
00499 a.putPoints(1, 9,
00500 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
00501 parentPoint.x()+(wgap/2), parentPoint.y()+3,
00502 parentPoint.x()+wgap/2, childTop-(hgap/2)-3,
00503 parentPoint.x()+(wgap/2)+3, childTop-(hgap/2),
00504 childPoint.x()+(wgap/2)-3, childTop-(hgap/2),
00505 childPoint.x()+(wgap/2), childTop-(hgap/2)+3,
00506 childPoint.x()+wgap/2, childPoint.y()-3,
00507 childPoint.x()+wgap/2-3, childPoint.y(),
00508 childPoint.x(), childPoint.y());
00509 }
00510 }
00511 setPoints(a);
00512 }
00513
00514 void PertRelationItem::setStartStartPoints()
00515 {
00516
00517 QPoint parentPoint = m_parentItem->exitPoint(Relation::StartStart);
00518 QPoint childPoint = m_childItem->entryPoint(Relation::StartStart);
00519
00520 QPointArray a;
00521 a.putPoints(0, 1, parentPoint.x(), parentPoint.y());
00522
00523 if ( parentRow > childRow )
00524 {
00525 if (parentCol == childCol)
00526 {
00527 a.putPoints(1, 4,
00528 parentPoint.x()-(wgap/2)+3, parentPoint.y(),
00529 parentPoint.x()-(wgap/2), parentPoint.y()-3,
00530 parentPoint.x()-(wgap/2), childPoint.y()+3,
00531 parentPoint.x()-(wgap/2)+3, childPoint.y());
00532 }
00533 else
00534 {
00535 a.putPoints(1, 8,
00536 parentPoint.x()-(wgap/2)+3, parentPoint.y(),
00537 parentPoint.x()-(wgap/2), parentPoint.y()-3,
00538 parentPoint.x()-(wgap/2), parentTop-(hgap/2)+3,
00539 parentPoint.x()-(wgap/2)+3, parentTop-(hgap/2),
00540 childPoint.x()-(wgap/2)-3, parentTop-(hgap/2),
00541 childPoint.x()-(wgap/2), parentTop-(hgap/2)-3,
00542 childPoint.x()-(wgap/2), childPoint.y()+3,
00543 childPoint.x()-(wgap/2)+3, childPoint.y());
00544 }
00545 }
00546 else
00547 {
00548 a.putPoints(1, 2,
00549 parentPoint.x()-(wgap/2)+3, parentPoint.y(),
00550 parentPoint.x()-(wgap/2), parentPoint.y()+3);
00551
00552 if (parentCol == childCol)
00553 {
00554 a.putPoints(3, 2,
00555 parentPoint.x()-(wgap/2), childPoint.y()-3,
00556 parentPoint.x()-(wgap/2)+3, childPoint.y());
00557 }
00558 else
00559 {
00560 if (parentRow == childRow)
00561 {
00562 a.putPoints(3, 6,
00563 parentPoint.x()-(wgap/2), parentBottom+hgap/2-3,
00564 parentPoint.x()-(wgap/2)+3, parentBottom+hgap/2,
00565 childPoint.x()-(wgap/2)-3, parentBottom+hgap/2,
00566 childPoint.x()-(wgap/2), parentBottom+hgap/2-3,
00567 childPoint.x()-(wgap/2), childPoint.y()+3,
00568 childPoint.x()-(wgap/2)+3, childPoint.y());
00569 }
00570 else
00571 {
00572 a.putPoints(3, 6,
00573 parentPoint.x()-(wgap/2), childTop-(hgap/2)-3,
00574 parentPoint.x()-(wgap/2)+3, childTop-hgap/2,
00575 childPoint.x()-(wgap/2)-3, childTop-hgap/2,
00576 childPoint.x()-(wgap/2), childTop-(hgap/2)+3,
00577 childPoint.x()-(wgap/2), childPoint.y()-3,
00578 childPoint.x()-(wgap/2)+3, childPoint.y());
00579 }
00580 }
00581 }
00582 a.putPoints(a.size(), 1, childPoint.x(), childPoint.y());
00583 setPoints(a);
00584 }
00585
00586 void PertRelationItem::drawShape(QPainter &p)
00587 {
00588
00589
00590 setBrush(Qt::NoBrush);
00591 QPointArray a = poly;
00592 int size = a.size()-1;
00593 for(int i = 0; i < size; ++i)
00594 {
00595
00596 p.drawLine(a[i], a[i+1]);
00597 }
00598
00599 int pos = a.size()-1;
00600 int xoffset = -3;
00601 if ( pos > 1&& a[pos-1].x() > a[pos].x())
00602 xoffset = 3;
00603 QPoint pnt(a[pos].x()+xoffset, a[pos].y()-3);
00604 p.drawLine(a[pos], pnt);
00605 pnt.setY(a[pos].y()+3);
00606 p.drawLine(a[pos], pnt);
00607 }
00608
00609 QPointArray PertRelationItem::areaPoints () const
00610 {
00611 QPointArray pa(4);
00612 int pw = (pen().width()+1)/2;
00613 if ( pw < 1 ) pw = 1;
00614 if ( pen() == NoPen ) pw = 0;
00615 pa[0] = QPoint(left-pw,top-pw);
00616 pa[1] = pa[0] + QPoint(right-left+pw*2,0);
00617 pa[2] = pa[1] + QPoint(0,bottom-top+pw*2);
00618 pa[3] = pa[0] + QPoint(0,bottom-top+pw*2);
00619
00620
00621
00622 return pa;
00623 }
00624
00625 bool PertRelationItem::rowFree(int row, int startCol, int endCol)
00626 {
00627 QCanvasItemList list = canvas()->allItems();
00628 QCanvasItemList::Iterator it = list.begin();
00629 for (; it != list.end(); ++it)
00630 {
00631 if ( (*it)->rtti() == PertProjectItem::RTTI ||
00632 (*it)->rtti() == PertTaskItem::RTTI ||
00633 (*it)->rtti() == PertMilestoneItem::RTTI )
00634 {
00635 PertNodeItem *item = (PertNodeItem *)(*it);
00636 if ( item->row() == row )
00637 {
00638 int col = item->column();
00639 if (col >= startCol && col <= endCol)
00640 {
00641
00642 return false;
00643 }
00644 }
00645 }
00646 }
00647 return true;
00648 }
00649
00650 #ifndef NDEBUG
00651 void PertRelationItem::printDebug( int )
00652 {
00653 }
00654 #endif
00655
00657 KDGanttViewTaskLink::LinkType ItemBase::kdLinkType(int relationType) {
00658 switch (relationType) {
00659 case Relation::FinishStart:
00660 return KDGanttViewTaskLink::FinishStart;
00661 break;
00662 case Relation::FinishFinish:
00663 return KDGanttViewTaskLink::FinishFinish;
00664 break;
00665 case Relation::StartStart:
00666 return KDGanttViewTaskLink::StartStart;
00667 break;
00668 default:
00669 break;
00670 }
00671 return KDGanttViewTaskLink::None;
00672 }
00673
00675
00676
00677 GanttViewSummaryItem::GanttViewSummaryItem(KDGanttView *parent, Node *node)
00678 : KDGanttViewSummaryItem(parent, node->name()),
00679 m_node(node),
00680 m_view(parent)
00681 {
00682 setExpandable(true);
00683 setOpen(true);
00684 }
00685
00686 GanttViewSummaryItem::GanttViewSummaryItem(KDGanttViewItem *parent, Node *node)
00687 : KDGanttViewSummaryItem(parent, node->name()),
00688 m_node(node),
00689 m_view(0)
00690 {
00691 m_drawn = false;
00692 GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
00693 if (p)
00694 m_view = p->ganttView();
00695 setExpandable(true);
00696 setOpen(true);
00697 }
00698
00699 void GanttViewSummaryItem::insertRelations(GanttView *view)
00700 {
00701
00702
00703 QPtrListIterator<Relation> it(m_node->dependChildNodes());
00704 for (; it.current(); ++it)
00705 {
00706 KDGanttViewItem *child = find(m_view->firstChild(), it.current()->child());
00707 if (child)
00708 {
00709 KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(it.current()->type()));
00710
00711 QString t = i18n("From: %1").arg(this->listViewText(0));
00712 t += "\n" + i18n("To: %1").arg(child->listViewText(0));
00713 if (it.current()->lag() > Duration::zeroDuration) {
00714 t += "\n" + i18n("Lag: %1").arg(it.current()->lag().toString(Duration::Format_i18nDayTime));
00715 }
00716 link->setTooltipText(t);
00717 view->addTaskLink(link);
00718 }
00719 }
00720 }
00721
00722 KDGanttViewItem *GanttViewSummaryItem::find(Node *node)
00723 {
00724
00725 if (m_node == node)
00726 return this;
00727
00728 KDGanttViewItem *item = find(firstChild(), node);
00729 if (item)
00730 return item;
00731
00732 return find(nextSibling(), node);
00733 }
00734
00735
00736 KDGanttViewItem *GanttViewSummaryItem::find(KDGanttViewItem *item, Node *node)
00737 {
00738 if (!item)
00739 return 0;
00740
00741 if (item->type() == Event)
00742 {
00743 GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
00744 return i->find(node);
00745 }
00746 else if (item->type() == Task)
00747 {
00748 GanttViewTaskItem *i = static_cast<GanttViewTaskItem *>(item);
00749 return i->find(node);
00750 }
00751 else if (item->type() == Summary)
00752 {
00753 GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
00754 return i->find(node);
00755 }
00756 return 0;
00757 }
00758
00760
00761
00762 GanttViewTaskItem::GanttViewTaskItem(KDGanttView *parent, KPlato::Task *task)
00763 : KDGanttViewTaskItem(parent, task->name()),
00764 m_task(task),
00765 m_view(parent)
00766 {
00767 }
00768
00769 GanttViewTaskItem::GanttViewTaskItem(KDGanttViewItem *parent, KPlato::Task *task)
00770 : KDGanttViewTaskItem(parent, task->name()),
00771 m_task(task),
00772 m_view()
00773 {
00774 m_drawn = false;
00775 GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
00776 if (p)
00777 m_view = p->ganttView();
00778 }
00779
00780 void GanttViewTaskItem::insertRelations(GanttView *view)
00781 {
00782
00783
00784 QPtrListIterator<Relation> it(m_task->dependChildNodes());
00785 for (; it.current(); ++it)
00786 {
00787 KDGanttViewItem *child = find(m_view->firstChild(), it.current()->child());
00788 if (child)
00789 {
00790 KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(it.current()->type()));
00791
00792 QString t = i18n("From: %1").arg(this->listViewText(0));
00793 t += "\n" + i18n("To: %1").arg(child->listViewText(0));
00794 if (it.current()->lag() > Duration::zeroDuration) {
00795 t += "\n" + i18n("Lag: %1").arg(it.current()->lag().toString(Duration::Format_i18nDayTime));
00796 }
00797 link->setTooltipText(t);
00798 view->addTaskLink(link);
00799 }
00800 }
00801 }
00802
00803 KDGanttViewItem *GanttViewTaskItem::find(Node *node)
00804 {
00805
00806 if (m_task == node)
00807 return this;
00808
00809 KDGanttViewItem *item = find(firstChild(), node);
00810 if (item)
00811 return item;
00812
00813 return find(nextSibling(), node);
00814 }
00815
00816
00817 KDGanttViewItem *GanttViewTaskItem::find(KDGanttViewItem *item, Node *node)
00818 {
00819 if (!item)
00820 return 0;
00821
00822 if (item->type() == Event)
00823 {
00824 GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
00825 return i->find(node);
00826 }
00827 else if (item->type() == Task)
00828 {
00829 GanttViewTaskItem *i= static_cast<GanttViewTaskItem *>(item);
00830 return i->find(node);
00831 }
00832 else if (item->type() == Summary)
00833 {
00834 GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
00835 return i->find(node);
00836 }
00837 return 0;
00838 }
00839
00841
00842
00843 GanttViewEventItem::GanttViewEventItem(KDGanttView *parent, KPlato::Task *task)
00844 : KDGanttViewEventItem(parent, task->name()),
00845 m_task(task),
00846 m_view(parent)
00847 {
00848 }
00849
00850 GanttViewEventItem::GanttViewEventItem(KDGanttViewItem *parent, KPlato::Task *task)
00851 : KDGanttViewEventItem(parent, task->name()),
00852 m_task(task),
00853 m_view()
00854 {
00855 m_drawn = false;
00856 GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
00857 if (p)
00858 m_view = p->ganttView();
00859 }
00860
00861
00862 void GanttViewEventItem::insertRelations(GanttView *view)
00863 {
00864
00865
00866 QPtrListIterator<Relation> it(m_task->dependChildNodes());
00867 for (; it.current(); ++it)
00868 {
00869 KDGanttViewItem *child = find(m_view->firstChild(), it.current()->child());
00870 if (child)
00871 {
00872 KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(it.current()->type()));
00873
00874 QString t = i18n("From: %1").arg(this->listViewText(0));
00875 t += "\n" + i18n("To: %1").arg(child->listViewText(0));
00876 if (it.current()->lag() > Duration::zeroDuration) {
00877 t += "\n" + i18n("Lag: %1").arg(it.current()->lag().toString(Duration::Format_i18nDayTime));
00878 }
00879 link->setTooltipText(t);
00880 view->addTaskLink(link);
00881 }
00882 }
00883 }
00884
00885 KDGanttViewItem *GanttViewEventItem::find(Node *node)
00886 {
00887
00888 if (m_task == node)
00889 return this;
00890
00891 KDGanttViewItem *item = find(firstChild(), node);
00892 if (item)
00893 return item;
00894
00895 return find(nextSibling(), node);
00896 }
00897
00898
00899 KDGanttViewItem *GanttViewEventItem::find(KDGanttViewItem *item, Node *node)
00900 {
00901 if (!item)
00902 return 0;
00903
00904 if (item->type() == Event)
00905 {
00906 GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
00907 return i->find(node);
00908 }
00909 else if (item->type() == Task)
00910 {
00911 GanttViewTaskItem *i = static_cast<GanttViewTaskItem *>(item);
00912 return i->find(node);
00913 }
00914 else if (item->type() == Summary)
00915 {
00916 GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
00917 return i->find(node);
00918 }
00919 return 0;
00920 }
00921
00922 }