24 #include "kdganttlegend_p.h" 28 #include <QApplication> 50 setFrameStyle( QFrame::NoFrame );
85 if ( this->model() != 0 )
87 disconnect( this->model(), SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT(
modelDataChanged() ) );
88 disconnect( this->model(), SIGNAL( rowsRemoved( QModelIndex,
int,
int ) ),
this, SLOT(
modelDataChanged() ) );
89 disconnect( this->model(), SIGNAL( columnsRemoved( QModelIndex,
int,
int ) ),
this, SLOT(
modelDataChanged() ) );
92 QAbstractItemView::setModel( model );
93 d->proxyModel.setSourceModel( model );
95 if ( this->model() != 0 )
97 connect( this->model(), SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT(
modelDataChanged() ) );
98 connect( this->model(), SIGNAL( rowsRemoved( QModelIndex,
int,
int ) ),
this, SLOT(
modelDataChanged() ) );
99 connect( this->model(), SIGNAL( columnsRemoved( QModelIndex,
int,
int ) ),
this, SLOT(
modelDataChanged() ) );
109 viewport()->update();
119 QPainter p( viewport() );
120 p.fillRect( viewport()->rect(), palette().color( QPalette::Window ) );
131 opt.displayAlignment = Qt::Alignment(
d->proxyModel.data( index, Qt::TextAlignmentRole ).toInt() );
133 opt.font = ( index.model()->data( index, Qt::FontRole ) ).value< QFont >();
142 QRect
Legend::drawItem( QPainter* painter,
const QModelIndex& index,
const QPoint& pos )
const 147 if ( index.isValid() && index.model() == &
d->proxyModel )
150 assert( delegate != 0 );
154 opt.rect.setWidth( r.height() );
157 const int dx = (typ ==
TypeEvent) ? (r.height() / 2) : 0;
159 opt.
itemRect = opt.rect.adjusted(dx,0,dx,0);
162 if ( !opt.
text.isNull() )
170 const int rowCount =
d->proxyModel.rowCount( index );
171 for (
int row = 0; row < rowCount; ++row )
173 const QRect r =
drawItem( painter,
d->proxyModel.index( row, 0, index ), QPoint( pos.x(), yPos ) );
174 xPos = qMax( xPos, r.right() );
175 yPos = qMax( yPos, r.bottom() );
178 return QRect( pos, QPoint( xPos, yPos ) );
190 if ( index.model() != 0 )
192 QFontMetrics fm( ( index.model()->data( index, Qt::FontRole ) ).value< QFont >() );
193 const QString text = index.model()->data( index,
LegendRole ).toString();
194 if ( !text.isEmpty() )
195 baseSize += QSize( fm.width( text ) + fm.height() + 2, fm.height() + 2 );
203 const int rowCount =
d->proxyModel.rowCount( index );
204 for (
int row = 0; row < rowCount; ++row )
206 const QSize childSize =
measureItem(
d->proxyModel.index( row, 0, index ) );
207 childrenSize.setWidth( qMax( childrenSize.width(), childSize.width() ) );
208 childrenSize.rheight() += childSize.height();
210 return baseSize + childrenSize;
void paintEvent(QPaintEvent *event) override
QSize minimumSizeHint() const override
Class used to render gantt items in a KDGantt::GraphicsView.
Class only listed here to document inheritance of some KDChart classes.
virtual StyleOptionGanttItem getStyleOption(const QModelIndex &index) const
QModelIndex indexAt(const QPoint &point) const override
virtual void paintGanttItem(QPainter *p, const StyleOptionGanttItem &opt, const QModelIndex &idx)
QRect visualRect(const QModelIndex &index) const override
Legend(QWidget *parent=0)
QStyleOption subclass for gantt items.
virtual void modelDataChanged()
virtual QSize measureItem(const QModelIndex &index, bool recursive=true) const
QSize sizeHint() const override
virtual QRect drawItem(QPainter *painter, const QModelIndex &index, const QPoint &pos=QPoint()) const
void setModel(QAbstractItemModel *model) override