KDGantt::GraphicsView Class Reference

#include <KDGanttGraphicsView>

Inheritance diagram for KDGantt::GraphicsView:

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

Collaboration graph
[legend]

List of all members.


Detailed Description

The GraphicsView class provides a model/view implementation of a gantt chart.

Definition at line 44 of file kdganttgraphicsview.h.


Public Slots

void setConstraintModel (ConstraintModel *)
void setGrid (AbstractGrid *)
void setItemDelegate (ItemDelegate *delegate)
void setModel (QAbstractItemModel *)
void setReadOnly (bool)
void setRootIndex (const QModelIndex &)
void setRowController (AbstractRowController *)
void setSelectionModel (QItemSelectionModel *)
void setSummaryHandlingModel (QAbstractProxyModel *model)
void updateSceneRect ()

Signals

void activated (const QModelIndex &index)
void clicked (const QModelIndex &index)
void doubleClicked (const QModelIndex &index)
void entered (const QModelIndex &index)
void headerContextMenuRequested (const QPoint &pt)
void pressed (const QModelIndex &index)

Public Member Functions

virtual void addConstraint (const QModelIndex &from, const QModelIndex &to, Qt::KeyboardModifiers modifiers)
void clearItems ()
ConstraintModelconstraintModel () const
void deleteSubtree (const QModelIndex &)
AbstractGridgrid () const
Qt::ContextMenuPolicy headerContextMenuPolicy () const
QModelIndex indexAt (const QPoint &pos) const
bool isReadOnly () const
ItemDelegateitemDelegate () const
QAbstractItemModel * model () const
void print (QPainter *painter, qreal start, qreal end, const QRectF &target=QRectF(), bool drawRowLabels=true)
void print (QPainter *painter, const QRectF &target=QRectF(), bool drawRowLabels=true)
void print (QPrinter *printer, qreal start, qreal end, bool drawRowLabels=true)
void print (QPrinter *printer, bool drawRowLabels=true)
 Q_PRIVATE_SLOT (d, void slotGridChanged()) Q_PRIVATE_SLOT(d
QModelIndex rootIndex () const
AbstractRowControllerrowController () const
QItemSelectionModel * selectionModel () const
void setHeaderContextMenuPolicy (Qt::ContextMenuPolicy)
void void void slotColumnsInserted (const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d
void void void void slotColumnsRemoved (const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d
void void void void void slotDataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)) Q_PRIVATE_SLOT(d
void void slotHeaderContextMenuRequested (const QPoint &)) Q_PRIVATE_SLOT(d
void slotHorizontalScrollValueChanged (int)) Q_PRIVATE_SLOT(d
void void void void void void
void void void void void 
slotItemClicked (const QModelIndex &idx)) Q_PRIVATE_SLOT(d
void void void void void void slotLayoutChanged ()) Q_PRIVATE_SLOT(d
void void void void void void void slotModelReset ()) Q_PRIVATE_SLOT(d
void void void void void void
void void void 
slotRowsAboutToBeRemoved (const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d
void void void void void void
void void 
slotRowsInserted (const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d
void void void void void void
void void void void 
slotRowsRemoved (const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d
QAbstractProxyModelsummaryHandlingModel () const
void updateRow (const QModelIndex &)
void updateScene ()

Protected Member Functions

void resizeEvent (QResizeEvent *)

Properties

bool readOnly

Member Function Documentation

void KDGantt::GraphicsView::activated ( const QModelIndex &  index  )  [signal]

void GraphicsView::addConstraint ( const QModelIndex &  from,
const QModelIndex &  to,
Qt::KeyboardModifiers  modifiers 
) [virtual]

Adds a constraint from from to to. modifiers are the keyboard modifiers pressed by the user when the action is invoked.

Override this to control how contraints are added. The default implementation adds a soft constraint unless the Shift key is pressed, in that case it adds a hard constraint. If a constraint is already present, it is removed and nothing is added.

Definition at line 566 of file kdganttgraphicsview.cpp.

References KDGantt::ConstraintModel::addConstraint(), c, constraintModel(), KDGantt::ConstraintModel::hasConstraint(), isReadOnly(), KDGantt::ConstraintModel::removeConstraint(), KDGantt::Constraint::TypeHard, and KDGantt::Constraint::TypeSoft.

Referenced by KDGantt::GraphicsItem::mouseReleaseEvent().

00569 {
00570     if ( isReadOnly() ) return;
00571     ConstraintModel* cmodel = constraintModel();
00572     assert( cmodel );
00573     Constraint c( from, to, ( modifiers&Qt::ShiftModifier )?Constraint::TypeHard:Constraint::TypeSoft );
00574     if ( cmodel->hasConstraint( c ) ) cmodel->removeConstraint( c );
00575     else cmodel->addConstraint( c );
00576 }

void GraphicsView::clearItems (  ) 

Definition at line 621 of file kdganttgraphicsview.cpp.

References d.

Referenced by updateScene().

00622 {
00623     d->scene.clearItems();
00624 }

void KDGantt::GraphicsView::clicked ( const QModelIndex &  index  )  [signal]

ConstraintModel * GraphicsView::constraintModel (  )  const

Returns:
the KDGantt::ConstraintModel displayed by this view.

Definition at line 427 of file kdganttgraphicsview.cpp.

References d.

Referenced by addConstraint().

00428 {
00429     return d->scene.constraintModel();
00430 }

void GraphicsView::deleteSubtree ( const QModelIndex &  idx  ) 

Definition at line 687 of file kdganttgraphicsview.cpp.

References d.

00688 {
00689     d->scene.deleteSubtree( d->scene.summaryHandlingModel()->mapFromSource( idx ) );
00690 }

void KDGantt::GraphicsView::doubleClicked ( const QModelIndex &  index  )  [signal]

void KDGantt::GraphicsView::entered ( const QModelIndex &  index  )  [signal]

AbstractGrid * GraphicsView::grid (  )  const

Returns:
the AbstractGrid used by this view.

Definition at line 517 of file kdganttgraphicsview.cpp.

References d.

00518 {
00519     return d->scene.grid();
00520 }

Qt::ContextMenuPolicy GraphicsView::headerContextMenuPolicy (  )  const

Returns:
the context menu policy for the header

Definition at line 553 of file kdganttgraphicsview.cpp.

References d.

00554 {
00555     return d->headerwidget.contextMenuPolicy();
00556 }

void KDGantt::GraphicsView::headerContextMenuRequested ( const QPoint &  pt  )  [signal]

QModelIndex GraphicsView::indexAt ( const QPoint &  pos  )  const

Returns:
The QModelIndex for the item located at position pos in the view or an invalid index if no item was present at that position.
This is useful for for example contextmenus.

Definition at line 610 of file kdganttgraphicsview.cpp.

References d.

00611 {
00612     QGraphicsItem* item = itemAt( pos );
00613     if ( GraphicsItem* gitem = qgraphicsitem_cast<GraphicsItem*>( item ) ) {
00614         return d->scene.summaryHandlingModel()->mapToSource( gitem->index() );
00615     } else {
00616         return QModelIndex();
00617     }
00618 }

bool GraphicsView::isReadOnly (  )  const

Returns:
true iff the view is in read-only mode

Definition at line 532 of file kdganttgraphicsview.cpp.

References d.

Referenced by addConstraint().

00533 {
00534     return d->scene.isReadOnly();
00535 }

ItemDelegate * GraphicsView::itemDelegate (  )  const

Returns:
the ItemDelegate used by this view to render items

Definition at line 479 of file kdganttgraphicsview.cpp.

References d.

00480 {
00481     return d->scene.itemDelegate();
00482 }

QAbstractItemModel * GraphicsView::model (  )  const

Returns:
the current model displayed by this view

Definition at line 384 of file kdganttgraphicsview.cpp.

References d.

Referenced by updateScene().

00385 {
00386     return d->scene.model();
00387 }

void KDGantt::GraphicsView::pressed ( const QModelIndex &  index  )  [signal]

void GraphicsView::print ( QPainter *  painter,
qreal  start,
qreal  end,
const QRectF &  targetRect = QRectF(),
bool  drawRowLabels = true 
)

Render the GanttView inside the rectangle target using the painter painter. If drawRowLabels is true (the default), each row will have it's label printed on the left side.

To print a certain range of a chart with a DateTimeGrid, use qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const to figure out the values for start and end.

Definition at line 735 of file kdganttgraphicsview.cpp.

References d.

00737 {
00738   d->scene.print(painter, start, end, targetRect, drawRowLabels);
00739 }

void GraphicsView::print ( QPainter *  painter,
const QRectF &  targetRect = QRectF(),
bool  drawRowLabels = true 
)

Render the GanttView inside the rectangle target using the painter painter. If drawRowLabels is true (the default), each row will have it's label printed on the left side.

Definition at line 722 of file kdganttgraphicsview.cpp.

References d.

00723 {
00724   d->scene.print(painter,targetRect,drawRowLabels);
00725 }

void GraphicsView::print ( QPrinter *  printer,
qreal  start,
qreal  end,
bool  drawRowLabels = true 
)

Print part of the Gantt chart from start to end using printer. If drawRowLabels is true (the default), each row will have it's label printed on the left side.

This version of print() will print multiple pages.

To print a certain range of a chart with a DateTimeGrid, use qreal DateTimeGrid::mapFromDateTime( const QDateTime& dt) const to figure out the values for start and end.

Definition at line 713 of file kdganttgraphicsview.cpp.

References d.

00714 {
00715     d->scene.print( printer, start, end, drawRowLabels );
00716 }

void GraphicsView::print ( QPrinter *  printer,
bool  drawRowLabels = true 
)

Print the Gantt chart using printer. If drawRowLabels is true (the default), each row will have it's label printed on the left side.

This version of print() will print multiple pages.

Definition at line 698 of file kdganttgraphicsview.cpp.

References d.

00699 {
00700     d->scene.print( printer, drawRowLabels );
00701 }

KDGantt::GraphicsView::Q_PRIVATE_SLOT ( ,
void   slotGridChanged() 
)

void GraphicsView::resizeEvent ( QResizeEvent *  ev  )  [protected]

Definition at line 578 of file kdganttgraphicsview.cpp.

References d, r, rowController(), and KDGantt::AbstractRowController::totalHeight().

00579 {
00580     d->updateHeaderGeometry();
00581     QRectF r = scene()->itemsBoundingRect();
00582     // To scroll more to the left than the actual item start, bug #4516
00583     r.setLeft( qMin( qreal(0.0), r.left() ) );
00584     // TODO: take scrollbars into account (if not always on)
00585     // The scene should be at least the size of the viewport
00586     QSizeF size = viewport()->size();
00587     //TODO: why -2 below? size should be ex. frames etc?
00588     if ( size.width() > r.width() ) {
00589         r.setWidth( size.width() - 2 );
00590     }
00591     if ( size.height() > r.height() ) {
00592         r.setHeight( size.height() - 2 );
00593     }
00594     const int totalh = rowController()->totalHeight();
00595     if ( r.height() < totalh ) {
00596         r.setHeight( totalh );
00597     }
00598 
00599     scene()->setSceneRect( r );
00600 
00601     QGraphicsView::resizeEvent( ev );
00602 }

QModelIndex GraphicsView::rootIndex (  )  const

Returns:
the rootindex for this view.

Definition at line 449 of file kdganttgraphicsview.cpp.

References d.

Referenced by updateScene().

00450 {
00451     return d->scene.rootIndex();
00452 }

AbstractRowController * GraphicsView::rowController (  )  const

Returns:
the AbstractRowController for this view.
See also:
setRowController

Definition at line 499 of file kdganttgraphicsview.cpp.

References d.

Referenced by resizeEvent(), updateScene(), and updateSceneRect().

00500 {
00501     return d->rowcontroller;
00502 }

QItemSelectionModel * GraphicsView::selectionModel (  )  const

Returns:
the QItemSelectionModel used by this view

Definition at line 464 of file kdganttgraphicsview.cpp.

References d.

00465 {
00466     return d->scene.selectionModel();
00467 }

void GraphicsView::setConstraintModel ( ConstraintModel cmodel  )  [slot]

Sets the constraintmodel displayed by this view.

See also:
KDGantt::ConstraintModel.

Definition at line 420 of file kdganttgraphicsview.cpp.

References d.

00421 {
00422     d->scene.setConstraintModel( cmodel );
00423 }

void GraphicsView::setGrid ( AbstractGrid grid  )  [slot]

Sets the AbstractGrid for this view. The grid is an object that controls how QModelIndexes are mapped to and from the view and how the background and header is rendered.

See also:
AbstractGrid and DateTimeGrid.

Definition at line 509 of file kdganttgraphicsview.cpp.

References d.

00510 {
00511     d->scene.setGrid( grid );
00512     d->slotGridChanged();
00513 }

void GraphicsView::setHeaderContextMenuPolicy ( Qt::ContextMenuPolicy  p  ) 

Sets the context menu policy for the header. The default value Qt::DefaultContextMenu results in a standard context menu on the header that allows the user to set the scale and zoom.

Setting this to Qt::CustomContextMenu will cause the signal headerContextMenuRequested(const QPoint& pt) to be emitted instead.

See also:
QWidget::setContextMenuPolicy( Qt::ContextMenuPolicy )

Definition at line 546 of file kdganttgraphicsview.cpp.

References d.

00547 {
00548     d->headerwidget.setContextMenuPolicy( p );
00549 }

void GraphicsView::setItemDelegate ( ItemDelegate delegate  )  [slot]

Sets the KDGantt::ItemDelegate used for rendering items on this view.

See also:
ItemDelegate and QAbstractItemDelegate.

Definition at line 472 of file kdganttgraphicsview.cpp.

References d.

00473 {
00474     d->scene.setItemDelegate( delegate );
00475 }

void GraphicsView::setModel ( QAbstractItemModel *  model  )  [slot]

Sets the model to be displayed in this view to model. The view does not take ownership of the model.

To make a model work well with GraphicsView it must have a certain layout. Whether the model is flat or has a treestrucure is not important, as long as an AbstractRowController is provided that can navigate the model.

GraphicsView operates per row in the model. The data is always taken from the _last_ item in the row. The ItemRoles used are Qt::DisplayRole and the roles defined in KDGantt::ItemDataRole.

Definition at line 370 of file kdganttgraphicsview.cpp.

References d, updateScene(), and updateSceneRect().

00371 {
00372     if ( d->scene.model() ) {
00373         disconnect( d->scene.model() );
00374     }
00375 
00376     d->scene.setModel( model );
00377     connect( model, SIGNAL( dataChanged(  const QModelIndex&, const QModelIndex& ) ),
00378              this, SLOT( updateSceneRect() ) );
00379     updateScene();
00380 }

void GraphicsView::setReadOnly ( bool  ro  )  [slot]

Sets the view to read-only mode if to is true. The default is read/write if the model permits it.

Definition at line 525 of file kdganttgraphicsview.cpp.

References d.

00526 {
00527     d->scene.setReadOnly( ro );
00528 }

void GraphicsView::setRootIndex ( const QModelIndex &  idx  )  [slot]

Sets the root index of the model displayed by this view. Similar to QAbstractItemView::setRootIndex, default is QModelIndex().

Definition at line 442 of file kdganttgraphicsview.cpp.

References d.

00443 {
00444     d->scene.setRootIndex( idx );
00445 }

void GraphicsView::setRowController ( AbstractRowController rowcontroller  )  [slot]

Sets the AbstractRowController used by this view. The AbstractRowController deals with the height and position of each row and with which parts of the model are displayed.

See also:
AbstractRowController

Definition at line 489 of file kdganttgraphicsview.cpp.

References d, and updateScene().

00490 {
00491     d->rowcontroller = rowcontroller;
00492     d->scene.setRowController( rowcontroller );
00493     updateScene();
00494 }

void GraphicsView::setSelectionModel ( QItemSelectionModel *  model  )  [slot]

Sets the QItemSelectionModel used by this view to manage selections. Similar to QAbstractItemView::setSelectionModel

Definition at line 457 of file kdganttgraphicsview.cpp.

References d.

00458 {
00459     d->scene.setSelectionModel( model );
00460 }

void GraphicsView::setSummaryHandlingModel ( QAbstractProxyModel model  )  [slot]

Definition at line 389 of file kdganttgraphicsview.cpp.

References d, slotColumnsInserted(), slotColumnsRemoved(), slotDataChanged(), slotLayoutChanged(), slotModelReset(), slotRowsAboutToBeRemoved(), slotRowsInserted(), slotRowsRemoved(), and updateScene().

00390 {
00391     disconnect( d->scene.summaryHandlingModel() );
00392     d->scene.setSummaryHandlingModel( proxyModel );
00393 
00394     /* Connections. We have to rely on the treeview
00395      * to receive the signals before we do(!)
00396      */
00397     connect( proxyModel, SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
00398              this,  SLOT( slotColumnsInserted( const QModelIndex&,  int, int ) ) );
00399     connect( proxyModel, SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
00400              this,  SLOT( slotColumnsRemoved( const QModelIndex&,  int, int ) ) );
00401     connect( proxyModel, SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
00402              this,  SLOT( slotDataChanged( const QModelIndex&, const QModelIndex& ) ) );
00403     connect( proxyModel, SIGNAL( layoutChanged() ),
00404              this,  SLOT( slotLayoutChanged() ) );
00405     connect( proxyModel, SIGNAL( modelReset() ),
00406              this,  SLOT( slotModelReset() ) );
00407     connect( proxyModel, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
00408              this,  SLOT( slotRowsInserted( const QModelIndex&,  int, int ) ) );
00409     connect( proxyModel, SIGNAL( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ),
00410              this,  SLOT( slotRowsAboutToBeRemoved( const QModelIndex&,  int, int ) ) );
00411     connect( proxyModel, SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
00412              this,  SLOT( slotRowsRemoved( const QModelIndex&,  int, int ) ) );
00413 
00414     updateScene();
00415 }

void void void KDGantt::GraphicsView::slotColumnsInserted ( const QModelIndex &  parent,
int  start,
int  end 
)

Referenced by setSummaryHandlingModel().

void void void void KDGantt::GraphicsView::slotColumnsRemoved ( const QModelIndex &  parent,
int  start,
int  end 
)

Referenced by setSummaryHandlingModel().

void void void void void KDGantt::GraphicsView::slotDataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight 
)

Referenced by setSummaryHandlingModel().

void void KDGantt::GraphicsView::slotHeaderContextMenuRequested ( const QPoint &   ) 

void KDGantt::GraphicsView::slotHorizontalScrollValueChanged ( int   ) 

void void void void void void void void void void void KDGantt::GraphicsView::slotItemClicked ( const QModelIndex &  idx  ) 

void void void void void void KDGantt::GraphicsView::slotLayoutChanged (  ) 

Referenced by setSummaryHandlingModel().

void void void void void void void KDGantt::GraphicsView::slotModelReset (  ) 

Referenced by setSummaryHandlingModel().

void void void void void void void void void KDGantt::GraphicsView::slotRowsAboutToBeRemoved ( const QModelIndex &  parent,
int  start,
int  end 
)

Referenced by setSummaryHandlingModel().

void void void void void void void void KDGantt::GraphicsView::slotRowsInserted ( const QModelIndex &  parent,
int  start,
int  end 
)

Referenced by setSummaryHandlingModel().

void void void void void void void void void void KDGantt::GraphicsView::slotRowsRemoved ( const QModelIndex &  parent,
int  start,
int  end 
)

Referenced by setSummaryHandlingModel().

QAbstractProxyModel * GraphicsView::summaryHandlingModel (  )  const

Returns:
the KDGantt::SummaryHandlingProxyModel used by this view.

Definition at line 434 of file kdganttgraphicsview.cpp.

References d.

00435 {
00436     return d->scene.summaryHandlingModel();
00437 }

void GraphicsView::updateRow ( const QModelIndex &  idx  ) 

Definition at line 627 of file kdganttgraphicsview.cpp.

References d.

Referenced by updateScene().

00628 {
00629     d->scene.updateRow( d->scene.summaryHandlingModel()->mapFromSource( idx ) );
00630 }

void GraphicsView::updateScene (  ) 

Definition at line 665 of file kdganttgraphicsview.cpp.

References clearItems(), model(), rootIndex(), rowController(), updateRow(), and updateSceneRect().

Referenced by setModel(), setRowController(), and setSummaryHandlingModel().

00666 {
00667     clearItems();
00668     if( !model()) return;
00669     if( !rowController()) return;
00670     QModelIndex idx = model()->index( 0, 0, rootIndex() );
00671     do {
00672         updateRow( idx );
00673     } while ( ( idx = rowController()->indexBelow( idx ) ) != QModelIndex() && rowController()->isRowVisible(idx) );
00674     //constraintModel()->cleanup();
00675     //qDebug() << constraintModel();
00676     updateSceneRect();
00677     if ( scene() ) scene()->invalidate( QRectF(), QGraphicsScene::BackgroundLayer );
00678 }

void GraphicsView::updateSceneRect (  )  [slot]

Definition at line 635 of file kdganttgraphicsview.cpp.

References d, r, rowController(), and KDGantt::AbstractRowController::totalHeight().

Referenced by setModel(), and updateScene().

00636 {
00637     /* What to do with this? We need to shrink the view to
00638      * make collapsing items work
00639      */
00640     qreal range = horizontalScrollBar()->maximum()-horizontalScrollBar()->minimum();
00641     const qreal hscroll = horizontalScrollBar()->value()/( range>0?range:1 );
00642     QRectF r = d->scene.itemsBoundingRect();
00643     // To scroll more to the left than the actual item start, bug #4516
00644     r.setTop( 0. );
00645     r.setLeft( qMin( qreal(0.0), r.left() ) );
00646     r.setSize( r.size().expandedTo( viewport()->size() ) );
00647     const int totalh = rowController()->totalHeight();
00648     if ( r.height() < totalh ) r.setHeight( totalh );
00649     d->scene.setSceneRect( r );
00650 
00651     /* set scrollbar to keep the same time in view */
00652     range = horizontalScrollBar()->maximum()-horizontalScrollBar()->minimum();
00653     if ( range>0 ) horizontalScrollBar()->setValue( qRound( hscroll*range ) );
00654 
00655     /* We have to update here to adjust for any rows with no
00656      * information because they are painted with a different
00657      * background brush
00658      */
00659     d->scene.invalidate( QRectF(), QGraphicsScene::BackgroundLayer );
00660 }


Property Documentation

bool KDGantt::GraphicsView::readOnly [read, write]

Definition at line 48 of file kdganttgraphicsview.h.


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