KDGantt::GraphicsItem Class Reference

#include <kdganttgraphicsitem.h>

Inheritance diagram for KDGantt::GraphicsItem:

Inheritance graph
[legend]
Collaboration diagram for KDGantt::GraphicsItem:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 42 of file kdganttgraphicsitem.h.


Public Types

enum  { Type = UserType + 42 }

Public Member Functions

void addEndConstraint (ConstraintGraphicsItem *)
void addStartConstraint (ConstraintGraphicsItem *)
QRectF boundingRect () const
QList< ConstraintGraphicsItem * > endConstraints () const
virtual QString ganttToolTip () const
 GraphicsItem (const QModelIndex &idx, QGraphicsItem *parent=0, GraphicsScene *scene=0)
 GraphicsItem (QGraphicsItem *parent=0, GraphicsScene *scene=0)
const QPersistentModelIndex & index () const
bool isEditable () const
bool isUpdating () const
QVariant itemChange (GraphicsItemChange, const QVariant &value)
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
QRectF rect () const
void removeEndConstraint (ConstraintGraphicsItem *)
void removeStartConstraint (ConstraintGraphicsItem *)
GraphicsScenescene () const
void setBoundingRect (const QRectF &r)
void setIndex (const QPersistentModelIndex &idx)
void setRect (const QRectF &r)
QList< ConstraintGraphicsItem * > startConstraints () const
int type () const
void updateItem (const Span &rowgeometry, const QPersistentModelIndex &idx)
virtual ~GraphicsItem ()

Protected Member Functions

void focusInEvent (QFocusEvent *event)
void hoverLeaveEvent (QGraphicsSceneHoverEvent *)
void hoverMoveEvent (QGraphicsSceneHoverEvent *)
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *)
void mouseMoveEvent (QGraphicsSceneMouseEvent *)
void mousePressEvent (QGraphicsSceneMouseEvent *)
void mouseReleaseEvent (QGraphicsSceneMouseEvent *)

Member Enumeration Documentation

anonymous enum

Enumerator:
Type 

Definition at line 44 of file kdganttgraphicsitem.h.

00044 { Type = UserType + 42 };


Constructor & Destructor Documentation

GraphicsItem::GraphicsItem ( QGraphicsItem parent = 0,
GraphicsScene scene = 0 
) [explicit]

Definition at line 71 of file kdganttgraphicsitem.cpp.

00072     : BASE( parent, scene ),  m_isupdating( false )
00073 {
00074   init();
00075 }

GraphicsItem::GraphicsItem ( const QModelIndex &  idx,
QGraphicsItem parent = 0,
GraphicsScene scene = 0 
) [explicit]

Definition at line 77 of file kdganttgraphicsitem.cpp.

00079     : BASE( parent, scene ),  m_index( idx ), m_isupdating( false )
00080 {
00081   init();
00082 }

GraphicsItem::~GraphicsItem (  )  [virtual]

Definition at line 84 of file kdganttgraphicsitem.cpp.

00085 {
00086 }


Member Function Documentation

void GraphicsItem::addEndConstraint ( ConstraintGraphicsItem item  ) 

Definition at line 255 of file kdganttgraphicsitem.cpp.

References KDGantt::ConstraintGraphicsItem::setEnd().

Referenced by KDGantt::GraphicsScene::insertItem().

00256 {
00257     assert( item );
00258     m_endConstraints << item;
00259     item->setEnd( endConnector( item->constraint().relationType() ) );
00260     constraintsChanged();
00261 }

void GraphicsItem::addStartConstraint ( ConstraintGraphicsItem item  ) 

Definition at line 247 of file kdganttgraphicsitem.cpp.

References KDGantt::ConstraintGraphicsItem::setStart().

Referenced by KDGantt::GraphicsScene::insertItem().

00248 {
00249     assert( item );
00250     m_startConstraints << item;
00251     item->setStart( startConnector( item->constraint().relationType() ) );
00252     constraintsChanged();
00253 }

QRectF GraphicsItem::boundingRect (  )  const

Definition at line 209 of file kdganttgraphicsitem.cpp.

Referenced by mouseReleaseEvent(), and paint().

00210 {
00211     return m_boundingrect;
00212 }

QList<ConstraintGraphicsItem*> KDGantt::GraphicsItem::endConstraints (  )  const

Definition at line 77 of file kdganttgraphicsitem.h.

Referenced by KDGantt::GraphicsScene::removeItem().

00077 { return m_endConstraints; }

void GraphicsItem::focusInEvent ( QFocusEvent *  event  )  [protected]

Definition at line 354 of file kdganttgraphicsitem.cpp.

References index(), scene(), and KDGantt::GraphicsScene::selectionModel().

00355 {
00356     Q_UNUSED( event );
00357     scene()->selectionModel()->select( index(), QItemSelectionModel::SelectCurrent );
00358 }

QString GraphicsItem::ganttToolTip (  )  const [virtual]

Definition at line 191 of file kdganttgraphicsitem.cpp.

References KDGantt::EndTimeRole, index(), and KDGantt::StartTimeRole.

00192 {
00193     // TODO: Make delegate handle this
00194     const QAbstractItemModel* model = index().model();
00195     if ( !model ) return QString();
00196 #if 0
00197     QString dbgstr;
00198     QDebug( &dbgstr ) << m_index;
00199     return dbgstr;
00200 #endif
00201     QString tip = model->data( index(), Qt::ToolTipRole ).toString();
00202     if ( !tip.isNull() ) return tip;
00203     else return GraphicsScene::tr( "%1 -> %2: %3" )
00204         .arg( model->data( index(), StartTimeRole ).toString() )
00205         .arg( model->data( index(), EndTimeRole ).toString() )
00206         .arg( model->data( index(), Qt::DisplayRole ).toString() );
00207 }

void GraphicsItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent *   )  [protected]

Definition at line 413 of file kdganttgraphicsitem.cpp.

00414 {
00415     unsetCursor();
00416 }

void GraphicsItem::hoverMoveEvent ( QGraphicsSceneHoverEvent *  event  )  [protected]

Definition at line 390 of file kdganttgraphicsitem.cpp.

References index(), KDGantt::ItemDelegate::interactionStateFor(), isEditable(), KDGantt::GraphicsScene::itemDelegate(), KDGantt::GraphicsScene::itemEntered(), scene(), KDGantt::ItemDelegate::State_ExtendLeft, KDGantt::ItemDelegate::State_ExtendRight, and KDGantt::ItemDelegate::State_Move.

00391 {
00392     if (  !isEditable() ) return;
00393     StyleOptionGanttItem opt = getStyleOption();
00394     ItemDelegate::InteractionState istate = scene()->itemDelegate()->interactionStateFor( event->pos(), opt, index() );
00395     switch( istate ) {
00396     case ItemDelegate::State_ExtendLeft:
00397         setCursor( Qt::SizeHorCursor );
00398         scene()->itemEntered( index() );
00399         break;
00400     case ItemDelegate::State_ExtendRight:
00401         setCursor( Qt::SizeHorCursor );
00402         scene()->itemEntered( index() );
00403         break;
00404     case ItemDelegate::State_Move:
00405         setCursor( Qt::SplitHCursor );
00406         scene()->itemEntered( index() );
00407         break;
00408     default:
00409         unsetCursor();
00410     };
00411 }

const QPersistentModelIndex& KDGantt::GraphicsItem::index (  )  const

Definition at line 66 of file kdganttgraphicsitem.h.

Referenced by focusInEvent(), ganttToolTip(), hoverMoveEvent(), itemChange(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), paint(), and updateItem().

00066 { return m_index; }

bool GraphicsItem::isEditable (  )  const

Definition at line 168 of file kdganttgraphicsitem.cpp.

References KDGantt::GraphicsScene::isReadOnly(), and scene().

Referenced by hoverMoveEvent(), itemChange(), mouseMoveEvent(), and mouseReleaseEvent().

00169 {
00170     return !scene()->isReadOnly() && m_index.model()->flags( m_index ) & Qt::ItemIsEditable;
00171 }

bool KDGantt::GraphicsItem::isUpdating (  )  const

Definition at line 70 of file kdganttgraphicsitem.h.

Referenced by itemChange().

00070 { return m_isupdating; }

QVariant GraphicsItem::itemChange ( GraphicsItemChange  change,
const QVariant &  value 
)

Definition at line 328 of file kdganttgraphicsitem.cpp.

References index(), isEditable(), isUpdating(), scene(), and KDGantt::GraphicsScene::selectionModel().

00329 {
00330     if ( !isUpdating() && change==ItemPositionChange && scene() ) {
00331         QPointF newPos=value.toPointF();
00332         if ( isEditable() ) {
00333             newPos.setY( pos().y() );
00334             return newPos;
00335         } else {
00336             return pos();
00337         }
00338     } else if ( change==QGraphicsItem::ItemSelectedChange ) {
00339         if ( index().isValid() && !( index().model()->flags( index() ) & Qt::ItemIsSelectable ) ) {
00340             // Reject selection attempt
00341             return qVariantFromValue( false );
00342         }
00343 
00344         if ( value.toBool() ) {
00345             scene()->selectionModel()->select( index(), QItemSelectionModel::Select );
00346         } else {
00347             scene()->selectionModel()->select( index(), QItemSelectionModel::Deselect );
00348         }
00349     }
00350 
00351     return QGraphicsItem::itemChange( change, value );
00352 }

void GraphicsItem::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent *  event  )  [protected]

Definition at line 484 of file kdganttgraphicsitem.cpp.

References index(), KDGantt::ItemDelegate::interactionStateFor(), KDGantt::GraphicsScene::itemDelegate(), KDGantt::GraphicsScene::itemDoubleClicked(), scene(), and KDGantt::ItemDelegate::State_None.

00485 {
00486     StyleOptionGanttItem opt = getStyleOption();
00487     ItemDelegate::InteractionState istate = scene()->itemDelegate()->interactionStateFor( event->pos(), opt, index() );
00488     if ( istate != ItemDelegate::State_None ) {
00489         scene()->itemDoubleClicked( index() );
00490     }
00491     BASE::mouseDoubleClickEvent( event );
00492 }

void GraphicsItem::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event  )  [protected]

Definition at line 525 of file kdganttgraphicsitem.cpp.

References index(), isEditable(), rect(), scene(), KDGantt::GraphicsScene::selectionModel(), KDGantt::GraphicsScene::setDragSource(), KDGantt::ItemDelegate::State_DragConstraint, KDGantt::ItemDelegate::State_ExtendLeft, KDGantt::ItemDelegate::State_ExtendRight, and KDGantt::ItemDelegate::State_Move.

00526 {
00527     if (  !isEditable() ) return;
00528     if ( m_presspos.isNull() ) return;
00529 
00530     //qDebug() << "GraphicsItem::mouseMoveEvent("<<event<<"), m_istate="<< static_cast<ItemDelegate::InteractionState>( m_istate );
00531     QPointF pos = event->pos() - m_presspos;
00532     switch( m_istate ) {
00533     case ItemDelegate::State_ExtendLeft:
00534     case ItemDelegate::State_ExtendRight:
00535     case ItemDelegate::State_Move:
00536         // Check for constraint drag
00537       if ( qAbs( m_pressscenepos.x()-event->scenePos().x() ) < 10.
00538            && qAbs( m_pressscenepos.y()-event->scenePos().y() ) > 5. ) {
00539             m_istate = ItemDelegate::State_DragConstraint;
00540             m_dragline = new QGraphicsLineItem( this );
00541             m_dragline->setPen( QPen( Qt::DashLine ) );
00542             m_dragline->setLine(QLineF( rect().center(), event->pos() ));
00543             scene()->addItem( m_dragline );
00544             scene()->setDragSource( this );
00545             break;
00546         }
00547 
00548         scene()->selectionModel()->setCurrentIndex( index(), QItemSelectionModel::Current );
00549         updateItemFromMouse(event->scenePos());
00550         //BASE::mouseMoveEvent(event);
00551         break;
00552     case ItemDelegate::State_DragConstraint: {
00553         QLineF line = m_dragline->line();
00554         m_dragline->setLine( QLineF( line.p1(), event->pos() ) );
00555         //QGraphicsItem* item = scene()->itemAt( event->scenePos() );
00556         break;
00557     }
00558     }
00559 }

void GraphicsItem::mousePressEvent ( QGraphicsSceneMouseEvent *  event  )  [protected]

Definition at line 418 of file kdganttgraphicsitem.cpp.

References index(), KDGantt::ItemDelegate::interactionStateFor(), KDGantt::GraphicsScene::itemDelegate(), KDGantt::GraphicsScene::itemPressed(), scene(), KDGantt::ItemDelegate::State_ExtendLeft, KDGantt::ItemDelegate::State_ExtendRight, and KDGantt::ItemDelegate::State_None.

00419 {
00420     //qDebug() << "GraphicsItem::mousePressEvent("<<event<<")";
00421     StyleOptionGanttItem opt = getStyleOption();
00422     int istate = scene()->itemDelegate()->interactionStateFor( event->pos(), opt, index() );
00423     // If State_None is returned by interactionStateFor(), we ignore this event so that
00424     // it can get forwarded to another item that's below this one. Needed, for example,
00425     // to allow items to be moved that are placed below the label of another item.
00426     if ( istate != ItemDelegate::State_None ) {
00427         m_istate = istate;
00428         m_presspos = event->pos();
00429         m_pressscenepos = event->scenePos();
00430         scene()->itemPressed( index() );
00431 
00432         switch( m_istate ) {
00433         case ItemDelegate::State_ExtendLeft:
00434         case ItemDelegate::State_ExtendRight:
00435         default: /* State_Move */
00436             BASE::mousePressEvent( event );
00437             break;
00438         }
00439     } else {
00440         event->ignore();
00441     }
00442 }

void GraphicsItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event  )  [protected]

Definition at line 444 of file kdganttgraphicsitem.cpp.

References KDGantt::GraphicsView::addConstraint(), boundingRect(), index(), isEditable(), KDGantt::GraphicsScene::itemClicked(), rect(), scene(), and KDGantt::GraphicsScene::setDragSource().

00445 {
00446     //qDebug() << "GraphicsItem::mouseReleaseEvent("<<event << ")";
00447     if ( !m_presspos.isNull() ) {
00448         scene()->itemClicked( index() );
00449     }
00450     delete m_dragline; m_dragline = 0;
00451     if ( scene()->dragSource() ) {
00452         // Create a new constraint
00453         GraphicsItem* other = qgraphicsitem_cast<GraphicsItem*>( scene()->itemAt( event->scenePos() ) );
00454         if ( other && scene()->dragSource()!=other &&
00455              other->mapToScene( other->rect() ).boundingRect().contains( event->scenePos() )) {
00456             GraphicsView* view = qobject_cast<GraphicsView*>( event->widget()->parentWidget() );
00457             if ( view ) {
00458                 view->addConstraint( scene()->summaryHandlingModel()->mapToSource( scene()->dragSource()->index() ),
00459                                      scene()->summaryHandlingModel()->mapToSource( other->index() ), event->modifiers() );
00460             }
00461         }
00462         scene()->setDragSource( 0 );
00463         //scene()->update();
00464     } else {
00465         if ( isEditable() ) {
00466             updateItemFromMouse(event->scenePos());
00467 
00468             // It is important to set m_presspos to null here because
00469             // when the sceneRect updates because we move the item
00470             // a MouseMoveEvent will be delivered, and we have to
00471             // protect against that
00472             m_presspos = QPointF();
00473             updateModel();
00474             // without this command we sometimes get a white area at the left side of a task item
00475             // after we moved that item right-ways into a grey weekend section of the scene:
00476             scene()->update();
00477         }
00478     }
00479 
00480     m_presspos = QPointF();
00481     BASE::mouseReleaseEvent( event );
00482 }

void GraphicsItem::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget widget = 0 
)

Definition at line 173 of file kdganttgraphicsitem.cpp.

References boundingRect(), index(), KDGantt::GraphicsScene::itemDelegate(), KDGantt::ItemDelegate::paintGanttItem(), and scene().

00175 {
00176     Q_UNUSED( widget );
00177     if ( boundingRect().isValid() && scene() ) {
00178         StyleOptionGanttItem opt = getStyleOption();
00179         *static_cast<QStyleOption*>(&opt) = *static_cast<const QStyleOption*>( option );
00180         //opt.fontMetrics = painter->fontMetrics();
00181         scene()->itemDelegate()->paintGanttItem( painter, opt, index() );
00182     }
00183 }

QRectF KDGantt::GraphicsItem::rect (  )  const

Definition at line 60 of file kdganttgraphicsitem.h.

Referenced by mouseMoveEvent(), mouseReleaseEvent(), updateItem(), and KDGantt::GraphicsScene::updateItems().

00060 { return m_rect; }

void GraphicsItem::removeEndConstraint ( ConstraintGraphicsItem item  ) 

Definition at line 270 of file kdganttgraphicsitem.cpp.

00271 {
00272     assert( item );
00273     m_endConstraints.removeAll( item );
00274     constraintsChanged();
00275 }

void GraphicsItem::removeStartConstraint ( ConstraintGraphicsItem item  ) 

Definition at line 263 of file kdganttgraphicsitem.cpp.

00264 {
00265     assert( item );
00266     m_startConstraints.removeAll( item );
00267     constraintsChanged();
00268 }

GraphicsScene * GraphicsItem::scene (  )  const

Definition at line 141 of file kdganttgraphicsitem.cpp.

Referenced by focusInEvent(), hoverMoveEvent(), isEditable(), itemChange(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), paint(), and updateItem().

00142 {
00143     return qobject_cast<GraphicsScene*>( QGraphicsItem::scene() );
00144 }

void GraphicsItem::setBoundingRect ( const QRectF &  r  ) 

Definition at line 161 of file kdganttgraphicsitem.cpp.

Referenced by updateItem().

00162 {
00163     prepareGeometryChange();
00164     m_boundingrect = r;
00165     update();
00166 }

void GraphicsItem::setIndex ( const QPersistentModelIndex &  idx  ) 

Definition at line 185 of file kdganttgraphicsitem.cpp.

Referenced by updateItem(), and KDGantt::GraphicsScene::updateRow().

00186 {
00187     m_index=idx;
00188     update();
00189 }

void GraphicsItem::setRect ( const QRectF &  r  ) 

Definition at line 146 of file kdganttgraphicsitem.cpp.

Referenced by updateItem().

00147 {
00148 #if 0
00149     qDebug() << "GraphicsItem::setRect("<<r<<"), txt="<<m_index.model()->data( m_index, Qt::DisplayRole ).toString();
00150     if ( m_index.model()->data( m_index, Qt::DisplayRole ).toString() == QLatin1String("Code Freeze" ) ) {
00151         qDebug() << "gotcha";
00152     }
00153 #endif
00154 
00155     prepareGeometryChange();
00156     m_rect = r;
00157     updateConstraintItems();
00158     update();
00159 }

QList<ConstraintGraphicsItem*> KDGantt::GraphicsItem::startConstraints (  )  const

Definition at line 76 of file kdganttgraphicsitem.h.

Referenced by KDGantt::GraphicsScene::removeItem().

00076 { return m_startConstraints; }

int GraphicsItem::type (  )  const

Definition at line 100 of file kdganttgraphicsitem.cpp.

References Type.

00101 {
00102     return Type;
00103 }

void GraphicsItem::updateItem ( const Span rowgeometry,
const QPersistentModelIndex &  idx 
)

Definition at line 291 of file kdganttgraphicsitem.cpp.

References KDGantt::GraphicsScene::grid(), index(), KDGantt::ItemDelegate::itemBoundingSpan(), KDGantt::GraphicsScene::itemDelegate(), KDGantt::ItemTypeRole, KDGantt::Span::length(), KDGantt::AbstractGrid::mapToChart(), KDGantt::AbstractRowController::maximumItemHeight(), r, rect(), KDGantt::GraphicsScene::rowController(), scene(), setBoundingRect(), setIndex(), setRect(), KDGantt::Span::start(), and KDGantt::TypeMulti.

Referenced by KDGantt::GraphicsScene::updateItems(), and KDGantt::GraphicsScene::updateRow().

00292 {
00293     //qDebug() << "GraphicsItem::updateItem("<<rowGeometry<<idx<<")";
00294     Updater updater( &m_isupdating );
00295     if ( !idx.isValid() || idx.data( ItemTypeRole )==TypeMulti ) {
00296         setRect( QRectF() );
00297         hide();
00298         return;
00299     }
00300 
00301     const Span s = scene()->grid()->mapToChart( idx );
00302     setPos( QPointF( s.start(), rowGeometry.start() ) );
00303     setRect( QRectF( 0., 0., s.length(), rowGeometry.length() ) );
00304     setIndex( idx );
00305     const Span bs = scene()->itemDelegate()->itemBoundingSpan( getStyleOption(), index() );
00306     //qDebug() << "boundingSpan for" << getStyleOption().text << rect() << "is" << bs;
00307     setBoundingRect( QRectF( bs.start(), 0., bs.length(), rowGeometry.length() ) );
00308     const int maxh = scene()->rowController()->maximumItemHeight();
00309     if ( maxh < rowGeometry.length() ) {
00310         QRectF r = rect();
00311         const Qt::Alignment align = getStyleOption().displayAlignment;
00312         if ( align & Qt::AlignTop ) {
00313             // Do nothing
00314         } else if ( align & Qt::AlignBottom ) {
00315             r.setY( rowGeometry.length()-maxh );
00316         } else {
00317             // Center
00318             r.setY( ( rowGeometry.length()-maxh ) / 2. );
00319         }
00320         r.setHeight( maxh );
00321         setRect( r );
00322     }
00323 
00324     //scene()->setSceneRect( scene()->sceneRect().united( mapToScene( boundingRect() ).boundingRect() ) );
00325     //updateConstraintItems();
00326 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 4 23:27:08 2010 for KD Chart 2 by  doxygen 1.5.4