KDGantt::Legend Class Reference

#include <KDGanttLegend>

Inheritance diagram for KDGantt::Legend:

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

Collaboration graph
[legend]

List of all members.


Detailed Description

Legend showing an image and a description for Gantt items.

This is an item view class showing a small Gantt item and it's text defined by LegendRole.

Definition at line 35 of file kdganttlegend.h.


Public Member Functions

QModelIndex indexAt (const QPoint &point) const
 Legend (QWidget *parent=0)
QSize minimumSizeHint () const
void scrollTo (const QModelIndex &, ScrollHint=EnsureVisible)
void setModel (QAbstractItemModel *model)
QSize sizeHint () const
QRect visualRect (const QModelIndex &index) const
virtual ~Legend ()

Protected Slots

virtual void modelDataChanged ()

Protected Member Functions

virtual QRect drawItem (QPainter *painter, const QModelIndex &index, const QPoint &pos=QPoint()) const
virtual StyleOptionGanttItem getStyleOption (const QModelIndex &index) const
int horizontalOffset () const
bool isIndexHidden (const QModelIndex &) const
virtual QSize measureItem (const QModelIndex &index, bool recursive=true) const
QModelIndex moveCursor (CursorAction, Qt::KeyboardModifiers)
void paintEvent (QPaintEvent *event)
void setSelection (const QRect &, QItemSelectionModel::SelectionFlags)
int verticalOffset () const
QRegion visualRegionForSelection (const QItemSelection &) const

Constructor & Destructor Documentation

Legend::Legend ( QWidget parent = 0  )  [explicit]

Constructor. Creates a Legend with parent parent. The QObject parent is not used for anything internally.

Definition at line 47 of file kdganttlegend.cpp.

00048     : QAbstractItemView( parent ),
00049       _d( new Private )
00050 {
00051     setItemDelegate( new ItemDelegate( this ) );
00052     setFrameStyle( QFrame::NoFrame );
00053 }

Legend::~Legend (  )  [virtual]

Destructor. Does nothing

Definition at line 56 of file kdganttlegend.cpp.

00057 {
00058     delete _d;
00059 }


Member Function Documentation

QRect Legend::drawItem ( QPainter *  painter,
const QModelIndex &  index,
const QPoint &  pos = QPoint() 
) const [protected, virtual]

Draws the legend item at index and all of it's children recursively at pos onto painter. Reimplement this if you want to draw items in an user defined way.

Returns:
the rectangle drawn.

Definition at line 144 of file kdganttlegend.cpp.

References KDGantt::StyleOptionGanttItem::boundingRect, d, getStyleOption(), KDGantt::StyleOptionGanttItem::itemRect, KDGantt::ItemTypeRole, measureItem(), KDGantt::ItemDelegate::paintGanttItem(), r, KDGantt::StyleOptionGanttItem::text, and KDGantt::TypeEvent.

Referenced by paintEvent().

00145 {
00146     int xPos = pos.x();
00147     int yPos = pos.y();
00148 
00149     if( index.isValid() && index.model() == &d->proxyModel )
00150     {
00151         ItemDelegate* const delegate = qobject_cast< ItemDelegate* >( itemDelegate( index ) );
00152         assert( delegate != 0 );
00153         const QRect r( pos, measureItem( index, false ) );
00154         StyleOptionGanttItem opt = getStyleOption( index );
00155         opt.rect = r;
00156         opt.rect.setWidth( r.height() );
00157 
00158         const ItemType typ = static_cast<ItemType>( index.model()->data( index, ItemTypeRole ).toInt() );
00159         const int dx = (typ == TypeEvent) ? (r.height() / 2) : 0;
00160 
00161         opt.itemRect = opt.rect.adjusted(dx,0,dx,0);
00162         opt.boundingRect = r;
00163         opt.boundingRect.setWidth( r.width() + r.height() );
00164         if( !opt.text.isNull() )
00165             delegate->paintGanttItem( painter, opt, index );
00166 
00167         xPos = r.right();
00168         yPos = r.bottom();
00169     }
00170 
00171     
00172     const int rowCount = d->proxyModel.rowCount( index );
00173     for( int row = 0; row < rowCount; ++row )
00174     {
00175         const QRect r = drawItem( painter, d->proxyModel.index( row, 0, index ), QPoint( pos.x(), yPos ) );
00176         xPos = qMax( xPos, r.right() );
00177         yPos = qMax( yPos, r.bottom() );
00178     }
00179 
00180     return QRect( pos, QPoint( xPos, yPos ) );
00181 }

StyleOptionGanttItem Legend::getStyleOption ( const QModelIndex &  index  )  const [protected, virtual]

Creates a StyleOptionGanttItem with all style options filled in except the target rectangles.

Definition at line 129 of file kdganttlegend.cpp.

References d, KDGantt::StyleOptionGanttItem::displayPosition, KDGantt::LegendRole, KDGantt::StyleOptionGanttItem::Right, and KDGantt::StyleOptionGanttItem::text.

Referenced by drawItem().

00130 {
00131     StyleOptionGanttItem opt;
00132     opt.displayPosition = StyleOptionGanttItem::Right;
00133     opt.displayAlignment = Qt::Alignment( d->proxyModel.data( index, Qt::TextAlignmentRole ).toInt() );
00134     opt.text = index.model()->data( index, LegendRole ).toString();
00135     opt.font = qVariantValue< QFont >( index.model()->data( index, Qt::FontRole ) );
00136     return opt;
00137 }

int KDGantt::Legend::horizontalOffset (  )  const [protected]

Definition at line 60 of file kdganttlegend.h.

00060 { return 0; }

QModelIndex Legend::indexAt ( const QPoint &  point  )  const

Definition at line 63 of file kdganttlegend.cpp.

00064 {
00065     Q_UNUSED( point );
00066     return QModelIndex();
00067 }

bool KDGantt::Legend::isIndexHidden ( const QModelIndex &   )  const [protected]

Definition at line 61 of file kdganttlegend.h.

00061 { return false; }

QSize Legend::measureItem ( const QModelIndex &  index,
bool  recursive = true 
) const [protected, virtual]

Calculates the needed space for the legend item at index and, if recursive is true, all child items.

Definition at line 186 of file kdganttlegend.cpp.

References d, and KDGantt::LegendRole.

Referenced by drawItem(), minimumSizeHint(), and sizeHint().

00187 {
00188     if( model() == 0 )
00189         return QSize();
00190 
00191     QSize baseSize;
00192     if( index.model() != 0 )
00193     {
00194         QFontMetrics fm( qVariantValue< QFont >( index.model()->data( index, Qt::FontRole ) ) );
00195         const QString text = index.model()->data( index, LegendRole ).toString();
00196         if( !text.isEmpty() )
00197             baseSize += QSize( fm.width( text ) + fm.height() + 2, fm.height() + 2 );
00198     }
00199 
00200     if( !recursive )
00201         return baseSize;
00202 
00203     QSize childrenSize;
00204 
00205     const int rowCount = d->proxyModel.rowCount( index );
00206     for( int row = 0; row < rowCount; ++row )
00207     {
00208         const QSize childSize = measureItem( d->proxyModel.index( row, 0, index ) );
00209         childrenSize.setWidth( qMax( childrenSize.width(), childSize.width() ) );
00210         childrenSize.rheight() += childSize.height();
00211     }
00212     return baseSize + childrenSize;
00213 }

QSize Legend::minimumSizeHint (  )  const

Definition at line 80 of file kdganttlegend.cpp.

References measureItem().

00081 {
00082     return measureItem( rootIndex() );
00083 }

void Legend::modelDataChanged (  )  [protected, virtual, slot]

Triggers repainting of the legend.

Definition at line 108 of file kdganttlegend.cpp.

Referenced by setModel().

00109 {
00110     updateGeometry();
00111     viewport()->update();
00112 }

QModelIndex KDGantt::Legend::moveCursor ( CursorAction  ,
Qt::KeyboardModifiers   
) [protected]

Definition at line 62 of file kdganttlegend.h.

00062 { return QModelIndex(); }

void Legend::paintEvent ( QPaintEvent *  event  )  [protected]

Definition at line 114 of file kdganttlegend.cpp.

References drawItem(), and p.

00115 {
00116     Q_UNUSED( event );
00117     // no model, no legend...
00118     if( model() == 0 )
00119         return;
00120 
00121     QPainter p( viewport() );
00122     p.fillRect( viewport()->rect(), palette().color( QPalette::Window ) );
00123     drawItem( &p, rootIndex() );
00124 }

void KDGantt::Legend::scrollTo ( const QModelIndex &  ,
ScrollHint  = EnsureVisible 
)

Definition at line 46 of file kdganttlegend.h.

00046 {}

void Legend::setModel ( QAbstractItemModel *  model  ) 

Definition at line 85 of file kdganttlegend.cpp.

References d, and modelDataChanged().

00086 {
00087     if( this->model() != 0 )
00088     {
00089         disconnect( this->model(), SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( modelDataChanged() ) );
00090         disconnect( this->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( modelDataChanged() ) );
00091         disconnect( this->model(), SIGNAL( columnsRemoved( QModelIndex, int, int ) ), this, SLOT( modelDataChanged() ) );
00092     }
00093 
00094     QAbstractItemView::setModel( model );
00095     d->proxyModel.setSourceModel( model );
00096 
00097     if( this->model() != 0 )
00098     {
00099         connect( this->model(), SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( modelDataChanged() ) );
00100         connect( this->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( modelDataChanged() ) );
00101         connect( this->model(), SIGNAL( columnsRemoved( QModelIndex, int, int ) ), this, SLOT( modelDataChanged() ) );
00102     }
00103 
00104 }

void KDGantt::Legend::setSelection ( const QRect &  ,
QItemSelectionModel::SelectionFlags   
) [protected]

Definition at line 63 of file kdganttlegend.h.

00063 {}

QSize Legend::sizeHint (  )  const

Definition at line 75 of file kdganttlegend.cpp.

References measureItem().

00076 {
00077     return measureItem( rootIndex() );
00078 }

int KDGantt::Legend::verticalOffset (  )  const [protected]

Definition at line 64 of file kdganttlegend.h.

00064 { return 0; }

QRect Legend::visualRect ( const QModelIndex &  index  )  const

Definition at line 69 of file kdganttlegend.cpp.

00070 {
00071     Q_UNUSED( index );
00072     return QRect();
00073 }

QRegion KDGantt::Legend::visualRegionForSelection ( const QItemSelection &   )  const [protected]

Definition at line 65 of file kdganttlegend.h.

00065 { return QRegion(); }


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